2013-05-03 50 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