You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/04/12 10:10:16 UTC
svn commit: r933133 - in /camel/trunk:
components/camel-http/src/main/java/org/apache/camel/component/http/helper/
components/camel-jetty/src/test/java/org/apache/camel/component/jetty/
tests/camel-itest/src/test/java/org/apache/camel/itest/issues/
Author: ningjiang
Date: Mon Apr 12 08:10:16 2010
New Revision: 933133
URL: http://svn.apache.org/viewvc?rev=933133&view=rev
Log:
CAMEL-2634 merged the revision 917527 back
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeRouteTest.java
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java
Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java?rev=933133&r1=933132&r2=933133&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java Mon Apr 12 08:10:16 2010
@@ -16,7 +16,11 @@
*/
package org.apache.camel.component.http.helper;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.http.HttpEndpoint;
import org.apache.camel.component.http.HttpMethods;
@@ -47,18 +51,44 @@ public final class HttpProducerHelper {
}
// append HTTP_PATH to HTTP_URI if it is provided in the header
- // when the endpoint is not working as a bridge
String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
if (path != null) {
- // make sure that there is exactly one "/" between HTTP_URI and
- // HTTP_PATH
- if (!uri.endsWith("/")) {
- uri = uri + "/";
- }
if (path.startsWith("/")) {
- path = path.substring(1);
+ URI baseURI;
+ String baseURIString = exchange.getIn().getHeader(Exchange.HTTP_BASE_URI, String.class);
+ try {
+ if (baseURIString == null) {
+ if (exchange.getFromEndpoint() != null) {
+ baseURIString = exchange.getFromEndpoint().getEndpointUri();
+ } else {
+ // will set a default one for it
+ baseURIString = "/";
+ }
+ }
+ baseURI = new URI(baseURIString);
+ String basePath = baseURI.getPath();
+ if (path.startsWith(basePath)) {
+ path = path.substring(basePath.length());
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+ } else {
+ throw new RuntimeCamelException("Can't anylze the Exchange.HTTP_PATH header, due to: can't find the right HTTP_BASE_URI");
+ }
+ } catch (Throwable t) {
+ throw new RuntimeCamelException("Can't anylze the Exchange.HTTP_PATH header, due to: "
+ + t.getMessage(), t);
+ }
+
+ }
+ if (path.length() > 0) {
+ // make sure that there is exactly one "/" between HTTP_URI and
+ // HTTP_PATH
+ if (!uri.endsWith("/")) {
+ uri = uri + "/";
+ }
+ uri = uri.concat(path);
}
- uri = uri.concat(path);
}
return uri;
Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeRouteTest.java?rev=933133&r1=933132&r2=933133&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeRouteTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeRouteTest.java Mon Apr 12 08:10:16 2010
@@ -30,7 +30,7 @@ public class HttpBridgeRouteTest extends
@Test
public void testHttpClient() throws Exception {
String response = template.requestBodyAndHeader("http://localhost:9090/test/hello", new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml", String.class);
- assertEquals("Get a wrong response", "/test/hello", response);
+ assertEquals("Get a wrong response", "/", response);
response = template.requestBody("http://localhost:9080/hello/world", "hello", String.class);
assertEquals("Get a wrong response", "/hello/world", response);
Modified: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java?rev=933133&r1=933132&r2=933133&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java (original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/issues/JettyHttpTest.java Mon Apr 12 08:10:16 2010
@@ -38,7 +38,7 @@ public class JettyHttpTest extends Camel
@Test
public void testGetRootPath() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedBodiesReceived("Hi! /someservice/myservice");
+ mock.expectedBodiesReceived("Hi! /someservice");
template.sendBody("direct:root", "");
@@ -48,7 +48,7 @@ public class JettyHttpTest extends Camel
@Test
public void testGetWithRelativePath() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedBodiesReceived("Hi! /someservice/myservice/relative");
+ mock.expectedBodiesReceived("Hi! /someservice/relative");
template.sendBody("direct:relative", "");
assertMockEndpointsSatisfied();