CAMEL-9309: Make it easier to turn on|off java transport over http

Conflicts:
        
components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
        
components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonComponent.java
        
components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java


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

Branch: refs/heads/camel-2.15.x
Commit: e7fd5f049c2fd51a528f8062da91a1c75e33b0e8
Parents: 349109b
Author: Claus Ibsen <[email protected]>
Authored: Thu Nov 12 11:18:36 2015 +0100
Committer: Claus Ibsen <[email protected]>
Committed: Thu Nov 12 18:41:44 2015 +0100

----------------------------------------------------------------------
 .../component/http/DefaultHttpBinding.java      | 38 ++++++++++++--------
 .../camel/component/http/HttpComponent.java     |  8 +++++
 .../camel/component/http/HttpEndpoint.java      |  6 ++++
 3 files changed, 38 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e7fd5f04/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 f080021..d0ea5f1 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
@@ -59,6 +59,7 @@ public class DefaultHttpBinding implements HttpBinding {
     private static final Logger LOG = 
LoggerFactory.getLogger(DefaultHttpBinding.class);
     private boolean useReaderForPayload;
     private boolean eagerCheckContentAvailable;
+    private boolean allowJavaSerializedObject;
     private HeaderFilterStrategy headerFilterStrategy = new 
HttpHeaderFilterStrategy();
     private HttpEndpoint endpoint;
 
@@ -74,6 +75,7 @@ public class DefaultHttpBinding implements HttpBinding {
     public DefaultHttpBinding(HttpEndpoint endpoint) {
         this.endpoint = endpoint;
         this.headerFilterStrategy = endpoint.getHeaderFilterStrategy();
+        this.allowJavaSerializedObject = 
endpoint.getComponent().isAllowJavaSerializedObject();
     }
 
     public void readRequest(HttpServletRequest request, HttpMessage message) {
@@ -137,14 +139,18 @@ 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);
-                Object object = HttpHelper.deserializeJavaObjectFromStream(is);
-                if (object != null) {
-                    message.setBody(object);
+            if (allowJavaSerializedObject || endpoint.isTransferException()) {
+                try {
+                    InputStream is = 
endpoint.getCamelContext().getTypeConverter().mandatoryConvertTo(InputStream.class,
 body);
+                    Object object = 
HttpHelper.deserializeJavaObjectFromStream(is);
+                    if (object != null) {
+                        message.setBody(object);
+                    }
+                } catch (Exception e) {
+                    throw new RuntimeCamelException("Cannot deserialize body 
to Java object", e);
                 }
-            } catch (Exception e) {
-                throw new RuntimeCamelException("Cannot deserialize body to 
Java object", e);
+            } else {
+                throw new RuntimeCamelException("Content-type " + 
HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT + " is not allowed");
             }
         }
         
@@ -326,13 +332,17 @@ public class DefaultHttpBinding implements HttpBinding {
         // if content type is serialized Java object, then serialize and write 
it to the response
         String contentType = message.getHeader(Exchange.CONTENT_TYPE, 
String.class);
         if (contentType != null && 
HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(contentType)) {
-            try {
-                Object object = message.getMandatoryBody(Serializable.class);
-                HttpHelper.writeObjectToServletResponse(response, object);
-                // object is written so return
-                return;
-            } catch (InvalidPayloadException e) {
-                throw new IOException(e);
+            if (allowJavaSerializedObject || endpoint.isTransferException()) {
+                try {
+                    Object object = 
message.getMandatoryBody(Serializable.class);
+                    HttpHelper.writeObjectToServletResponse(response, object);
+                    // object is written so return
+                    return;
+                } catch (InvalidPayloadException e) {
+                    throw new IOException(e);
+                }
+            } else {
+                throw new RuntimeCamelException("Content-type " + 
HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT + " is not allowed");
             }
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/e7fd5f04/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
 
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
index 9256c9b..1ef9c9d 100644
--- 
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
+++ 
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
@@ -47,6 +47,7 @@ public class HttpComponent extends 
HeaderFilterStrategyComponent {
     protected HttpConnectionManager httpConnectionManager;
     protected HttpBinding httpBinding;
     protected HttpConfiguration httpConfiguration;
+    protected boolean allowJavaSerializedObject;
 
     public HttpComponent() {
         super(HttpEndpoint.class);
@@ -348,4 +349,11 @@ public class HttpComponent extends 
HeaderFilterStrategyComponent {
         this.httpConfiguration = httpConfiguration;
     }
 
+    public boolean isAllowJavaSerializedObject() {
+        return allowJavaSerializedObject;
+    }
+
+    public void setAllowJavaSerializedObject(boolean 
allowJavaSerializedObject) {
+        this.allowJavaSerializedObject = allowJavaSerializedObject;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e7fd5f04/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 97f01ee..cad38b1 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
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.PollingConsumer;
 import org.apache.camel.Processor;
@@ -112,6 +113,11 @@ public class HttpEndpoint extends DefaultEndpoint 
implements HeaderFilterStrateg
         this.httpConnectionManager = httpConnectionManager;
     }
 
+    @Override
+    public HttpComponent getComponent() {
+        return (HttpComponent) super.getComponent();
+    }
+
     public Producer createProducer() throws Exception {
         return new HttpProducer(this);
     }

Reply via email to