camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1457879 - in /camel/branches/camel-2.10.x/components/camel-jetty/src: main/java/org/apache/camel/component/jetty/JettyHttpProducer.java test/java/org/apache/camel/component/jetty/JettyHttpBridgeEncodedPathTest.java
Date Mon, 18 Mar 2013 17:22:55 GMT
Author: davsclaus
Date: Mon Mar 18 17:22:55 2013
New Revision: 1457879

URL: http://svn.apache.org/r1457879
Log:
CAMEL-6175: Issue when bridging with jetty http producer and uri query parameter has encoded
value

Modified:
    camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
    camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBridgeEncodedPathTest.java

Modified: camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java?rev=1457879&r1=1457878&r2=1457879&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
Mon Mar 18 17:22:55 2013
@@ -42,6 +42,7 @@ import org.apache.camel.util.ExchangeHel
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
+import org.apache.camel.util.UnsafeUriCharactersEncoder;
 import org.eclipse.jetty.client.HttpClient;
 import org.eclipse.jetty.io.ByteArrayBuffer;
 import org.slf4j.Logger;
@@ -225,19 +226,17 @@ public class JettyHttpProducer extends D
             return;
         }
 
+        // make sure the query string is safe
+        queryString = UnsafeUriCharactersEncoder.encode(queryString);
+
         // okay we need to add the query string to the URI so we need to juggle a bit with
the parameters
         String uri = httpExchange.getRequestURI();
 
-        Map<String, Object> parameters = URISupport.parseParameters(new URI(uri));
-        parameters.putAll(URISupport.parseQuery(queryString));
-
         if (uri.contains("?")) {
             uri = ObjectHelper.before(uri, "?");
         }
-        if (!parameters.isEmpty()) {
-            uri = uri + "?" + URISupport.createQueryString(parameters);
-            httpExchange.setRequestURI(uri);
-        }
+        uri = uri + "?" + queryString;
+        httpExchange.setRequestURI(uri);
     }
 
     protected static void doSendExchange(HttpClient client, JettyContentExchange httpExchange)
throws IOException {

Modified: camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBridgeEncodedPathTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBridgeEncodedPathTest.java?rev=1457879&r1=1457878&r2=1457879&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBridgeEncodedPathTest.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBridgeEncodedPathTest.java
Mon Mar 18 17:22:55 2013
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.component.jetty;
 
-import java.io.ByteArrayInputStream;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
@@ -30,8 +28,7 @@ public class JettyHttpBridgeEncodedPathT
 
     @Test
     public void testJettyHttpClient() throws Exception {
-        String response = template.requestBodyAndHeader("http://localhost:" + port2 + "/jettyTestRouteA?param1=%2B447777111222",
-                new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "text/plain",
String.class);
+        String response = template.requestBody("http://localhost:" + port2 + "/jettyTestRouteA?param1=%2B447777111222",
null, String.class);
         assertEquals("Get a wrong response", "param1=+447777111222", response);
     }
 
@@ -48,9 +45,8 @@ public class JettyHttpBridgeEncodedPathT
                     public void process(Exchange exchange) throws Exception {
                         // %2B becomes decoded to a space
                         Object s = exchange.getIn().getHeader("param1");
-                        assertEquals(" 447777111222", exchange.getIn().getHeader("param1"));
-                        // and in the http query %20 becomes a + sign
-                        assertEquals("param1=+447777111222", exchange.getIn().getHeader(Exchange.HTTP_QUERY));
+                        // can be either + or %2B
+                        assertTrue(s.equals(" 447777111222") || s.equals("+447777111222")
|| s.equals("%2B447777111222"));
 
                         // send back the query
                         exchange.getOut().setBody(exchange.getIn().getHeader(Exchange.HTTP_QUERY));
@@ -58,9 +54,7 @@ public class JettyHttpBridgeEncodedPathT
                 };
                 from("jetty://http://localhost:" + port2 + "/jettyTestRouteA?matchOnUriPrefix=true")
                     .log("Using JettyTestRouteA route: CamelHttpPath=[${header.CamelHttpPath}],
CamelHttpUri=[${header.CamelHttpUri}]")
-                    // TODO: Jetty has a bug in its client so use http for now
-                    // .to("jetty://http://localhost:" + port1 + "/jettyTestRouteB?throwExceptionOnFailure=false&bridgeEndpoint=true");
-                    .to("http://localhost:" + port1 + "/jettyTestRouteB?throwExceptionOnFailure=false&bridgeEndpoint=true");
+                    .to("jetty://http://localhost:" + port1 + "/jettyTestRouteB?throwExceptionOnFailure=false&bridgeEndpoint=true");
 
                 from("jetty://http://localhost:" + port1 + "/jettyTestRouteB?matchOnUriPrefix=true")
                     .log("Using JettyTestRouteB route: CamelHttpPath=[${header.CamelHttpPath}],
CamelHttpUri=[${header.CamelHttpUri}]")



Mime
View raw message