使用 Camel+Spring WS 发送 SOAP 附件?
我一直在尝试使用 Camel+SpringWS 发送 SOAP 附件。
以下是我的 RouteBuilder 类中的代码,端点工作正常,我已经得到空的 SOAP 响应:
from("spring-ws:rootqname:{http://www.lala.org/Bean}GetBookRequest?endpointMapping=#endpointMapping").process(new Processor() {
public void process(Exchange arg0) throws Exception {
//SpringWebserviceMessage msg = (SpringWebserviceMessage) arg0.getIn(); // --> SpringWebserviceMessage instance
arg0.getOut().addAttachment("test",new DataHandler(new FileDataSource("c:/CompanyLogo.jpg")));
}
});
我还尝试通过 SpringWebserviceMessage 添加附件,但它没有任何效果。 有谁知道如何使用 Camel+SpringWS 添加 SOAP 附件?
i have been trying to send SOAP attachment using Camel+SpringWS.
Following is code inside my RouteBuilder class, endpoint is working properly i have already got empty SOAP response :
from("spring-ws:rootqname:{http://www.lala.org/Bean}GetBookRequest?endpointMapping=#endpointMapping").process(new Processor() {
public void process(Exchange arg0) throws Exception {
//SpringWebserviceMessage msg = (SpringWebserviceMessage) arg0.getIn(); // --> SpringWebserviceMessage instance
arg0.getOut().addAttachment("test",new DataHandler(new FileDataSource("c:/CompanyLogo.jpg")));
}
});
I have also tried adding attachment through SpringWebserviceMessage, but it doesn't make any effect.
Is anyone know how to add SOAP Attachment with Camel+SpringWS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不熟悉 Camel,但我记得有一个案例,我也必须使用 spring-ws 在消息中放置 SOAP 附件。对我来说,诀窍是使用 SaajSoapMessage。
下面是关于如何在 java 中使用 spring-ws 附加文件的片段
:);
关键是实现 doWithMessage 并将 WebServiceMessage 转换为 SaajSoapMessage。
I'm not familiair with Camel but I do remember a case where I had to place a SOAP attachment in the message with spring-ws as well. The trick for me was to use a SaajSoapMessage.
Below is a snippet on how to attach a file using spring-ws in java:
);
The key was implementing the doWithMessage and casting the WebServiceMessage to a SaajSoapMessage.
Spring-WS 的 Camel 组件不包含任何正式发布的附件/标头支持。
但是,camel-spring-ws的最新快照包含解决此问题的补丁。
看这里: https://issues.apache.org/jira/browse/CAMEL-5724
这是建议功能的当前文档
现在您可以使用
注意:如果管道中的交换标头包含文本,则会在soap标头中生成 Qname(key)=value 属性。
建议直接创建一个
QName
类并将任意键放入 header 中。The Camel component for Spring-WS doesn't contains any attachment / header support that was officially released.
However, the latest snapshot of camel-spring-ws contains the patch that address this issue.
Look here: https://issues.apache.org/jira/browse/CAMEL-5724
Here is current doc of the proposed functionality
Now you can use
Note: If the exchange header in the pipeline contains text, it generates Qname(key)=value attribute in the soap header.
Recommended is to create a
QName
class directly and put into any key into header.不知道您的网络服务如何期望附件。我需要使用 Camel + Soap 发送附件。如果您计划使用“@mtom”,则需要添加二进制消息部分,然后需要添加附件以及对二进制部分的引用。
或者,如果您的 Web 服务使用 Base64 编码的附件。您只需设置文件内容,将 base64 编码为消息中的附件字段名称。
如果您可以分享 wsdl,我将能够更好地帮助您。
Don't know how your webservice expects the attachment. I had a requirement to send attachment using Camel + Soap. If you plan to use '@mtom', you need to add a binary message part and then you need to add the attachment, with the reference to the binary part.
Or else, if your webservice is using base64 encoded attachments. You simply need to set your file contents, base64 encoded to the attachment field name in message.
If you can share the wsdl, I will be able to help you better.