Question

We are sending a transaction to our customers using SOAP web service.

Our enviornment:

Container : None (Component is running as stand alone) Axis version : 1.6.2

Requirment:

If the transaction size is small, we need to send the content as part of Body. If the transaction is huge, need to send the content as an attachment.

Code snippet:

final ServiceClient sender = new ServiceClient();

final Options options = new Options();

options.setTo(endpointRef);

options.setTransportInProtocol(Constants.TRANSPORT_HTTP);

options.setProperty(Constants.Configuration.ENABLE_MTOM,Constants.VALUE_TRUE);

sender.setOptions(options); 

final OMFactory omFactory = OMAbstractFactory.getOMFactory();

. 
. 
. 

DataHandler dataHandler = new DataHandler(new FileDataSource(new File("C://KB_9.9.xml")));

OMText omText = omFactory.createOMText(dataHandler, true); 

final OMElement inputData = omFactory.createOMElement("inputData",null); 
inputData.addChild(omText); 

method.addChild(inputData); 
sender.fireAndForget(omElement);

Our issue:

It is working fine and the data reached successfully. But the issue is attachment is not encoded. It is displaying the content of the file as it is. My question is do we need to enable any of the property of axis to encode the attachment content or we need to manually perform the Base64 Encoding.

Sample Output:

***--MIMEBoundary_5e6b57717e6fc299242f9cc2ec3ab3d6cd5ef851033370e3***

Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"

Content-Transfer-Encoding: binary

Content-ID: <0.d5d9e693c8e32f0069b7cbb392d60e7f8b08366c7cb4384d@apache.org> 

<?xml version='1.0' encoding='UTF-8'?>

 xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:1.7e6b57717e6fc299242f9cc2ec3ab3d6cd5ef851033370e3@apache.org"

***--MIMEBoundary_5e6b57717e6fc299242f9cc2ec3ab3d6cd5ef851033370e3***

Content-Type: application/octet-stream

Content-Transfer-Encoding: binary

Content-ID: <1.7e6b57717e6fc299242f9cc2ec3ab3d6cd5ef851033370e3@apache.org> 

My test file..... 

***--MIMEBoundary_5e6b57717e6fc299242f9cc2ec3ab3d6cd5ef851033370e3--***

Can you please help me to resolve this issue

Was it helpful?

Solution

For optimum efficiency of MTOM, it is advised to send smaller binary attachments using base64encoding (non-optimized) and larger attachments as optimized content.

Refer section (Enabling MTOM Optimization on the Server Side)

To enableMTOM globally for all services, users can set the "enableMTOM" parameter to True in the Axis2.xml. When it is set, all outgoing messages will be serialized and sent as MTOM optimized MIME messages. If it is not set, all the binary data in the binary content nodes will be serialized as Base64 encoded strings. This configuration can be overriden in services.xml on the basis of per service and per operation.

<parameter name="enableMTOM">true</parameter>

http://axis.apache.org/axis2/java/core/docs/mtom-guide.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top