1 Reply Latest reply on Mar 7, 2011 8:47 AM by fambad

    Force MTOM Response in JBossWS-3.1.1.GA

    fambad

      Hi,

       

      How can I force a MOTOM Response although it is not neccessary because I have no binary data in the response.

       

      The reason is follow. I have a foreign test client that sends the request with MTOM enabled and expected that the response is also using MTOM (I think this is a little bit stupid). The client is using AXIS.

      In the request the client sends binary data using MTOM but in my response no binary data is available and so JBoss-WS won't enable the Mtom Feature for the response. The result is that the client don't accept my response.

      All works fine when my response contains binary data (annotated with "@XmlMimeType("application/octet-stream")" ). Then JBoss-WS creates a mtom response and the client accepted the response.

       

      Is there a workaround to force that MTOM is being enabled?

        • 1. Force MTOM Response in JBossWS-3.1.1.GA
          fambad

          I have found a workaround for this problem by my own.

           

          I have added a response handler to the webservice that add a dummy attachment part to the soap message and activate mtom using the method org.jboss.ws.extensions.xop.XOPContext#setMTOMEnabled(true) and declare the message as a XOP Message. That's all.

           

          Code Sample:

           

          public boolean handleMessage( MessageContext msgContext ) {

          ....

          ... // decide if outbound and other code left out....

          ....

           

               org.jboss.ws.core.soap.SOAPMessage msg = ((SOAPMessageContext) msgContext).getMessage();

               org.jboss.ws.core.CommonMessageContext cmCtx = (org.jboss.ws.core.CommonMessageContext) msgContext;

                     

               ByteArrayDataSource DUMMY_PLAIN_DATA_SOURCE;

               DUMMY_PLAIN_DATA_SOURCE = new ByteArrayDataSource( "DUMMY_ATTACHMENT_TO_FORCE_MTOM_RESPONSE", "text/plain" );

               msg.addAttachmentPart( msg.createAttachmentPart( new DataHandler( DUMMY_PLAIN_DATA_SOURCE ) ) );

              ((SOAPMessageImpl) msg).setXOPMessage( true );

               Scope lastScope = cmCtx.getCurrentScope();

               cmCtx.setCurrentScope( Scope.APPLICATION );

               XOPContext.setMTOMEnabled( true );

               cmCtx.setCurrentScope( lastScope );

          ...

          }