Author: ningjiang Date: Thu Aug 16 02:02:01 2012 New Revision: 1373691 URL: http://svn.apache.org/viewvc?rev=1373691&view=rev Log: CAMEL-5509 Fix the empty path issue of http consumer
Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?rev=1373691&r1=1373690&r2=1373691&view=diff ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java (original) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java Thu Aug 16 02:02:01 2012 @@ -208,7 +208,8 @@ public class HttpEndpoint extends Defaul } public String getPath() { - return httpUri.getPath(); + //if the path is empty, we just return the default path here + return httpUri.getPath().length() == 0 ? "/" : httpUri.getPath(); } public int getPort() { Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=1373691&r1=1373690&r2=1373691&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java (original) +++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java Thu Aug 16 02:02:01 2012 @@ -199,7 +199,6 @@ public class JettyHttpComponent extends URI endpointUri = URISupport.createRemainingURI(addressUri, httpClientParameters); // restructure uri to be based on the parameters left as we dont want to include the Camel internal options URI httpUri = URISupport.createRemainingURI(addressUri, parameters); - // create endpoint after all known parameters have been extracted from parameters JettyHttpEndpoint endpoint = new JettyHttpEndpoint(this, endpointUri.toString(), httpUri); setEndpointHeaderFilterStrategy(endpoint); Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java?rev=1373691&r1=1373690&r2=1373691&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java Thu Aug 16 02:02:01 2012 @@ -16,6 +16,7 @@ */ package org.apache.camel.component.jetty; +import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.util.StopWatch; import org.apache.camel.util.TimeUtils; @@ -31,20 +32,34 @@ public class HttpProxyRouteTest extends StopWatch watch = new StopWatch(); for (int i = 0; i < size; i++) { - String out = template.requestBody("http://localhost:{{port}}/hello?foo=" + i, null, String.class); + String out = template.requestBody("http://localhost:{{port}}?foo=" + i, null, String.class); assertEquals("Bye " + i, out); } log.info("Time taken: " + TimeUtils.printDuration(watch.taken())); } + + @Test + public void testHttpProxyWithDifferentPath() throws Exception { + String out = template.requestBody("http://localhost:{{port}}/proxy", null, String.class); + assertEquals("/otherEndpoint", out); + + out = template.requestBody("http://localhost:{{port}}/proxy/path", null, String.class); + assertEquals("/otherEndpoint/path", out); + } protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { - from("jetty://http://localhost:{{port}}/hello") + from("jetty://http://localhost:{{port}}") .to("http://localhost:{{port}}/bye?throwExceptionOnFailure=false&bridgeEndpoint=true"); + + from("jetty://http://localhost:{{port}}/proxy?matchOnUriPrefix=true") + .to("http://localhost:{{port}}/otherEndpoint?throwExceptionOnFailure=false&bridgeEndpoint=true"); from("jetty://http://localhost:{{port}}/bye").transform(header("foo").prepend("Bye ")); + + from("jetty://http://localhost:{{port}}/otherEndpoint?matchOnUriPrefix=true").transform(header(Exchange.HTTP_PATH)); } }; }