Axis2 - 附件未编码

时间:2014-01-03 12:27:05

标签: java wso2 axis2

我们正在使用SOAP Web服务向客户发送交易。

我们的环境:

容器:无(组件独立运行)     轴版:1.6.2

需求量的:

如果交易规模很小,我们需要将内容作为Body的一部分发送。   如果交易量巨大,则需要将内容作为附件发送。

代码段:

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

我们的问题:

工作正常,数据成功。但问题是附件没有编码。它按原样显示文件的内容。我的问题是我们是否需要启用axis的任何属性来编码附件内容,或者我们需要手动执行Base64编码。

示例输出:

***--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--***

你能帮我解决这个问题吗

1 个答案:

答案 0 :(得分:0)

为了获得MTOM的最佳效率,建议发送较小的二进制附件 使用base64encoding(非优化)和更大的附件作为优化内容。

参考部分(在服务器端启用MTOM优化)

要为所有服务全局启用MTOM,用户可以在Axis2.xml中将“enableMTOM”参数设置为True。设置后,所有外发邮件都将被序列化并作为MTOM优化的MIME邮件发送。如果未设置,则二进制内容节点中的所有二进制数据将被序列化为Base64编码的字符串。可以基于每个服务和每个操作在services.xml中覆盖此配置。

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

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

相关问题