82.3. 使用 Java DSL
以下示例使用名为 soap 的名为 DataFormat,它配置了软件包 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");
注意
另请参阅
,因为来自 JAXB 数据格式的 SOAP 数据格式继承在此处都适用。
82.3.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");
当使用 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>
在 Camel 路由中
<route> <from uri="direct:start"/> <marshal> <soapjaxb contentPath="com.example.customerservice" version="1.2" elementNameStrategyRef="myNameStrategy"/> </marshal> <to uri="jms:myQueue"/> </route>