4 Replies Latest reply on Aug 1, 2006 7:24 PM by Max Northup

    Problem with SOAP Attachments using EJB 2.1 Web Service Endp

    Max Northup Newbie

      We are trying to build an interoperable web service implemented using an EJB 2.1 service endpoint. We are starting from WSDL using Sun's tools (wscompile) to generate ties, etc. The deployment consists only of an ejb-jar file with the appropriate deployment descriptors. The web service should run on any J2EE 1.4 appserver but I'm having trouble with JBOSS.

      The web service allows for download of arbitrary files; therefore the mime-type of the response is not known ahead of time.

      For maximum interoperability the attachments are sent via document/literal WSDL using SwaRef/xsd:anyURI according to Sun's example:


      As such, my business method generates and returns a java.net.URI (the Content-ID of the attachment). Using properties on the EJB MessageContext and SAAJ I am attempting to create/add the attachment to the SOAP response using a custom handler declared in webservices.xml

      By using SOAPMessage.writeTo( System.out ) the logs appear to show the correct SOAP message:

      11:33:23,890 ERROR [STDERR] Jul 18, 2006 11:33:23 AM com.rtn.ejb.AttachmentHandler handleResponse
      INFO: Message content:
      Content-Type: text/xml; charset=UTF-8
      Content-Transfer-Encoding: 8bit
      Content-ID: <rootpart@ws.jboss.org>

      <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
      <ns1:retrieveProductResponse xmlns:ns1='java:com.rtn.ejb' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
      Content-Type: text/xml
      Content-Transfer-Encoding: binary
      Content-Id: <result=realData.xml@rtn.com>

      <?xml version="1.0" encoding="UTF-8"?>
      <!-- test example of an XML attachment -->
      hello, world!


      However, using a TCP Monitor program it appears that the SOAPMessage isn't getting onto the wire properly.

      HTTP/1.1 200 OK
      Server: Apache-Coyote/1.1
      X-Powered-By: Servlet 2.4; JBoss-4.0.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)/Tomcat-5.5
      Set-Cookie: JSESSIONID=0764D1BC6FB60F654B3E38ECAEF7F36F; Path=/
      Content-Type: text/xml;charset=UTF-8
      Transfer-Encoding: chunked
      Date: Tue, 18 Jul 2006 23:05:05 GMT

      <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header/>
      <env:Body><ns1:retrieveProductResponse xmlns:ns1='java:com.rtn.ejb' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>cid:result=realData.xml@rtn.com


      Somehow JBOSS is not saving my attachment or it is reverting to the SOAP message as it existed before the handler got invoked...?

      I am disappointed to find very little information regarding this and EJB endpoints on the Web. I have created a sample ANT script and test case and can provide it for evaluation. If anyone has implemented something like this please let me know what I'm doing wrong.


        • 1. Re: Problem with SOAP Attachments using EJB 2.1 Web Service
          Max Northup Newbie

          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;

          public boolean handleResponse( MessageContext context )
          SOAPMessageContext mctx = ( SOAPMessageContext )context;

          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 );

          • 2. Re: Problem with SOAP Attachments using EJB 2.1 Web Service
            Thomas Diesler Master

            Have a look at the attachment samples + test cases

            • 3. Re: Problem with SOAP Attachments using EJB 2.1 Web Service
              Max Northup Newbie

              The SOAP w/ Attachments example shows a procedure for port operations with a "known" mime-type. We have a method for retrieving arbitrary files, and we would like to set the mime-type correctly based on the file extension.

              The user's guide chapter 11 seems to suggest that MTOM/XOP is a good choice for unknown return mime types (*/* maps to DataHandler). However, I do not understand how to use MTOM/XOP with JAX-RPC. Is this possible?

              Are the samples/test cases available for download? I would like to see the source code.


              • 4. Re: Problem with SOAP Attachments using EJB 2.1 Web Service
                Max Northup Newbie

                Ok, I found some samples for jbossws 1.0.1 GA.

                It would be nice to see a working sample where the Server returns an attachment to the Client. The example which I have shown seems to indicate that there may be a bug in this scenario.

                It would be great if we could return arbitrary content types using a DataHandler return type. But if this is not possible, perhaps with a SOAP response handler.