You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/04/29 10:23:08 UTC
[5/5] camel git commit: CAMEL-8716: camel-http - Make it easier to
extend DefaultHttpBinding and have default no-arg ctr
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/8962627f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8962627f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8962627f
Branch: refs/heads/master
Commit: 8962627fb073e969d72f6a211c9f5589a90eb944
Parents: 9305806
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Apr 29 09:36:40 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Apr 29 10:26:32 2015 +0200
----------------------------------------------------------------------
.../component/http/DefaultHttpBinding.java | 4 +++-
.../component/http4/DefaultHttpBinding.java | 22 ++++++++++++++------
.../camel/component/http4/HttpBinding.java | 16 ++++++++++++++
.../camel/component/http4/HttpEndpoint.java | 22 +++++++++++++-------
4 files changed, 49 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8962627f/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 580dc00..6617f70 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
@@ -51,6 +51,8 @@ import org.slf4j.LoggerFactory;
/**
* Binding between {@link HttpMessage} and {@link HttpServletResponse}.
+ * <p/>
+ * Uses by default the {@link org.apache.camel.component.http.HttpHeaderFilterStrategy}
*
* @version
*/
@@ -59,7 +61,7 @@ public class DefaultHttpBinding implements HttpBinding {
private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpBinding.class);
private boolean useReaderForPayload;
private boolean transferException;
- private HeaderFilterStrategy headerFilterStrategy;
+ private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
public DefaultHttpBinding() {
}
http://git-wip-us.apache.org/repos/asf/camel/blob/8962627f/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
index 7064c78..f94a3c1 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
@@ -51,6 +51,8 @@ import org.slf4j.LoggerFactory;
/**
* Binding between {@link HttpMessage} and {@link HttpServletResponse}.
+ * <p/>
+ * Uses by default the {@link org.apache.camel.component.http4.HttpHeaderFilterStrategy}
*
* @version
*/
@@ -58,10 +60,9 @@ public class DefaultHttpBinding implements HttpBinding {
private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpBinding.class);
private boolean useReaderForPayload;
+ private boolean transferException;
private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
- private HttpEndpoint endpoint;
- @Deprecated
public DefaultHttpBinding() {
}
@@ -70,9 +71,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) {
@@ -124,8 +126,8 @@ 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);
+ InputStream is = message.getExchange().getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, body);
+ Object object = HttpHelper.deserializeJavaObjectFromStream(is, message.getExchange().getContext());
if (object != null) {
message.setBody(object);
}
@@ -229,7 +231,7 @@ public class DefaultHttpBinding implements HttpBinding {
public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException {
// 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 {
@@ -431,6 +433,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/8962627f/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java
index 339f13b..6f667e8 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java
@@ -116,6 +116,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/8962627f/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
index 4229c1c..03724b5 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
@@ -52,16 +52,21 @@ 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 HttpContext httpContext;
private HttpComponent component;
- @UriPath @Metadata(required = "true")
- private URI httpUri;
private HttpClientConfigurer httpClientConfigurer;
private HttpClientConnectionManager clientConnectionManager;
private HttpClientBuilder clientBuilder;
private HttpClient httpClient;
+ private UrlRewrite urlRewrite;
+ private CookieStore cookieStore = new BasicCookieStore();
+
+ @UriPath @Metadata(required = "true")
+ private URI httpUri;
+ @UriParam
+ private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
+ @UriParam
+ private HttpBinding binding;
@UriParam(defaultValue = "true")
private boolean throwExceptionOnFailure = true;
@UriParam
@@ -80,11 +85,9 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
private boolean authenticationPreemptive;
@UriParam
private String httpMethodRestrict;
- private UrlRewrite urlRewrite;
@UriParam(defaultValue = "true")
private boolean clearExpiredCookies = true;
- private CookieStore cookieStore = new BasicCookieStore();
-
+
public HttpEndpoint() {
}
@@ -252,7 +255,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;
}