如何使用apache camel restlet将一个休息服务的响应路由到另一个休息服务

时间:2016-09-16 07:41:30

标签: java rest apache-camel jersey-1.0

我正在尝试使用camel-restlet在两个Web服务之间路由。这是我的pom.xml

<repositories>
    <repository>
        <id>maven-restlet</id>
        <name>Public online Restlet repository</name>
        <url>http://maven.restlet.org</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.17.1</version>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet.ext.httpclient</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet.ext.spring</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-http</artifactId>
        <version>2.17.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

任何人都可以帮助如何仅使用camel-restlet和tomcat在两个Web服务之间进行路由。这是我的camel-context.xml

   <beans>
<camelContext>
  <route>
    <from uri="restlet:/bid/req?restletMethods=GET"/>
     <to uri="cxfrs:http://localhost:8080/xxxxxxxxxx"/> 
  </route>
</camelContext>
<bean id="RestletComponent" class="org.restlet.Component" />
<bean id="RestletComponentService" class="org.apache.camel.component.restlet.RestletComponent">
  <constructor-arg index="0">
    <ref bean="RestletComponent"/>
  </constructor-arg>
</bean>
</beans>

1 个答案:

答案 0 :(得分:0)

The response returned from 1st service is set in exchange body. Retrieve body at the 2nd service endpoint to get response.



    .to("bean:beanName?method=testMethod");
    .to("bean:beanName2?method=testMethod2");

        public Response testMethod() { // This line will return testMethod respose in exchange body
        return response;
        }
        public void testMethod2() {
        Response response = exchange.getIn().getBody();
    }