2013-05-03 47 views
1

我是Apache Camel的新手。我想創建一個非常簡單的應用程序,它將接受WS調用並使用JPA將有效負載保存到數據庫中。 有效載荷的結構非常簡單。根是一個婚姻對象。它包含一些String和int和Date字段,一個妻子,一個丈夫和一個孩子列表(Person對象)。將WS有效載荷保存到Camel數據庫中

我的目標是將這些數據保存到數據庫的兩個表中:MARRIAGE,PERSON。

我已經成功創建了一個jaxws:端點,在該端點中我偵聽並響應一個虛擬響應。 我創建了表和JPA實體。

我不知道如何將WS實現與彈簧配置JpaTemplate「連接」。我應該使用某種方式使用@Converter類來解決這個問題,或者使用@Injet將它解析爲Spring的WS實現類。我很困惑。

我應該使用cxf端點而不是jaxws端點嗎?

回答

3

如果您想使用駱駝,則需要使用camle-cxf端點。我要做的就是將端點公開爲camle-cxf端點。事情是這樣的:如果你想使用JPA只配置了所有的配置,並注入您的實體管理器爲這個bean

<bean id="processor" class="com.dummy.DummyProcessor"> 
    <property name="..." value="..."/> //there goes your data source of jdbc template or whatever... 
</bean> 

<camel-cxf:cxfEndpoint id="listenerEndpoint" 
         address="http://0.0.0.0:8022/Dummy/services/Dummy" 
         wsdlURL="wsdl/DummyService.wsdl" 
         xmlns:tns="http://dummy.com/ws/Dummy" 
         serviceName="tns:Dummy" 
         endpointName="tns:DummyService"> 
    <camel-cxf:properties> 
     <entry key="schema-validation-enabled" value="true"/> 
     <entry key="dataFormat" value="PAYLOAD"/> 
    </camel-cxf:properties> 
</camel-cxf:cxfEndpoint> 

然後,我將有一個簡單的Spring bean這樣。

實際的類會是這個樣子:

public class DummyProcessor { 

    @Trancational //If you need transaction to be at this level... 
    public void processRequest(Exchange exchange) { 
     YourPayloadObject object = exchange.getIn().getBody(YourPayloadObject.class); 
     //object - is your object from SOAP request, now you can get all the data and store it in the database. 
    } 
} 

駱駝路線是這樣的:

<camel:camelContext trace="true" id="camelContext" > 

    <camel:route id="listenerEndpointRoute"> 
     <camel:from uri="cxf:bean:listenerEndpoint?dataFormat=POJO&amp;synchronous=true" /> 
     <camel:log message="Got message. The expected operation is :: ${headers.operationName}"/> 
     <camel:choice> 
      <camel:when> 
       <camel:simple>${headers.operationName} == 'YourPayloadObject'</camel:simple> 
       <camel:bean ref="processor" method="processRequest"/> 
      </camel:when> 
     </camel:choice> 
     <camel:log message="Got message before sending to target: ${headers.operationName}"/> 
     <camel:to uri="cxf:bean:someTargetEndpointOrSomethingElse"/> 
     <camel:log message="Got message received from target ${headers.operationName}"/> 
    </camel:route> 

</camel:camelContext> 

希望這有助於。

+0

Hello Paulius! 感謝您的幫助!使用你的示例代碼,我可以做我想做的事。現在我可以繼續。我的下一個目標是將我的試點應用程序與jBPM集成。 哦,我接受了你的建議,用CXF取代JAXWS。 – 2013-05-08 20:35:03