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 2018/03/05 15:31:34 UTC
[camel] branch master updated: CAMEL-12270: Make it easier to
configure timeout options on http4 component.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 76cfe34 CAMEL-12270: Make it easier to configure timeout options on http4 component.
76cfe34 is described below
commit 76cfe3435751dcee7fef42a2627d6dd476f8a210
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 5 16:31:15 2018 +0100
CAMEL-12270: Make it easier to configure timeout options on http4 component.
---
.../camel-http4/src/main/docs/http4-component.adoc | 5 +-
.../camel/component/http4/HttpComponent.java | 95 +++++++++++++++++++++-
.../apache/camel/component/http4/HttpEndpoint.java | 78 ++++++++++++++++++
.../camel/component/http4/HttpSOTimeoutTest.java | 21 +++++
.../springboot/HttpComponentConfiguration.java | 47 +++++++++++
5 files changed, 242 insertions(+), 4 deletions(-)
diff --git a/components/camel-http4/src/main/docs/http4-component.adoc b/components/camel-http4/src/main/docs/http4-component.adoc
index 3bb3fe0..a673c71 100644
--- a/components/camel-http4/src/main/docs/http4-component.adoc
+++ b/components/camel-http4/src/main/docs/http4-component.adoc
@@ -52,7 +52,7 @@ route, use the <<jetty-component,Jetty Component>> instead.
// component options: START
-The HTTP4 component supports 15 options which are listed below.
+The HTTP4 component supports 18 options which are listed below.
@@ -69,6 +69,9 @@ The HTTP4 component supports 15 options which are listed below.
| *connectionsPerRoute* (advanced) | The maximum number of connections per route. | 20 | int
| *connectionTimeToLive* (advanced) | The time for connection to live, the time unit is millisecond, the default value is always keep alive. | | long
| *cookieStore* (producer) | To use a custom org.apache.http.client.CookieStore. By default the org.apache.http.impl.client.BasicCookieStore is used which is an in-memory only cookie store. Notice if bridgeEndpoint=true then the cookie store is forced to be a noop cookie store as cookie shouldn't be stored as we are just bridging (eg acting as a proxy). | | CookieStore
+| *connectionRequest Timeout* (timeout) | The timeout in milliseconds used when requesting a connection from the connection manager. A timeout value of zero is interpreted as an infinite timeout. A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default). Default: code -1 | -1 | int
+| *connectTimeout* (timeout) | Determines the timeout in milliseconds until a connection is established. A timeout value of zero is interpreted as an infinite timeout. A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default). Default: code -1 | -1 | int
+| *socketTimeout* (timeout) | Defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets). A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default). Default: code -1 | -1 | int
| *httpBinding* (advanced) | To use a custom HttpBinding to control the mapping between Camel message and HttpClient. | | HttpBinding
| *httpConfiguration* (advanced) | To use the shared HttpConfiguration as base configuration. | | HttpConfiguration
| *allowJavaSerialized Object* (advanced) | Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object. This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk. | false | boolean
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
index 0273929..eedc0f0 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
@@ -94,6 +94,24 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
+ " shouldn't be stored as we are just bridging (eg acting as a proxy).")
protected CookieStore cookieStore;
+ // timeout
+ @Metadata(label = "timeout", defaultValue = "-1", description = "The timeout in milliseconds used when requesting a connection"
+ + " from the connection manager. A timeout value of zero is interpreted as an infinite timeout."
+ + " A timeout value of zero is interpreted as an infinite timeout."
+ + " A negative value is interpreted as undefined (system default).")
+ protected int connectionRequestTimeout = -1;
+ @Metadata(label = "timeout", defaultValue = "-1", description = "Determines the timeout in milliseconds until a connection is established."
+ + " A timeout value of zero is interpreted as an infinite timeout."
+ + " A timeout value of zero is interpreted as an infinite timeout."
+ + " A negative value is interpreted as undefined (system default).")
+ protected int connectTimeout = -1;
+ @Metadata(label = "timeout", defaultValue = "-1", description = "Defines the socket timeout in milliseconds,"
+ + " which is the timeout for waiting for data or, put differently,"
+ + " a maximum period inactivity between two consecutive data packets)."
+ + " A timeout value of zero is interpreted as an infinite timeout."
+ + " A negative value is interpreted as undefined (system default).")
+ protected int socketTimeout = -1;
+
// options to the default created http connection manager
@Metadata(label = "advanced", defaultValue = "200", description = "The maximum number of connections.")
protected int maxTotalConnections = 200;
@@ -181,6 +199,21 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
final Map<String, Object> httpClientOptions = new HashMap<>();
+
+ // timeout values can be configured on both component and endpoint level, where endpoint take priority
+ int val = getAndRemoveParameter(parameters, "connectionRequestTimeout", int.class, connectionRequestTimeout);
+ if (val != -1) {
+ httpClientOptions.put("connectionRequestTimeout", val);
+ }
+ val = getAndRemoveParameter(parameters, "connectTimeout", int.class, connectTimeout);
+ if (val != -1) {
+ httpClientOptions.put("connectTimeout", val);
+ }
+ val = getAndRemoveParameter(parameters, "socketTimeout", int.class, socketTimeout);
+ if (val != -1) {
+ httpClientOptions.put("socketTimeout", val);
+ }
+
final HttpClientBuilder clientBuilder = createHttpClientBuilder(uri, parameters, httpClientOptions);
HttpBinding httpBinding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class);
@@ -257,9 +290,6 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
// configure the endpoint
setProperties(endpoint, parameters);
- // determine the portnumber (special case: default portnumber)
- //int port = getPort(uriHttpUriAddress);
-
// we can not change the port of an URI, we must create a new one with an explicit port value
URI httpUri = URISupport.createRemainingURI(
new URI(uriHttpUriAddress.getScheme(),
@@ -535,6 +565,65 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
this.cookieStore = cookieStore;
}
+ public int getConnectionRequestTimeout() {
+ return connectionRequestTimeout;
+ }
+
+ /**
+ * The timeout in milliseconds used when requesting a connection
+ * from the connection manager. A timeout value of zero is interpreted
+ * as an infinite timeout.
+ * <p>
+ * A timeout value of zero is interpreted as an infinite timeout.
+ * A negative value is interpreted as undefined (system default).
+ * </p>
+ * <p>
+ * Default: {@code -1}
+ * </p>
+ */
+ public void setConnectionRequestTimeout(int connectionRequestTimeout) {
+ this.connectionRequestTimeout = connectionRequestTimeout;
+ }
+
+ public int getConnectTimeout() {
+ return connectTimeout;
+ }
+
+ /**
+ * Determines the timeout in milliseconds until a connection is established.
+ * A timeout value of zero is interpreted as an infinite timeout.
+ * <p>
+ * A timeout value of zero is interpreted as an infinite timeout.
+ * A negative value is interpreted as undefined (system default).
+ * </p>
+ * <p>
+ * Default: {@code -1}
+ * </p>
+ */
+ public void setConnectTimeout(int connectTimeout) {
+ this.connectTimeout = connectTimeout;
+ }
+
+ public int getSocketTimeout() {
+ return socketTimeout;
+ }
+
+ /**
+ * Defines the socket timeout ({@code SO_TIMEOUT}) in milliseconds,
+ * which is the timeout for waiting for data or, put differently,
+ * a maximum period inactivity between two consecutive data packets).
+ * <p>
+ * A timeout value of zero is interpreted as an infinite timeout.
+ * A negative value is interpreted as undefined (system default).
+ * </p>
+ * <p>
+ * Default: {@code -1}
+ * </p>
+ */
+ public void setSocketTimeout(int socketTimeout) {
+ this.socketTimeout = socketTimeout;
+ }
+
@Override
public void doStart() throws Exception {
super.doStart();
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 cddd51f..3c8f875 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
@@ -29,6 +29,7 @@ import org.apache.camel.Producer;
import org.apache.camel.http.common.HttpCommonEndpoint;
import org.apache.camel.http.common.HttpHelper;
import org.apache.camel.http.common.cookie.CookieHandler;
+import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.util.IOHelper;
@@ -70,6 +71,23 @@ public class HttpEndpoint extends HttpCommonEndpoint {
@UriParam(label = "advanced", defaultValue = "false", description = "To use System Properties as fallback for configuration")
private boolean useSystemProperties;
+ // timeout
+ @Metadata(label = "timeout", defaultValue = "-1", description = "The timeout in milliseconds used when requesting a connection"
+ + " from the connection manager. A timeout value of zero is interpreted as an infinite timeout."
+ + " A timeout value of zero is interpreted as an infinite timeout."
+ + " A negative value is interpreted as undefined (system default).")
+ private int connectionRequestTimeout = -1;
+ @Metadata(label = "timeout", defaultValue = "-1", description = "Determines the timeout in milliseconds until a connection is established."
+ + " A timeout value of zero is interpreted as an infinite timeout."
+ + " A timeout value of zero is interpreted as an infinite timeout."
+ + " A negative value is interpreted as undefined (system default).")
+ private int connectTimeout = -1;
+ @Metadata(label = "timeout", defaultValue = "-1", description = "Defines the socket timeout in milliseconds,"
+ + " which is the timeout for waiting for data or, put differently,"
+ + " a maximum period inactivity between two consecutive data packets)."
+ + " A timeout value of zero is interpreted as an infinite timeout."
+ + " A negative value is interpreted as undefined (system default).")
+ private int socketTimeout = -1;
@UriParam(label = "producer", description = "To use a custom CookieStore."
+ " By default the BasicCookieStore is used which is an in-memory only cookie store."
+ " Notice if bridgeEndpoint=true then the cookie store is forced to be a noop cookie store as cookie shouldn't be stored as we are just bridging (eg acting as a proxy)."
@@ -377,4 +395,64 @@ public class HttpEndpoint extends HttpCommonEndpoint {
public void setX509HostnameVerifier(HostnameVerifier x509HostnameVerifier) {
this.x509HostnameVerifier = x509HostnameVerifier;
}
+
+ public int getConnectionRequestTimeout() {
+ return connectionRequestTimeout;
+ }
+
+ /**
+ * The timeout in milliseconds used when requesting a connection
+ * from the connection manager. A timeout value of zero is interpreted
+ * as an infinite timeout.
+ * <p>
+ * A timeout value of zero is interpreted as an infinite timeout.
+ * A negative value is interpreted as undefined (system default).
+ * </p>
+ * <p>
+ * Default: {@code -1}
+ * </p>
+ */
+ public void setConnectionRequestTimeout(int connectionRequestTimeout) {
+ this.connectionRequestTimeout = connectionRequestTimeout;
+ }
+
+ public int getConnectTimeout() {
+ return connectTimeout;
+ }
+
+ /**
+ * Determines the timeout in milliseconds until a connection is established.
+ * A timeout value of zero is interpreted as an infinite timeout.
+ * <p>
+ * A timeout value of zero is interpreted as an infinite timeout.
+ * A negative value is interpreted as undefined (system default).
+ * </p>
+ * <p>
+ * Default: {@code -1}
+ * </p>
+ */
+ public void setConnectTimeout(int connectTimeout) {
+ this.connectTimeout = connectTimeout;
+ }
+
+ public int getSocketTimeout() {
+ return socketTimeout;
+ }
+
+ /**
+ * Defines the socket timeout ({@code SO_TIMEOUT}) in milliseconds,
+ * which is the timeout for waiting for data or, put differently,
+ * a maximum period inactivity between two consecutive data packets).
+ * <p>
+ * A timeout value of zero is interpreted as an infinite timeout.
+ * A negative value is interpreted as undefined (system default).
+ * </p>
+ * <p>
+ * Default: {@code -1}
+ * </p>
+ */
+ public void setSocketTimeout(int socketTimeout) {
+ this.socketTimeout = socketTimeout;
+ }
+
}
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSOTimeoutTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSOTimeoutTest.java
index 3317ecc..bdcfa46 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSOTimeoutTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSOTimeoutTest.java
@@ -77,4 +77,25 @@ public class HttpSOTimeoutTest extends BaseHttpTest {
Exception e = reply.getException();
assertNotNull("Should have thrown an exception", e);
}
+
+ @Test
+ public void httpGetUriOption() throws Exception {
+ Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "?socketTimeout=5000", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ }
+ });
+
+ assertExchange(exchange);
+ }
+
+ @Test
+ public void httpGetUriOptionShouldThrowASocketTimeoutException() throws Exception {
+ Exchange reply = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "?socketTimeout=1000", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ }
+ });
+ Exception e = reply.getException();
+ assertNotNull("Should have thrown an exception", e);
+ }
+
}
\ No newline at end of file
diff --git a/platforms/spring-boot/components-starter/camel-http4-starter/src/main/java/org/apache/camel/component/http4/springboot/HttpComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-http4-starter/src/main/java/org/apache/camel/component/http4/springboot/HttpComponentConfiguration.java
index d3921f1..c3e14a8 100644
--- a/platforms/spring-boot/components-starter/camel-http4-starter/src/main/java/org/apache/camel/component/http4/springboot/HttpComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-http4-starter/src/main/java/org/apache/camel/component/http4/springboot/HttpComponentConfiguration.java
@@ -100,6 +100,29 @@ public class HttpComponentConfiguration
@NestedConfigurationProperty
private CookieStore cookieStore;
/**
+ * The timeout in milliseconds used when requesting a connection from the
+ * connection manager. A timeout value of zero is interpreted as an infinite
+ * timeout. A timeout value of zero is interpreted as an infinite timeout. A
+ * negative value is interpreted as undefined (system default). Default:
+ * code -1
+ */
+ private Integer connectionRequestTimeout = -1;
+ /**
+ * Determines the timeout in milliseconds until a connection is established.
+ * A timeout value of zero is interpreted as an infinite timeout. A timeout
+ * value of zero is interpreted as an infinite timeout. A negative value is
+ * interpreted as undefined (system default). Default: code -1
+ */
+ private Integer connectTimeout = -1;
+ /**
+ * Defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the
+ * timeout for waiting for data or, put differently, a maximum period
+ * inactivity between two consecutive data packets). A timeout value of zero
+ * is interpreted as an infinite timeout. A negative value is interpreted as
+ * undefined (system default). Default: code -1
+ */
+ private Integer socketTimeout = -1;
+ /**
* To use a custom HttpBinding to control the mapping between Camel message
* and HttpClient.
*/
@@ -215,6 +238,30 @@ public class HttpComponentConfiguration
this.cookieStore = cookieStore;
}
+ public Integer getConnectionRequestTimeout() {
+ return connectionRequestTimeout;
+ }
+
+ public void setConnectionRequestTimeout(Integer connectionRequestTimeout) {
+ this.connectionRequestTimeout = connectionRequestTimeout;
+ }
+
+ public Integer getConnectTimeout() {
+ return connectTimeout;
+ }
+
+ public void setConnectTimeout(Integer connectTimeout) {
+ this.connectTimeout = connectTimeout;
+ }
+
+ public Integer getSocketTimeout() {
+ return socketTimeout;
+ }
+
+ public void setSocketTimeout(Integer socketTimeout) {
+ this.socketTimeout = socketTimeout;
+ }
+
public HttpBinding getHttpBinding() {
return httpBinding;
}
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.