Accessing web services - 6.3

Talend ESB Mediation Developer Guide

Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Design and Development
Talend ESB

To call a web service at simply define a route:


And sent a message:

template.requestBody("direct:example", "<foobar 
xmlns=\"\"><msg>test message</msg></foobar>");

Remember if it's a SOAP service you're calling you don't have to include SOAP tags. Spring-WS will perform the XML-to-SOAP marshaling.

Sending SOAP and WS-Addressing action headers

When a remote web service requires a SOAP action or use of the WS-Addressing standard you define your route as:


Optionally you can override the endpoint options with header values:

"<foobar xmlns=\"\"><msg>test message</msg></foobar>",
SpringWebserviceConstants.SPRING_WS_SOAP_ACTION, "");

Using SOAP headers

Available as of Camel 2.11.1

You can provide the SOAP header(s) as a Camel Message header when sending a message to a spring-ws endpoint, for example given the following SOAP header in a String

String body = ...
String soapHeader = "<h:Header 

We can set the body and header on the Camel Message as follows:

exchange.getIn().setHeader(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER, soapHeader);

And then send the Exchange to a spring-ws endpoint to call the Web Service.

Likewise the spring-ws consumer will also enrich the Camel Message with the SOAP header.

For an example see this unit test.

The header and attachment propagation

Spring WS Camel supports propagation of the headers and attachments into Spring-WS WebServiceMessage response since version 2.10.3. The endpoint will use so called "hook" the MessageFilter (default implementation is provided by BasicMessageFilter) to propagate the exchange headers and attachments into WebServiceMessage response. Now you can use

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.

How to use MTOM attachments

The BasicMessageFilter provides all required information for Apache Axiom in order to produce MTOM message. If you want to use Apache Camel Spring WS within Apache Axiom, here is an example:

1. Simply define the messageFactory as is bellow and Spring-WS will use MTOM strategy to populate your SOAP message with optimized attachments.

<bean id="axiomMessageFactory"
<property name="payloadCaching" value="false" />
<property name="attachmentCaching" value="true" />
<property name="attachmentCacheThreshold" value="1024" />

2. Add into your pom.xml the following dependencies


3. Add your attachment into the pipeline, for example using a Processor implementation.

private class Attachement implements Processor {
public void process(Exchange exchange) throws Exception
{ exchange.getOut().copyFrom(exchange.getIn()); File file = new 
File("testAttachment.txt"); exchange.getOut().addAttachment("test", new 
DataHandler(new FileDataSource(file)));  }

4. Define endpoint (producer) as ussual, for example like this:

.process(new Attachement())

5. Now, your producer will generate MTOM message with otpmized attachments.

The custom header and attachment filtering

If you need to provide your custom processing of either headers or attachments, extend existing BasicMessageFilter and override the appropriate methods or write a brand new implementation of the MessageFilter interface.

To use your custom filter, add this into your spring context:

You can specify either a global a or a local message filter as follows:

a) the global custom filter that provides the global configuration for all Spring-WS endpoints

<bean id="messageFilter" class="your.domain.myMessageFiler" scope="singleton" />


b) the local messageFilter directly on the endpoint as follows:


For more information see CAMEL-5724

If you want to create your own MessageFilter, consider overriding the following methods in the default implementation of MessageFilter in class BasicMessageFilter:

protected void doProcessSoapHeader(Message inOrOut, SoapMessage soapMessage)
{your code /*no need to call super*/ }
protected void doProcessSoapAttachements(Message inOrOut, SoapMessage response)
{ your code /*no need to call super*/ }

Using a custom MessageSender and MessageFactory

A custom message sender or factory in the registry can be referenced like this:


Spring configuration:

<!-- authenticate using HTTP Basic Authentication -->
<bean id="messageSender" 
    <property name="credentials">
        <bean class="org.apache.commons.httpclient.UsernamePasswordCredentials">
            <constructor-arg index="0" value="admin"/>
            <constructor-arg index="1" value="secret"/>
<!-- force use of Sun SAAJ implementation, -->
<bean id="messageFactory" 
    <property name="messageFactory">