...
SOAP is a Data Format which uses JAXB2 and JAX-WS annotations to marshal and unmarshal SOAP payloads. It provides the basic features of Apache CXF without need for the CXF Stack.
Info | ||
---|---|---|
| ||
SOAP 1.1 is supported by default. SOAP 1.2 is supported from Camel 2.11 onwards. |
Tip | ||
---|---|---|
| ||
See JAXB for details how you can control namespace prefix mappings when marshalling using SOAP data format. |
ElementNameStrategy
An element name strategy is used for two purposes. The first is to find a xml element name for a given object and soap action when marshaling the object into a SOAP message. The second is to find an Exception class for a given soap fault name.
...
Tip | ||
---|---|---|
| ||
As the SOAP dataformat inherits from the JAXB dataformat most settings apply here as well |
Using SOAP 1.2
Available as of Camel 2.11
Code Block |
---|
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
soap.setVersion("1.2");
from("direct:start")
.marshal(soap)
.to("jms:myQueue");
|
When using XML DSL there is a version attribute you can set on the <soapjaxb> element.
Code Block | ||||
---|---|---|---|---|
| ||||
<!-- Defining a ServiceInterfaceStrategy for retrieving the element name when marshalling -->
<bean id="myNameStrategy" class="org.apache.camel.dataformat.soap.name.ServiceInterfaceStrategy">
<constructor-arg value="com.example.customerservice.CustomerService"/>
<constructor-arg value="true"/>
</bean>
|
And in the Camel route
Code Block | ||||
---|---|---|---|---|
| ||||
<route>
<from uri="direct:start"/>
<marshal>
<soapjaxb contentPath="com.example.customerservice" version="1.2" elementNameStrategyRef="myNameStrategy"/>
</marshal>
<to uri="jms:myQueue"/>
</route>
|
Multi-part Messages
Available as of Camel 2.8.1
...
The payload parameters for a multi-part request are initiazlied using a BeanInvocation
object that reflects the signature of the target operation. The camel-soap DatFormat DataFormat maps the content in the BeanInvocation
to fields in the SOAP header and body in accordance with the JAX-WS mapping when the marshal()
processor is invoked.
Code Block |
---|
BeanInvocation beanInvocation = new BeanInvocation(); // Identify the target method beanInvocation.setMethod(MultiPartCustomerService.class.getMethod("getCustomersByName", GetCustomersByName.class, com.example.customerservice.multipart.Product.class)); // Populate the method arguments GetCustomersByName getCustomersByName = new GetCustomersByName(); getCustomersByName.setName("Dr. Multipart"); Product product = new Product(); product.setName("Multiuse Product"); product.setDescription("Useful for lots of things."); Object[] args = new Object[] {getCustomersByName, product}; // Add the arguments to the bean invocation beanInvocation.setArgs(args); // Set the bean invocation object as the exchangemessage body exchange.getIn().setBody(beanInvocation); |
...