Skip to content

Commit

Permalink
CAMEL-9309: Make it easier to turn on|off java transport over http
Browse files Browse the repository at this point in the history
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
  • Loading branch information
davsclaus committed Nov 12, 2015
1 parent 349109b commit e7fd5f0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -74,6 +75,7 @@ public DefaultHttpBinding(HeaderFilterStrategy headerFilterStrategy) {
public DefaultHttpBinding(HttpEndpoint endpoint) {
this.endpoint = endpoint;
this.headerFilterStrategy = endpoint.getHeaderFilterStrategy();
this.allowJavaSerializedObject = endpoint.getComponent().isAllowJavaSerializedObject();
}

public void readRequest(HttpServletRequest request, HttpMessage message) {
Expand Down Expand Up @@ -137,14 +139,18 @@ public void readRequest(HttpServletRequest request, HttpMessage message) {

// 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");
}
}

Expand Down Expand Up @@ -326,13 +332,17 @@ protected void doWriteDirectResponse(Message message, HttpServletResponse respon
// 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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -348,4 +349,11 @@ public void setHttpConfiguration(HttpConfiguration httpConfiguration) {
this.httpConfiguration = httpConfiguration;
}

public boolean isAllowJavaSerializedObject() {
return allowJavaSerializedObject;
}

public void setAllowJavaSerializedObject(boolean allowJavaSerializedObject) {
this.allowJavaSerializedObject = allowJavaSerializedObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -112,6 +113,11 @@ public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI, Ht
this.httpConnectionManager = httpConnectionManager;
}

@Override
public HttpComponent getComponent() {
return (HttpComponent) super.getComponent();
}

public Producer createProducer() throws Exception {
return new HttpProducer(this);
}
Expand Down

0 comments on commit e7fd5f0

Please sign in to comment.