8 Replies Latest reply on Aug 12, 2008 2:58 PM by lfoggy

    Enabling MTOM-Support at JBossWS client fails

    seventy8

      Hello!

      I am trying to use mtom for sending a binary file from a web service client to a web service endpoint, using JBoss AS 4.2.2.GA with build in JBossWS 2.0.1.SP2.

      I enabled mtom on the endpoint and on the client like it is told in the user guide:

      First I added the @BindingType Annotation

      @Stateless
      @TransactionManagement(value=TransactionManagementType.CONTAINER)
      @WebService(name="AdminLibrary",
       serviceName="AdminLibraryService",
       wsdlLocation="META-INF/wsdl/AdminLibraryService.wsdl")
      @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, parameterStyle = SOAPBinding.ParameterStyle.BARE)
      @BindingType(value = "http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true")
      @WebContext(contextRoot = "ALibrary")
      public class AdminLibraryWS {
      
      ...
      
      


      Then I used WSProvide to generate the wsdl and did the appropriate changes


      
       <xs:schema targetNamespace='http://ws.session.ejb.alibrary.seventy8.com/' version='1.0' xmlns:tns='http://ws.session.ejb.alibrary.seventy8.com/' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
       <xs:import schemaLocation='http://www.w3.org/2005/05/xmlmime' namespace='http://www.w3.org/2005/05/xmlmime'/>
       <xs:element name='ALibraryException' type='tns:ALibraryException'/>
       <xs:element name='importBook' nillable='true' type='tns:importBookRequest'/>
       <xs:element name='importBookResponse' nillable='true' type='tns:importBookResponse'/>
       <xs:complexType name='importBookRequest'>
       <xs:sequence>
       <xs:element minOccurs='0' name='dataHandler' type='xmime:base64Binary' xmlns:xmime='http://www.w3.org/2005/05/xmlmime'/>
       <xs:element minOccurs='0' name='userId' type='xs:string'/>
       </xs:sequence>
      
      


      After deploying everything looks fine on the server. So I ran WSConsume

      At the clients side I enabled MTOM as follows:

      
      SOAPBindingbinding = (SOAPBinding)((BindingProvider)port).getBinding();
      binding.setMTOMEnabled(true);
      
      


      When I test this service and check the SOAP Message, the binary content is transmitted inline.

      
      POST /ALibrary-ALibrary./AdminLibraryWS HTTP/1.1
      SOAPAction: ""
      Content-Type: text/xml; charset=UTF-8
      JBoss-Remoting-Version: 22
      User-Agent: JBossRemoting - 2.2.2.SP1 (Bluto)
      Host: 127.0.0.1:4040
      Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
      Connection: keep-alive
      Content-Length: 284493
      
      <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><ns1:importBook xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:ns1="http://ws.session.ejb.alibrary.seventy8.com/"><dataHandler>PQA9AD0AIABWAGUAcgBiAG8AcwBlACAAbABvAGcAZwBpAG4AZwAgAHMAdABhAHIAdABlAGQAOgAgA
      
      ...
      
      DAAMwAuADAANAAuADIAMAAwADcAIAAgADIAMQA6ADMANQA6ADAANwAgACAAQgB1AGkAbABkACAAdAB5AHAAZQA6ACAAUwBIAEkAUAAgAFUATgBJAgA=</dataHandler><userId>user1</userId></ns1:importBook></env:Body></env:Envelope>
      
      


      Is there anything further I have to do to enable MTOM at the client?

      WSConsume generates a class named Base64Binary which includes a byte-array and a field called contentType.

      IMO the type should be DataHandler instead, or am I wrong?

      best regards


        • 1. Re: Enabling MTOM-Support at JBossWS client fails
          lfoggy

          Hi,
          I am also having the same problem. I am using JAX-WS 2.0.3 with jboss 4.0.5, and enabling mtom on the client side to send an attachment to the server. When I check the content of the msg in trace mode, it looks like it is inline. Is there anything else I need to do or maybe the trace mode is not showing the correct msg body?
          Any help would be appreciated.
          Thanks,

          • 2. Re: Enabling MTOM-Support at JBossWS client fails
            lfoggy

            Hi,
            I have been trying to compare my classes with the sample xop examples in jbossws package and finally I was able to find the problem.
            Here are my classes:
            class AttachmentType {
            @XmlMimeType("application/octet-stream")
            protected DataHandler dh;

            ....

            class AttachmentTypeHolder {
            protected List attachments;

            ....

            In my endpoint class if I have the following method signature, then the xop works:

            public AttachmentType echoDataHandler(DHRequest request)

            but if I change the method signature to this:

            public AttachmentHolder echoDataHandler(DHRequest request)

            then the response is returned inline and not xop encoded.

            Is there anything I have to do to fix this. I am using Doc/Literal Wrapped wsdl, with a WSDL-first approach.

            Any help would really be appreciated.
            Thanks,

            • 3. Re: Enabling MTOM-Support at JBossWS client fails
              kosulin

              The cause is, may be, in 'protected' declaration.
              I used

              private DataHandler stmtContent;

              @XmlElement(name = "StatementContent", required = false)
              @XmlMimeType("application/zip")
              public final DataHandler getStmtContent()
              {
              return this.stmtContent;
              }
              public final void setStmtContent(DataHandler stmtContent)
              {
              this.stmtContent = stmtContent;
              }

              and it works fine with .NET client.

              Another thing you can do:
              put into your endpoint declaration
              @MTOM(enabled = true)
              in addition to @BindingType

              • 4. Re: Enabling MTOM-Support at JBossWS client fails
                lfoggy

                Well, I am using document/literal wrapped for my wsdl file, and what I have found so far is that mtom only works if the parameter type of the method is DataHandler. For example, this works:

                @WebMethod
                @RequestWrapper(localName = "sendOctet", targetNamespace = "http://xxx.com/webservice/mtom/", className = "com.xxx.webservice.mtom.SendOctet")
                @ResponseWrapper(localName = "sendOctetResponse", targetNamespace = "http://xxx.com/stat/webservice/mtom/", className = "com.xxx.webservice.mtom.SendOctetResponse")
                public void sendOctet(
                @WebParam(name = "octet", targetNamespace = "")
                DataHandler octet,

                But if I pass something like List, or another holder bean that contains a DataHandler field, mtom does not work anymore, and the message is send inline.

                • 5. Re: Enabling MTOM-Support at JBossWS client fails
                  kosulin

                  The following code works for me (java 6, JBoss 5.0.0CR1, jbossws Core 3.02):

                  @WebService(...)
                  @EndpointConfig(...)
                  @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
                  @MTOM(enabled = true)
                  @BindingType(value = "http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true")
                  public class StatementService
                  {
                  ...
                  @WebMethod(operationName = "GetStatementContent")
                  public StatementListDO getStatementContent(@WebParam(name = "FileName") final String fileName)
                  {
                  StatementListDO sldo = new StatementListDO();
                  ...
                  ArrayList statements = new ArrayList(1);
                  final File f7z = new File(fileName);
                  StatementDO statement = new StatementDO();
                  statement.setStmtContent(new DataHandler(new FileDataSource(f7z)));
                  statements.add(statement);
                  sldo.setStatements(statements);
                  return sldo;
                  }
                  ...
                  }

                  @XmlType
                  @XmlRootElement(name = "StatementList")
                  public class StatementListDO
                  implements Serializable
                  {
                  private ArrayList statements;
                  @XmlElement(name = "Statements", nillable = true, required = false)
                  public final ArrayList getStatements()
                  {
                  return this.statements;
                  }
                  public final void setStatements(ArrayList statements)
                  {
                  this.statements = statements;
                  }

                  }

                  @XmlType
                  public final class StatementDO
                  implements Serializable
                  {
                  ...
                  private DataHandler stmtContent;
                  @XmlElement(name = "StatementContent", required = false)
                  @XmlMimeType("application/zip")
                  public final DataHandler getStmtContent()
                  {
                  return this.stmtContent;
                  }
                  public final void setStmtContent(DataHandler stmtContent)
                  {
                  this.stmtContent = stmtContent;
                  }
                  ...
                  }

                  • 6. Re: Enabling MTOM-Support at JBossWS client fails
                    kosulin

                    I hope my example should work also if I used StatementListDO as web parameter.

                    • 7. Re: Enabling MTOM-Support at JBossWS client fails
                      kosulin

                      You use the very old stack.
                      May be, one of these bugs are the cause (these were fixed since your revision):
                      [JBWS-1736] - MTOM property at service-ref level
                      [JBWS-1460] @XmlMimeType on SEI parameter declarations
                      [JBWS-1973] - MTOM/XOP attachments not inlined when using JAX-WS handlers
                      [JBWS-2000] - MTOM: Chunked encoding transfer problem
                      [JBWS-2012] - Attachment support for JAX-WS collections
                      [JBWS-2014] - MTOM + WS-Security not working

                      • 8. Re: Enabling MTOM-Support at JBossWS client fails
                        lfoggy

                        Thank you very much for the replies.
                        In your case the code is working because StatementDO has a single DataHandler field.

                        public final class StatementDO
                        implements Serializable {
                        ...
                        private DataHandler stmtContent;

                        I think the problem is when there is a List of DataHandlers.
                        public final class StatementDO
                        implements Serializable {
                        ...
                        private List stmtContent;

                        I also think you are right and the problem might be taken care of by this:
                        [JBWS-2012] - Attachment support for JAX-WS collections

                        unfortunately it was fixed in version 3.0.2 and I can't move up to that version yet since I am running Jboss 4.0.5 for now.

                        Thanks,