简体   繁体   English

Axis2-附件未编码

[英]Axis2 - Attachment is not encoded

We are sending a transaction to our customers using SOAP web service. 我们正在使用SOAP Web服务向我们的客户发送交易。

Our enviornment: 我们的环境:

Container : None (Component is running as stand alone) Axis version : 1.6.2 容器:无(组件独立运行)轴版本: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. 我的问题是我们是否需要启用axis的任何属性来编码附件内容,还是需要手动执行Base64编码。

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 你能帮我解决这个问题吗

For optimum efficiency of MTOM, it is advised to send smaller binary attachments using base64encoding (non-optimized) and larger attachments as optimized content. 为了获得最佳的MTOM效率,建议使用base64encoding(未优化)发送较小的二进制附件,并使用优化的内容发送较大的附件。

Refer section (Enabling MTOM Optimization on the Server Side) 请参阅部分(在服务器端启用MTOM优化)

To enableMTOM globally for all services, users can set the "enableMTOM" parameter to True in the Axis2.xml. 要全局为所有服务启用MTOM,用户可以在Axis2.xml中将“ enableMTOM”参数设置为True。 When it is set, all outgoing messages will be serialized and sent as MTOM optimized MIME messages. 设置后,所有传出消息将被序列化并作为MTOM优化的MIME消息发送。 If it is not set, all the binary data in the binary content nodes will be serialized as Base64 encoded strings. 如果未设置,则二进制内容节点中的所有二进制数据都将被序列化为Base64编码的字符串。 This configuration can be overriden in services.xml on the basis of per service and per operation. 可以基于每个服务和每个操作在services.xml中覆盖此配置。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM