我们正在使用SOAP服务向客户发送一个事务。
我们的环境:
容器:无(组件作为独立运行) Axis版本: 1.6.2
请求:
如果事务大小较小,则需要将内容作为正文的一部分发送。如果事务很大,则需要将内容作为附件发送。
代码片段:
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--***
你能帮我解决这个问题吗?
发布于 2014-01-04 12:53:34
为了优化MTOM的效率,建议使用base64encoding (非优化)和较大的附件作为优化内容发送较小的二进制附件。
参考部分(启用服务器端的MTOM优化)
要对所有服务进行全局enableMTOM,用户可以在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
https://stackoverflow.com/questions/20903652
复制相似问题