camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9833: Improve a bit. Also fixed that issue with potentially setting content-type two times.
Date Thu, 07 Apr 2016 15:42:16 GMT
Repository: camel
Updated Branches:
  refs/heads/master 0b78c8318 -> c29946a36


CAMEL-9833: Improve a bit. Also fixed that issue with potentially setting content-type two
times.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c29946a3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c29946a3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c29946a3

Branch: refs/heads/master
Commit: c29946a36c16301a8c2b4da2e1a637a3c3aa7015
Parents: 0b78c83
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Apr 7 17:42:05 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Apr 7 17:42:05 2016 +0200

----------------------------------------------------------------------
 .../camel/http/common/DefaultHttpBinding.java   | 77 ++++++++++++--------
 .../http/common/DefaultHttpBindingTest.java     |  3 +
 .../component/jetty9/JettyHttpEndpoint9.java    |  4 +
 .../jetty/HttpBridgeBigFormPostRouteTest.java   | 24 +++---
 4 files changed, 66 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c29946a3/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
index c3a7080..adf5ad1 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
@@ -99,17 +99,45 @@ public class DefaultHttpBinding implements HttpBinding {
 
     public void readRequest(HttpServletRequest request, HttpMessage message) {
         LOG.trace("readRequest {}", request);
-        
-        // lets parse the body if mapHttpMessageBody is true
+
+        if (mapHttpMessageHeaders) {
+            readHeaders(request, message);
+        }
         if (mapHttpMessageBody) {
-            message.getBody();
+            readBody(request, message);
         }
-        // populate the headers from the request if mapHttpHeaders is true
-        Map<String, Object> headers = new HashMap<String, Object>();  
-        if (mapHttpMessageHeaders) {
-        	headers = message.getHeaders();
+
+        // populate the headers from the request
+        Map<String, Object> headers = message.getHeaders();
+
+        // always store these standard headers
+        // store the method and query and other info in headers as String types
+        String rawPath = getRawPath(request);
+        headers.put(Exchange.HTTP_METHOD, request.getMethod());
+        headers.put(Exchange.HTTP_QUERY, request.getQueryString());
+        headers.put(Exchange.HTTP_URL, request.getRequestURL().toString());
+        headers.put(Exchange.HTTP_URI, request.getRequestURI());
+        headers.put(Exchange.HTTP_PATH, rawPath);
+        // only set content type if not already extracted
+        if (!headers.containsKey(Exchange.CONTENT_TYPE)) {
+            headers.put(Exchange.CONTENT_TYPE, request.getContentType());
+        }
+
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("HTTP method {}", request.getMethod());
+            LOG.trace("HTTP query {}", request.getQueryString());
+            LOG.trace("HTTP url {}", request.getRequestURL());
+            LOG.trace("HTTP uri {}", request.getRequestURI());
+            LOG.trace("HTTP path {}", rawPath);
+            LOG.trace("HTTP content-type {}", headers.get(Exchange.CONTENT_TYPE));
         }
-        
+    }
+
+    protected void readHeaders(HttpServletRequest request, HttpMessage message) {
+        LOG.trace("readHeaders {}", request);
+
+        Map<String, Object> headers = message.getHeaders();
+
         //apply the headerFilterStrategy
         Enumeration<?> names = request.getHeaderNames();
         while (names.hasMoreElements()) {
@@ -122,11 +150,11 @@ public class DefaultHttpBinding implements HttpBinding {
                 name = Exchange.CONTENT_TYPE;
             }
             if (headerFilterStrategy != null
-                && !headerFilterStrategy.applyFilterToExternalHeaders(name, extracted,
message.getExchange())) {
+                    && !headerFilterStrategy.applyFilterToExternalHeaders(name, extracted,
message.getExchange())) {
                 HttpHelper.appendHeader(headers, name, extracted);
             }
         }
-                
+
         if (request.getCharacterEncoding() != null) {
             headers.put(Exchange.HTTP_CHARACTER_ENCODING, request.getCharacterEncoding());
             message.getExchange().setProperty(Exchange.CHARSET_NAME, request.getCharacterEncoding());
@@ -137,29 +165,16 @@ public class DefaultHttpBinding implements HttpBinding {
         } catch (Exception e) {
             throw new RuntimeCamelException("Cannot read request parameters due " + e.getMessage(),
e);
         }
-        
+    }
+
+    protected void readBody(HttpServletRequest request, HttpMessage message) {
+        LOG.trace("readBody {}", request);
+
+        // lets parse the body
         Object body = message.getBody();
         // reset the stream cache if the body is the instance of StreamCache
         if (body instanceof StreamCache) {
-            ((StreamCache)body).reset();
-        }
-
-        // store the method and query and other info in headers as String types
-        String rawPath = getRawPath(request);
-        headers.put(Exchange.HTTP_METHOD, request.getMethod());
-        headers.put(Exchange.HTTP_QUERY, request.getQueryString());
-        headers.put(Exchange.HTTP_URL, request.getRequestURL().toString());
-        headers.put(Exchange.HTTP_URI, request.getRequestURI());
-        headers.put(Exchange.HTTP_PATH, rawPath);
-        headers.put(Exchange.CONTENT_TYPE, request.getContentType());
-
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("HTTP method {}", request.getMethod());
-            LOG.trace("HTTP query {}", request.getQueryString());
-            LOG.trace("HTTP url {}", request.getRequestURL());
-            LOG.trace("HTTP uri {}", request.getRequestURI());
-            LOG.trace("HTTP path {}", rawPath);
-            LOG.trace("HTTP content-type {}", request.getContentType());
+            ((StreamCache) body).reset();
         }
 
         // if content type is serialized java object, then de-serialize it to a Java object
@@ -180,7 +195,7 @@ public class DefaultHttpBinding implements HttpBinding {
                 message.setBody(null);
             }
         }
-        
+
         populateAttachments(request, message);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/c29946a3/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java
b/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java
index dbeb01f..5454986 100644
--- a/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java
+++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java
@@ -35,6 +35,7 @@ public class DefaultHttpBindingTest extends CamelTestSupport {
         assertNotEquals(value, date.toString());
         assertEquals(value, DefaultHttpBinding.getHttpDateFormat().format(date));
     }
+
     @Test
     public void testConvertDateTypeConverter() throws Exception {
         DefaultHttpBinding binding = new DefaultHttpBinding();
@@ -44,6 +45,7 @@ public class DefaultHttpBindingTest extends CamelTestSupport {
         String value = binding.convertHeaderValueToString(exchange, date);
         assertEquals(value, date.toString());
     }
+
     @Test
     public void testConvertLocale() throws Exception {
         DefaultHttpBinding binding = new DefaultHttpBinding();
@@ -54,6 +56,7 @@ public class DefaultHttpBindingTest extends CamelTestSupport {
         assertNotEquals(value, l.toString());
         assertEquals("zh-CN", value);
     }
+
     @Test
     public void testConvertLocaleTypeConverter() throws Exception {
         DefaultHttpBinding binding = new DefaultHttpBinding();

http://git-wip-us.apache.org/repos/asf/camel/blob/c29946a3/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpEndpoint9.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpEndpoint9.java
b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpEndpoint9.java
index cdf3bba..27dc781 100644
--- a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpEndpoint9.java
+++ b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpEndpoint9.java
@@ -48,6 +48,10 @@ public class JettyHttpEndpoint9 extends JettyHttpEndpoint {
                 this.binding.setAllowJavaSerializedObject(getComponent().isAllowJavaSerializedObject());
             }
             this.binding.setHeaderFilterStrategy(getHeaderFilterStrategy());
+            // TODO: this option may not work with jetty9 afair
+            //this.binding.setEagerCheckContentAvailable(isEagerCheckContentAvailable());
+            this.binding.setMapHttpMessageBody(isMapHttpMessageBody());
+            this.binding.setMapHttpMessageHeaders(isMapHttpMessageHeaders());
         }
         return this.binding;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/c29946a3/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeBigFormPostRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeBigFormPostRouteTest.java
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeBigFormPostRouteTest.java
index 9d4221d..acf3952 100644
--- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeBigFormPostRouteTest.java
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeBigFormPostRouteTest.java
@@ -16,16 +16,14 @@
  */
 package org.apache.camel.component.jetty;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.http.Consts;
 import org.apache.http.HttpEntity;
-import org.apache.http.HttpHost;
 import org.apache.http.NameValuePair;
-import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
@@ -83,6 +81,8 @@ public class HttpBridgeBigFormPostRouteTest extends BaseJettyTest {
 
     @Test
     public void testHttpClient() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
         
         List<NameValuePair> nvps = new ArrayList<NameValuePair>();
         nvps.add(new BasicNameValuePair("param1", LARGE_HEADER_VALUE));
@@ -93,19 +93,16 @@ public class HttpBridgeBigFormPostRouteTest extends BaseJettyTest {
         HttpPost httpPost = new HttpPost("http://localhost:" + port2 + "/test/hello");
         httpPost.setEntity(entity);
 
-        HttpHost proxy = new HttpHost("localhost", 8888, "http");
-        RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
-        httpPost.setConfig(config);
-
         CloseableHttpClient httpClient = HttpClients.createDefault();
         try {
             CloseableHttpResponse response = httpClient.execute(httpPost);
             assertEquals(response.getStatusLine().getStatusCode(), 200);
             response.close();
-        } catch (IOException e) {
         } finally {
             httpClient.close();
         }
+
+        mock.assertIsSatisfied();
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -116,9 +113,14 @@ public class HttpBridgeBigFormPostRouteTest extends BaseJettyTest {
 
                 errorHandler(noErrorHandler());
 
-                from("jetty:http://localhost:" + port2 + "/test/hello?matchOnUriPrefix=true")
-                    .removeHeaders("formMetaData")
-                    .to("http://localhost:" + port1 + "?bridgeEndpoint=true");
+                from("jetty:http://localhost:" + port2 + "/test/hello?matchOnUriPrefix=true&mapHttpMessageHeaders=false&mapHttpMessageBody=false")
+                    .log("I was here")
+                    .to("jetty:http://localhost:" + port1 + "?bridgeEndpoint=true");
+
+                from("jetty://http://localhost:" + port1 + "?matchOnUriPrefix=true")
+                    .log("Me too")
+                    .to("mock:input");
+
             }
         };
     }  


Mime
View raw message