[jboss-user] [JBossWS] - Re: Problem with SOAP Attachments using EJB 2.1 Web Service

mnorthu do-not-reply at jboss.com
Tue Jul 18 19:25:24 EDT 2006


FYI - this is the code in the Handler

package com.rtn.ejb;

import java.io.*;
import java.util.*;
import java.util.logging.*;

import javax.activation.*;
import javax.xml.namespace.*;
import javax.xml.rpc.handler.*;
import javax.xml.rpc.handler.soap.*;
import javax.xml.soap.*;

import com.rtn.util.*;

public final class AttachmentHandler extends GenericHandler
{
    private static QName[] EMPTY = new QName[0];

    /**
     * Returns an empty array of headers.
     * 
     * @return an empty array of headers.
     */
    public QName[] getHeaders()
    {
        return EMPTY;
    }

    @Override
    public boolean handleResponse( MessageContext context )
    {
        SOAPMessageContext mctx = ( SOAPMessageContext )context;

        try
        {
            String dataFileStr = ( String )mctx.getProperty( "PRODUCT_ATTACHMENT_FILE_NAME" );
            String cid = ( String )mctx.getProperty( "PRODUCT_ATTACHMENT_CID" );

            if ( dataFileStr == null || cid == null )
            {
                LOGGER.info( "No attachment detected." );
                return true;
            }

            FileInputStream dataFileIn = new FileInputStream( dataFileStr );
            DataHandler dataHandler = new DataHandler( new ByteArrayDataSource(
                dataFileIn, "text/xml" ) );

            AttachmentPart att = mctx.getMessage().createAttachmentPart(
                dataHandler );
            att.setContentId( "<" + cid + ">" );

            mctx.getMessage().addAttachmentPart( att );

//            doesn't seem to make a difference...
//            mctx.getMessage().saveChanges();

             // this is for logging only...
             java.io.ByteArrayOutputStream out = new ByteArrayOutputStream();
             mctx.getMessage().writeTo( out );
             LOGGER.info( "Message content: " + out.toString() );
        }
        catch ( Exception e )
        {
            LOGGER.warning( "Exception in handleResponse: " + e.getMessage() );
            LOGGER.info( "Returning false..." );            
            return false;
        }

        LOGGER.info( "Returning true..." );
        return true;
    }

    private static final String CLASSNAME = AttachmentHandler.class.getName();
    private static final Logger LOGGER = Logger.getLogger( CLASSNAME );
}


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3958980#3958980

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3958980



More information about the jboss-user mailing list