使用 Camel+Spring WS 发送 SOAP 附件?

发布于 2024-12-02 06:25:44 字数 682 浏览 3 评论 0原文

我一直在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灯下孤影 2024-12-09 06:25:44

我不熟悉 Camel,但我记得有一个案例,我也必须使用 spring-ws 在消息中放置 SOAP 附件。对我来说,诀窍是使用 SaajSoapMessage。

下面是关于如何在 java 中使用 spring-ws 附加文件的片段

JAXBElement<ShowCandidateType> responseElement = (JAXBElement<ShowCandidateType>) kandidaatServiceTemplate.marshalSendAndReceive(
objectFactory.createProcessCandidate(processCandidate), 
new WebServiceMessageCallback() {

    public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {

        SaajSoapMessage saajMessage = (SaajSoapMessage) message;

        //Use the file name as the contentId 
        saajMessage.addAttachment(file.getName(), file); 
    } 
}

:);

关键是实现 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:

JAXBElement<ShowCandidateType> responseElement = (JAXBElement<ShowCandidateType>) kandidaatServiceTemplate.marshalSendAndReceive(
objectFactory.createProcessCandidate(processCandidate), 
new WebServiceMessageCallback() {

    public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {

        SaajSoapMessage saajMessage = (SaajSoapMessage) message;

        //Use the file name as the contentId 
        saajMessage.addAttachment(file.getName(), file); 
    } 
}

);

The key was implementing the doWithMessage and casting the WebServiceMessage to a SaajSoapMessage.

谢绝鈎搭 2024-12-09 06:25:44

Spring-WSCamel 组件不包含任何正式发布的附件/标头支持。

但是,camel-spring-ws的最新快照包含解决此问题的补丁。

看这里: https://issues.apache.org/jira/browse/CAMEL-5724

这是建议功能的当前文档

标头和附件传播

端点将使用所谓的“hook”MessageFilter(默认实现由 BasicMessageFilter 提供)将交换标头和附件传播到 WebSdrviceMessage 响应中。

现在您可以使用

exchange.getOut().getHeaders().put("myCustom","myHeaderValue")
exchange.getIn().addAttachment("myAttachment", new DataHandler(...))

注意:如果管道中的交换标头包含文本,则会在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

The header and attachment propagation

The endpoint will use so called "hook" the MessageFilter (default implementation is provided by BasicMessageFilter) to propagate the exchange headers and attachments into WebSdrviceMessage response.

Now you can use

exchange.getOut().getHeaders().put("myCustom","myHeaderValue")
exchange.getIn().addAttachment("myAttachment", new DataHandler(...))

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.

倾其所爱 2024-12-09 06:25:44

不知道您的网络服务如何期望附件。我需要使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文