JBoss Community

Re: Force MTOM Response in JBossWS-3.1.1.GA

created by Marco Strauch in JBoss Web Services - View the full discussion

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

...

}

Reply to this message by going to Community

Start a new discussion in JBoss Web Services at Community