【问题标题】:Axis2 - Attachment is not encodedAxis2 - 附件未编码
【发布时间】:2014-01-04 20:53:34
【问题描述】:

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

我们的环境:

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

要求:

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

代码 sn-p:

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

我们的问题:

它工作正常,数据成功到达。但问题是附件未编码。它按原样显示文件的内容。我的问题是我们是否需要启用轴的任何属性来编码附件内容,或者我们需要手动执行 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--***

你能帮我解决这个问题吗

【问题讨论】:

    标签: java wso2 axis2


    【解决方案1】:

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

    参考章节(在服务器端启用 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

    【讨论】:

    • 我的问题是,附件响应是正确的还是应该被编码。如果要编码,程序是什么。
    • 好吧,你不需要在这里做特殊的编码,因为你的服务器和客户端可以正确读取内容。但是,如果您需要对消息传输进行某种压缩,您可以使用axis2 GZIP 压缩支持。参考(people.apache.org/~chinthaka/articles/…)
    猜你喜欢
    • 1970-01-01
    • 2011-05-22
    • 1970-01-01
    • 2011-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    相关资源
    最近更新 更多