312.4. Java DSL を使用

次の例では、パッケージ com.example.customerservice で設定された soap の名前付き DataFormat を使用して、JAXBContext を初期化します。2 番目のパラメーターは ElementNameStrategy です。ルートは、通常のオブジェクトと例外をマーシャリングできます。(以下は、SOAP エンベロープをキューに送信するだけである点に注意してください。Web サービスプロバイダーは、SOAP 呼び出しが実際に発生するために実際にキューをリッスンする必要があります。この場合には、一方向の SOAP 要求になります。リクエストの返信が必要な場合は、次の例を参照してください。)

SoapJaxbDataFormat soap = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
from("direct:start")
  .marshal(soap)
  .to("jms:myQueue");
ヒント

参照内容: SOAP データ形式は JAXB データ形式を継承しているため、ほとんどの設定がここにも適用されます。

312.4.1. 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>