camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] branch camel-2.20.x updated: CAMEL-11961: Fixed ClassCastException in HttpMessage
Date Sat, 28 Oct 2017 08:55:44 GMT
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.20.x by this push:
     new 8947b84  CAMEL-11961: Fixed ClassCastException in HttpMessage
8947b84 is described below

commit 8947b84cd554752b011009b1c40443f08ff1f9d2
Author: Claus Ibsen <claus.ibsen@gmail.com>
AuthorDate: Sat Oct 28 10:40:04 2017 +0200

    CAMEL-11961: Fixed ClassCastException in HttpMessage
---
 .../org/apache/camel/http/common/CamelServlet.java  |  5 ++---
 .../org/apache/camel/http/common/HttpMessage.java   | 21 ++++++++++-----------
 .../component/jetty/CamelContinuationServlet.java   |  5 ++---
 3 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/CamelServlet.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/CamelServlet.java
index ed94745..2bfcaba 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/CamelServlet.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/CamelServlet.java
@@ -31,7 +31,6 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -152,7 +151,7 @@ public class CamelServlet extends HttpServlet {
         }
         
         // create exchange and set data on it
-        Exchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut);
+        Exchange exchange = consumer.getEndpoint().createExchange(ExchangePattern.InOut);
 
         if (consumer.getEndpoint().isBridgeEndpoint()) {
             exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
@@ -166,7 +165,7 @@ public class CamelServlet extends HttpServlet {
         // does some class resolution
         ClassLoader oldTccl = overrideTccl(exchange);
         HttpHelper.setCharsetFromContentType(request.getContentType(), exchange);
-        exchange.setIn(new HttpMessage(exchange, request, response));
+        exchange.setIn(new HttpMessage(exchange, consumer.getEndpoint(), request, response));
         // set context path as header
         String contextPath = consumer.getEndpoint().getPath();
         exchange.getIn().setHeader("CamelServletContextPath", contextPath);
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
index a96d580..a799a08 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
@@ -30,12 +30,14 @@ import org.apache.camel.util.ObjectHelper;
  */
 public class HttpMessage extends DefaultMessage {
 
-    private HttpServletRequest request;
-    private HttpServletResponse response;
+    private final HttpServletRequest request;
+    private final HttpServletResponse response;
+    private final HttpCommonEndpoint endpoint;
 
-    public HttpMessage(Exchange exchange, HttpServletRequest request, HttpServletResponse
response) {
+    public HttpMessage(Exchange exchange, HttpCommonEndpoint endpoint, HttpServletRequest
request, HttpServletResponse response) {
         setExchange(exchange);
         setCamelContext(exchange.getContext());
+        this.endpoint = endpoint;
 
         this.request = request;
         this.response = response;
@@ -51,13 +53,14 @@ public class HttpMessage extends DefaultMessage {
 
         // use binding to read the request allowing end users to use their
         // implementation of the binding
-        getEndpoint().getHttpBinding().readRequest(request, this);
+        endpoint.getHttpBinding().readRequest(request, this);
     }
 
-    private HttpMessage(HttpServletRequest request, HttpServletResponse response, Exchange
exchange) {
+    private HttpMessage(HttpServletRequest request, HttpServletResponse response, Exchange
exchange, HttpCommonEndpoint endpoint) {
         this.request = request;
         this.response = response;
         setExchange(getExchange());
+        this.endpoint = endpoint;
         setCamelContext(exchange.getContext());
     }
 
@@ -72,7 +75,7 @@ public class HttpMessage extends DefaultMessage {
     @Override
     protected Object createBody() {
         try {
-            return getEndpoint().getHttpBinding().parseBody(this);
+            return endpoint.getHttpBinding().parseBody(this);
         } catch (IOException e) {
             throw new RuntimeCamelException(e);
         }
@@ -80,11 +83,7 @@ public class HttpMessage extends DefaultMessage {
 
     @Override
     public HttpMessage newInstance() {
-        return new HttpMessage(request, response, getExchange());
-    }
-
-    private HttpCommonEndpoint getEndpoint() {
-        return (HttpCommonEndpoint) getExchange().getFromEndpoint();
+        return new HttpMessage(request, response, getExchange(), endpoint);
     }
 
     @Override
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
index 4953570..f6e3d83 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
@@ -34,7 +34,6 @@ import org.apache.camel.http.common.HttpConstants;
 import org.apache.camel.http.common.HttpConsumer;
 import org.apache.camel.http.common.HttpHelper;
 import org.apache.camel.http.common.HttpMessage;
-import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
 import org.eclipse.jetty.continuation.Continuation;
@@ -161,7 +160,7 @@ public class CamelContinuationServlet extends CamelServlet {
             }
 
             // a new request so create an exchange
-            final Exchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut);
+            final Exchange exchange = consumer.getEndpoint().createExchange(ExchangePattern.InOut);
 
             if (consumer.getEndpoint().isBridgeEndpoint()) {
                 exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
@@ -173,7 +172,7 @@ public class CamelContinuationServlet extends CamelServlet {
             
             HttpHelper.setCharsetFromContentType(request.getContentType(), exchange);
             
-            exchange.setIn(new HttpMessage(exchange, request, response));
+            exchange.setIn(new HttpMessage(exchange, consumer.getEndpoint(), request, response));
             // set context path as header
             String contextPath = consumer.getEndpoint().getPath();
             exchange.getIn().setHeader("CamelServletContextPath", contextPath);

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <commits@camel.apache.org>'].

Mime
View raw message