76.9. Camel を CXF トランスポート層に統合する
Camel Transport を CXF バスに含めるには、CamelTransportFactory を使用します。これは、Spring だけでなく Java でも実行できます。
76.9.1. Spring に Camel トランスポートをセットアップする
特別なものを設定したい場合は、ApplicationContext で次のスニペットを使用できます。camel トランスポートのみをアクティブ化する場合は、アプリケーションコンテキストで何もする必要はありません。アプリに camel-cxf-transport jar (camel バージョンが 2.7.x 未満の場合は camel-cxf.jar) を含めるとすぐに、cxf は jar をスキャンして CamelTransportFactory をロードします。
<!-- you don't need to specify the CamelTransportFactory configuration as it is auto load by CXF bus --> <bean class="org.apache.camel.component.cxf.transport.CamelTransportFactory"> <property name="bus" ref="cxf" /> <property name="camelContext" ref="camelContext" /> <!-- checkException new added in Camel 2.1 and Camel 1.6.2 --> <!-- If checkException is true , CamelDestination will check the outMessage's exception and set it into camel exchange. You can also override this value in CamelDestination's configuration. The default value is false. This option should be set true when you want to leverage the camel's error handler to deal with fault message --> <property name="checkException" value="true" /> <property name="transportIds"> <list> <value>http://cxf.apache.org/transports/camel</value> </list> </property> </bean>
76.9.2. プログラムによる Camel Transport の統合
Camel トランスポートは、Camel コンテキストをトランスポートファクトリーに設定するために使用できる setContext メソッドを提供します。このファクトリーを有効にするには、ファクトリーを CXF バスに登録する必要があります。これが完全な例です。
import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.transport.ConduitInitiatorManager; import org.apache.cxf.transport.DestinationFactoryManager; ... BusFactory bf = BusFactory.newInstance(); Bus bus = bf.createBus(); CamelTransportFactory camelTransportFactory = new CamelTransportFactory(); // set up the CamelContext which will be use by the CamelTransportFactory camelTransportFactory.setCamelContext(context) // if you are using CXF higher then 2.4.x the camelTransportFactory.setBus(bus); // if you are lower CXF, you need to register the ConduitInitiatorManager and DestinationFactoryManager like below // register the conduit initiator ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class); cim.registerConduitInitiator(CamelTransportFactory.TRANSPORT_ID, camelTransportFactory); // register the destination factory DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class); dfm.registerDestinationFactory(CamelTransportFactory.TRANSPORT_ID, camelTransportFactory); // set or bus as the default bus for cxf BusFactory.setDefaultBus(bus);