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/06/09 13:43:02 UTC

[camel] branch master updated: CAMEL-12567: camel-stream - Add support for configuring timeout for HTTP urls

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 41be489  CAMEL-12567: camel-stream - Add support for configuring timeout for HTTP urls
41be489 is described below

commit 41be4891581af98ec4f5c47e59c84986b147e1b8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Jun 9 15:42:45 2018 +0200

    CAMEL-12567: camel-stream - Add support for configuring timeout for HTTP urls
---
 .../src/main/docs/stream-component.adoc            |  4 ++-
 .../camel/component/stream/StreamConsumer.java     |  6 ++++
 .../camel/component/stream/StreamEndpoint.java     | 36 ++++++++++++++++++++++
 .../camel/component/stream/StreamProducer.java     |  8 +++--
 4 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/components/camel-stream/src/main/docs/stream-component.adoc b/components/camel-stream/src/main/docs/stream-component.adoc
index 5eb5134..f0dca33 100644
--- a/components/camel-stream/src/main/docs/stream-component.adoc
+++ b/components/camel-stream/src/main/docs/stream-component.adoc
@@ -72,7 +72,7 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (20 parameters):
+==== Query Parameters (22 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -96,7 +96,9 @@ with the following path and query parameters:
 | *autoCloseCount* (producer) | Number of messages to process before closing stream on Producer side. Never close stream by default (only when Producer is stopped). If more messages are sent, the stream is reopened for another autoCloseCount batch. |  | int
 | *closeOnDone* (producer) | This option is used in combination with Splitter and streaming to the same file. The idea is to keep the stream open and only close when the Splitter is done, to improve performance. Mind this requires that you only stream to the same file, and not 2 or more files. | false | boolean
 | *delay* (producer) | Initial delay in milliseconds before producing the stream. |  | long
+| *connectTimeout* (advanced) | Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection. If the timeout expires before the connection can be established, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout. |  | int
 | *httpHeaders* (advanced) | Optional http headers to use in request when using HTTP URL. |  | Map
+| *readTimeout* (advanced) | Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout. |  | int
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
 |===
 // endpoint options: END
diff --git a/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java b/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
index ac39fde..a9d62d0 100644
--- a/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
+++ b/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
@@ -296,6 +296,12 @@ public class StreamConsumer extends DefaultConsumer implements Runnable {
 
         URL url = new URL(u);
         URLConnection c = url.openConnection();
+        if (endpoint.getConnectTimeout() > 0) {
+            c.setConnectTimeout(endpoint.getConnectTimeout());
+        }
+        if (endpoint.getReadTimeout() > 0) {
+            c.setReadTimeout(endpoint.getReadTimeout());
+        }
         if (endpoint.getHttpHeaders() != null) {
             endpoint.getHttpHeaders().forEach((k, v) -> c.addRequestProperty(k, v.toString()));
         }
diff --git a/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java b/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java
index 50eb80a..59c0cd8 100644
--- a/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java
+++ b/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java
@@ -75,6 +75,10 @@ public class StreamEndpoint extends DefaultEndpoint {
     private GroupStrategy groupStrategy = new DefaultGroupStrategy();
     @UriParam(label = "advanced", prefix = "httpHeaders.", multiValue = true)
     private Map<String, Object> httpHeaders;
+    @UriParam(label = "advanced")
+    private int connectTimeout;
+    @UriParam(label = "advanced")
+    private int readTimeout;
 
     public StreamEndpoint(String endpointUri, Component component) throws Exception {
         super(endpointUri, component);
@@ -314,6 +318,38 @@ public class StreamEndpoint extends DefaultEndpoint {
         this.httpHeaders = httpHeaders;
     }
 
+    public int getConnectTimeout() {
+        return connectTimeout;
+    }
+
+    /**
+     * Sets a specified timeout value, in milliseconds, to be used
+     * when opening a communications link to the resource referenced
+     * by this URLConnection.  If the timeout expires before the
+     * connection can be established, a
+     * java.net.SocketTimeoutException is raised. A timeout of zero is
+     * interpreted as an infinite timeout.
+     */
+    public void setConnectTimeout(int connectTimeout) {
+        this.connectTimeout = connectTimeout;
+    }
+
+    public int getReadTimeout() {
+        return readTimeout;
+    }
+
+    /**
+     * Sets the read timeout to a specified timeout, in
+     * milliseconds. A non-zero value specifies the timeout when
+     * reading from Input stream when a connection is established to a
+     * resource. If the timeout expires before there is data available
+     * for read, a java.net.SocketTimeoutException is raised. A
+     * timeout of zero is interpreted as an infinite timeout.
+     */
+    public void setReadTimeout(int readTimeout) {
+        this.readTimeout = readTimeout;
+    }
+
     // Implementations
     //-------------------------------------------------------------------------
 
diff --git a/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java b/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
index 1e5e5fd..2362e6b 100644
--- a/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
+++ b/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
@@ -91,11 +91,15 @@ public class StreamProducer extends DefaultProducer {
         URL url = new URL(u);
         URLConnection c = url.openConnection();
         c.setDoOutput(true);
-
+        if (endpoint.getConnectTimeout() > 0) {
+            c.setConnectTimeout(endpoint.getConnectTimeout());
+        }
+        if (endpoint.getReadTimeout() > 0) {
+            c.setReadTimeout(endpoint.getReadTimeout());
+        }
         if (endpoint.getHttpHeaders() != null) {
             endpoint.getHttpHeaders().forEach((k, v) -> c.addRequestProperty(k, v.toString()));
         }
-
         return c.getOutputStream();
     }
 

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.