开发者

Sending SOAP attachment with Camel+Spring WS?

开发者 https://www.devze.com 2023-04-01 19:09 出处:网络
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:

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=#endpointM开发者_开发技巧apping").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?


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号