camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/5] camel git commit: CAMEL-8716: camel-http - Make it easier to extend DefaultHttpBinding and have default no-arg ctr
Date Wed, 29 Apr 2015 08:23:05 GMT
CAMEL-8716: camel-http - Make it easier to extend DefaultHttpBinding and have default no-arg
ctr


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

Branch: refs/heads/master
Commit: 0dbc097916465ae0e3850f65b9ee2ade3d32649a
Parents: 4129a58
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Apr 29 08:53:02 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Apr 29 10:26:31 2015 +0200

----------------------------------------------------------------------
 .../component/http/DefaultHttpBinding.java      | 22 +++++++++++++-------
 .../camel/component/http/HttpBinding.java       | 17 +++++++++++++++
 .../camel/component/http/HttpEndpoint.java      | 19 +++++++++++------
 3 files changed, 45 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0dbc0979/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
index e1fa34e..580dc00 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
@@ -58,10 +58,9 @@ public class DefaultHttpBinding implements HttpBinding {
 
     private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpBinding.class);
     private boolean useReaderForPayload;
-    private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
-    private HttpEndpoint endpoint;
+    private boolean transferException;
+    private HeaderFilterStrategy headerFilterStrategy;
 
-    @Deprecated
     public DefaultHttpBinding() {
     }
 
@@ -70,9 +69,10 @@ public class DefaultHttpBinding implements HttpBinding {
         this.headerFilterStrategy = headerFilterStrategy;
     }
 
+    @Deprecated
     public DefaultHttpBinding(HttpEndpoint endpoint) {
-        this.endpoint = endpoint;
         this.headerFilterStrategy = endpoint.getHeaderFilterStrategy();
+        this.transferException = endpoint.isTransferException();
     }
 
     public void readRequest(HttpServletRequest request, HttpMessage message) {
@@ -129,7 +129,7 @@ public class DefaultHttpBinding implements HttpBinding {
             LOG.trace("HTTP method {}", request.getMethod());
             LOG.trace("HTTP query {}", request.getQueryString());
             LOG.trace("HTTP url {}", request.getRequestURL());
-            LOG.trace("HTTP uri {}", request.getRequestURI().toString());
+            LOG.trace("HTTP uri {}", request.getRequestURI());
             LOG.trace("HTTP path {}", request.getPathInfo());
             LOG.trace("HTTP content-type {}", request.getContentType());
         }
@@ -137,7 +137,7 @@ public class DefaultHttpBinding implements HttpBinding {
         // if content type is serialized java object, then de-serialize it to a Java object
         if (request.getContentType() != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(request.getContentType()))
{
             try {
-                InputStream is = endpoint.getCamelContext().getTypeConverter().mandatoryConvertTo(InputStream.class,
body);
+                InputStream is = message.getExchange().getContext().getTypeConverter().mandatoryConvertTo(InputStream.class,
body);
                 Object object = HttpHelper.deserializeJavaObjectFromStream(is, message.getExchange().getContext());
                 if (object != null) {
                     message.setBody(object);
@@ -246,7 +246,7 @@ public class DefaultHttpBinding implements HttpBinding {
         // 500 for internal server error
         response.setStatus(500);
 
-        if (endpoint != null && endpoint.isTransferException()) {
+        if (isTransferException()) {
             // transfer the exception as a serialized java object
             HttpHelper.writeObjectToServletResponse(response, exception);
         } else {
@@ -468,6 +468,14 @@ public class DefaultHttpBinding implements HttpBinding {
         this.useReaderForPayload = useReaderForPayload;
     }
 
+    public boolean isTransferException() {
+        return transferException;
+    }
+
+    public void setTransferException(boolean transferException) {
+        this.transferException = transferException;
+    }
+
     public HeaderFilterStrategy getHeaderFilterStrategy() {
         return headerFilterStrategy;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/0dbc0979/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
index a045aee..25d804d 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.spi.HeaderFilterStrategy;
@@ -116,6 +117,22 @@ public interface HttpBinding {
     void setUseReaderForPayload(boolean useReaderForPayload);
 
     /**
+     * If enabled and an Exchange failed processing on the consumer side, and if the caused
Exception was send back
+     * serialized in the response as a application/x-java-serialized-object content type
(for example using Jetty or
+     * Servlet Camel components). On the producer side the exception will be deserialized
and thrown as is,
+     * instead of the HttpOperationFailedException. The caused exception is required to be
serialized.
+     */
+    boolean isTransferException();
+
+    /**
+     * If enabled and an Exchange failed processing on the consumer side, and if the caused
Exception was send back
+     * serialized in the response as a application/x-java-serialized-object content type
(for example using Jetty or
+     * Servlet Camel components). On the producer side the exception will be deserialized
and thrown as is,
+     * instead of the HttpOperationFailedException. The caused exception is required to be
serialized.
+     */
+    void setTransferException(boolean transferException);
+
+    /**
      * Gets the header filter strategy
      *
      * @return the strategy

http://git-wip-us.apache.org/repos/asf/camel/blob/0dbc0979/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
index 8bf65e5..ac82939 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
@@ -50,14 +50,19 @@ import org.slf4j.LoggerFactory;
 public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware {
 
     private static final Logger LOG = LoggerFactory.getLogger(HttpEndpoint.class);
-    private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
-    private HttpBinding binding;
+
     private HttpComponent component;
-    @UriPath @Metadata(required = "true", label = "producer")
-    private URI httpUri;
     private HttpClientParams clientParams;
     private HttpClientConfigurer httpClientConfigurer;
     private HttpConnectionManager httpConnectionManager;
+    private UrlRewrite urlRewrite;
+
+    @UriPath @Metadata(required = "true", label = "producer")
+    private URI httpUri;
+    @UriParam
+    private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
+    @UriParam
+    private HttpBinding binding;
     @UriParam(defaultValue = "true")
     private boolean throwExceptionOnFailure = true;
     @UriParam
@@ -80,7 +85,6 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
     private boolean traceEnabled;
     @UriParam
     private String httpMethodRestrict;
-    private UrlRewrite urlRewrite;
     @UriParam
     private Integer responseBufferSize;
 
@@ -227,7 +231,10 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
 
     public HttpBinding getBinding() {
         if (binding == null) {
-            binding = new DefaultHttpBinding(this);
+            // create a new binding and use the options from this endpoint
+            binding = new DefaultHttpBinding();
+            binding.setHeaderFilterStrategy(getHeaderFilterStrategy());
+            binding.setTransferException(isTransferException());
         }
         return binding;
     }


Mime
View raw message