312.4. 使用 Java DSL
以下示例使用名为 DataFormat of soap,它使用软件包 com.example.customerservice 来配置来初始化 JAXBContext。第二个参数是 ElementNameStrategy。路由可以 marshal 常规对象和例外。(请注意,以下只是将 SOAP Envelope 发送到队列。Web 服务提供商实际上需要侦听用于实际发生 SOAP 调用的队列,在这种情况下,它将是一个 SOAP 请求。如果您需要请求回复,您应该查看下一个示例。
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
from("direct:start")
.marshal(soap)
.to("jms:myQueue");
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
from("direct:start")
.marshal(soap)
.to("jms:myQueue");
提示
另请参阅,因为 SOAP dataformat 从 JAXB dataformat 大多数设置继承,此处应用最多设置
312.4.1. Using SOAP 1.2 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
从 Camel 2.11 开始提供
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
soap.setVersion("1.2");
from("direct:start")
.marshal(soap)
.to("jms:myQueue");
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
soap.setVersion("1.2");
from("direct:start")
.marshal(soap)
.to("jms:myQueue");
当使用 XML DSL 时,您可以在 <soapjaxb> 元素上设置 version 属性。
<!-- 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>
<!-- 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>
在 Camel 路由中