2016-04-26 24 views
1
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:cxf="http://camel.apache.org/schema/cxf" 
     xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd 
     http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd 
     http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd 
    "> 

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> 

    <!-- Defined the real JAXRS back end service --> 
    <jaxrs:server id="restService" 
       address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest" 
       staticSubresourceResolution="true"> 
    <jaxrs:serviceBeans> 
     <ref bean="customerService"/> 
    </jaxrs:serviceBeans>  
    </jaxrs:server> 

    <bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider"/> 

    <bean id="customerService" class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService" /> 

    <!-- Defined the server endpoint to create the cxf-rs consumer --> 
    <cxf:rsServer id="rsServer" address="http://localhost:${CXFTestSupport.port1}/CxfRsRouterTest/route" 
    serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService" 
    loggingFeatureEnabled="true" loggingSizeLimit="20" skipFaultLogging="true"> 
    <cxf:providers> 
     <ref bean="jsonProvider"/> 
    </cxf:providers> 
    </cxf:rsServer> 

    <!-- Defined the client endpoint to create the cxf-rs consumer --> 
    <cxf:rsClient id="rsClient" address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest" 
    serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService" 
    loggingFeatureEnabled="true" skipFaultLogging="true"> 
    <cxf:providers> 
     <ref bean="jsonProvider"/> 
    </cxf:providers> 
    </cxf:rsClient> 

    <!-- The camel route context --> 
    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> 
    <route> 
     <!-- Just need to ignoreDeleteMethodMessageBody --> 
     <from uri="cxfrs://bean://rsServer"/> 
     <to uri="log:body?level=INFO"/> 
     <to uri="cxfrs://bean://rsClient?ignoreDeleteMethodMessageBody=true"/> 
    </route> 
    </camelContext> 

</beans> 

在駱駝文檔他們說CXF:rsServer是一個REST消費者那裏爲CXF:rsClient是一個REST製片但代碼似乎做反之亦然。 另外我想了解Jaxrs標籤和cxf之間的區別:rsserver和cxf:rsclient標籤。什麼在下面駱駝CXF做不同的標記確實

回答

0
  • jaxrs:server:創建一個基本的端點服務。
  • cxf:rsServer:是一個創建REST端點的駱駝組件。它會將請求轉變爲普通的Java對象。
  • cxf:rsClient:與rsServer相反,它將java對象轉換爲REST請求。

    <camelContext> <route> <from uri="cxfrs://bean://rsServer" /> <to uri="log:body?level=INFO" /> <to uri="cxfrs://bean://..=true" /> </route> </camelContext>

如果我們看一看的代碼示例中,我們看到,這是一個代理。我們收到了REST請求,我們將其記錄下來,然後轉發。

<cxf:rsServer id="rsServer" address="http://localhost:${CXFTestSupport.port1}/CxfRsRouterTest/route" 
    serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService" 
    loggingFeatureEnabled="true" loggingSizeLimit="20" skipFaultLogging="true"> 
    <cxf:providers> 
     <ref bean="jsonProvider"/> 
    </cxf:providers> 
    </cxf:rsServer> 

    <cxf:rsClient id="rsClient" address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest" 
    serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService" 
    loggingFeatureEnabled="true" skipFaultLogging="true"> 
    <cxf:providers> 
     <ref bean="jsonProvider"/> 
    </cxf:providers> 
    </cxf:rsClient> 

這些標籤用於配置駱駝路由之外的cxf組件。

希望得到這個幫助。

+0

謝謝托馬斯,真的幫助。只有一個解釋需要說明,當你說rsServer將Request轉換爲Java Object時,是否將Request中的JSON轉換爲Object? –

+0

是的,一個JSON或XML對象(使用Jaxrs或傑克遜) – Thomas