Author: ningjiang
Date: Mon Mar 29 02:51:41 2010
New Revision: 928575
URL: http://svn.apache.org/viewvc?rev=928575&view=rev
Log:
CAMEL-2575 Fix the CXFRS routing issue
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java?rev=928575&r1=928574&r2=928575&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
(original)
+++
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
Mon Mar 29 02:51:41 2010
@@ -89,10 +89,18 @@ public class DefaultCxfRsBinding impleme
// TODO use header filter strategy and cxfToCamelHeaderMap
copyMessageHeader(cxfMessage, camelMessage,
org.apache.cxf.message.Message.REQUEST_URI, Exchange.HTTP_URI);
-
+
copyMessageHeader(cxfMessage, camelMessage,
org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, Exchange.HTTP_METHOD);
- copyMessageHeader(cxfMessage, camelMessage,
org.apache.cxf.message.Message.PATH_INFO, Exchange.HTTP_PATH);
+ // We need remove the BASE_PATH from the PATH_INFO
+ String pathInfo =
(String)cxfMessage.get(org.apache.cxf.message.Message.PATH_INFO);
+ String basePath =
(String)cxfMessage.get(org.apache.cxf.message.Message.BASE_PATH);
+ if (pathInfo != null && basePath != null &&
pathInfo.startsWith(basePath)) {
+ pathInfo = pathInfo.substring(basePath.length());
+ }
+ if (pathInfo != null) {
+ camelMessage.setHeader(Exchange.HTTP_PATH, pathInfo);
+ }
copyMessageHeader(cxfMessage, camelMessage,
org.apache.cxf.message.Message.CONTENT_TYPE, Exchange.CONTENT_TYPE);
Modified:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java?rev=928575&r1=928574&r2=928575&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
(original)
+++
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
Mon Mar 29 02:51:41 2010
@@ -41,7 +41,7 @@ public class CxfRsRouterTest extends Cam
@Test
public void testGetCustomer() throws Exception {
- HttpGet get = new
HttpGet("http://localhost:9000/customerservice/customers/123");
+ HttpGet get = new
HttpGet("http://localhost:9000/route/customerservice/customers/123");
get.addHeader("Accept" , "application/json");
HttpClient httpclient = new DefaultHttpClient();
@@ -57,7 +57,7 @@ public class CxfRsRouterTest extends Cam
@Test
public void testGetCustomers() throws Exception {
- HttpGet get = new
HttpGet("http://localhost:9000/customerservice/customers/");
+ HttpGet get = new
HttpGet("http://localhost:9000/route/customerservice/customers/");
get.addHeader("Accept" , "application/xml");
HttpClient httpclient = new DefaultHttpClient();
@@ -79,7 +79,7 @@ public class CxfRsRouterTest extends Cam
@Test
public void testGetSubResource() throws Exception {
- HttpGet get = new
HttpGet("http://localhost:9000/customerservice/orders/223/products/323");
+ HttpGet get = new
HttpGet("http://localhost:9000/route/customerservice/orders/223/products/323");
get.addHeader("Accept" , "application/json");
HttpClient httpclient = new DefaultHttpClient();
@@ -95,7 +95,7 @@ public class CxfRsRouterTest extends Cam
@Test
public void testPutConsumer() throws Exception {
- HttpPut put = new
HttpPut("http://localhost:9000/customerservice/customers");
+ HttpPut put = new
HttpPut("http://localhost:9000/route/customerservice/customers");
StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
entity.setContentType("text/xml; charset=ISO-8859-1");
put.setEntity(entity);
@@ -112,7 +112,7 @@ public class CxfRsRouterTest extends Cam
@Test
public void testPostConsumer() throws Exception {
- HttpPost post = new
HttpPost("http://localhost:9000/customerservice/customers");
+ HttpPost post = new
HttpPost("http://localhost:9000/route/customerservice/customers");
post.addHeader("Accept" , "text/xml");
StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
entity.setContentType("text/xml; charset=ISO-8859-1");
@@ -132,7 +132,7 @@ public class CxfRsRouterTest extends Cam
@Test
public void testPostConsumerUniqueResponseCode() throws Exception {
- HttpPost post = new
HttpPost("http://localhost:9000/customerservice/customersUniqueResponseCode");
+ HttpPost post = new
HttpPost("http://localhost:9000/route/customerservice/customersUniqueResponseCode");
post.addHeader("Accept" , "text/xml");
StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
entity.setContentType("text/xml; charset=ISO-8859-1");
Modified:
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml?rev=928575&r1=928574&r2=928575&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml
(original)
+++
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml
Mon Mar 29 02:51:41 2010
@@ -28,7 +28,7 @@
">
<!-- Defined the real JAXRS back end service -->
<jaxrs:server id="restService"
- address="http://localhost:9002"
+ address="http://localhost:9002/rest"
staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="customerService"/>
@@ -40,11 +40,11 @@
<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:9000"
+ <cxf:rsServer id="rsServer" address="http://localhost:9000/route"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService" />
<!-- Defined the client endpoint to create the cxf-rs consumer -->
- <cxf:rsClient id="rsClient" address="http://localhost:9002"
+ <cxf:rsClient id="rsClient" address="http://localhost:9002/rest"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"/>
<!-- The camel route context -->