简体   繁体   中英

Sending SOAP attachment with Camel+Spring WS?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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