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 2019/10/01 08:33:17 UTC

[camel] 01/02: CAMEL-13796: Allow to configure idle and connection timeout on camel-salesforce http client and increaase default a bit

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 42c5857d6895aa40655472b5690cd860df4762eb
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 7 10:30:51 2019 +0200

    CAMEL-13796: Allow to configure idle and connection timeout on camel-salesforce http client and increaase default a bit
---
 .../src/main/docs/salesforce-component.adoc        |  8 +++--
 .../component/salesforce/SalesforceComponent.java  | 42 +++++++++++++++++++++-
 .../modules/ROOT/pages/salesforce-component.adoc   |  8 +++--
 .../SalesforceComponentConfiguration.java          | 26 ++++++++++++++
 4 files changed, 79 insertions(+), 5 deletions(-)

diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/docs/salesforce-component.adoc b/components/camel-salesforce/camel-salesforce-component/src/main/docs/salesforce-component.adoc
index 5f1af11..f46918c 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/docs/salesforce-component.adoc
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/docs/salesforce-component.adoc
@@ -600,7 +600,7 @@ for details on how to generated the DTO.
 
 
 // component options: START
-The Salesforce component supports 29 options, which are listed below.
+The Salesforce component supports 31 options, which are listed below.
 
 
 
@@ -623,6 +623,8 @@ The Salesforce component supports 29 options, which are listed below.
 | *longPollingTransport Properties* (common) | Used to set any properties that can be configured on the LongPollingTransport used by the BayeuxClient (CometD) used by the streaming api |  | Map
 | *sslContextParameters* (security) | SSL parameters to use, see SSLContextParameters class for all available options. |  | SSLContextParameters
 | *useGlobalSslContext Parameters* (security) | Enable usage of global SSL context parameters | false | boolean
+| *httpClientIdleTimeout* (common) | Timeout used by the HttpClient when waiting for response from the Salesforce server. | 10000 | long
+| *httpClientConnection Timeout* (common) | Connection timeout used by the HttpClient when connecting to the Salesforce server. | 60000 | long
 | *httpProxyHost* (proxy) | Hostname of the HTTP proxy server to use. |  | String
 | *httpProxyPort* (proxy) | Port number of the HTTP proxy server to use. |  | Integer
 | *httpProxyUsername* (security) | Username to use to authenticate against the HTTP proxy server. |  | String
@@ -736,7 +738,7 @@ When using Spring Boot make sure to use the following Maven dependency to have s
 ----
 
 
-The component supports 85 options, which are listed below.
+The component supports 87 options, which are listed below.
 
 
 
@@ -794,6 +796,8 @@ The component supports 85 options, which are listed below.
 | *camel.component.salesforce.config.serialize-nulls* | Should the NULL values of given DTO be serialized with empty (NULL) values. This affects only JSON data format. | false | Boolean
 | *camel.component.salesforce.config.update-topic* | Whether to update an existing Push Topic when using the Streaming API, defaults to false | false | Boolean
 | *camel.component.salesforce.enabled* | Enable salesforce component | true | Boolean
+| *camel.component.salesforce.http-client-connection-timeout* | Connection timeout used by the HttpClient when connecting to the Salesforce server. | 60000 | Long
+| *camel.component.salesforce.http-client-idle-timeout* | Timeout used by the HttpClient when waiting for response from the Salesforce server. | 10000 | Long
 | *camel.component.salesforce.http-client-properties* | Used to set any properties that can be configured on the underlying HTTP client. Have a look at properties of SalesforceHttpClient and the Jetty HttpClient for all available options. |  | Map
 | *camel.component.salesforce.http-proxy-auth-uri* | Used in authentication against the HTTP proxy server, needs to match the URI of the proxy server in order for the httpProxyUsername and httpProxyPassword to be used for authentication. |  | String
 | *camel.component.salesforce.http-proxy-excluded-addresses* | A list of addresses for which HTTP proxy server should not be used. |  | Set
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceComponent.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceComponent.java
index 54a2024..7ef163c 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceComponent.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceComponent.java
@@ -78,9 +78,11 @@ public class SalesforceComponent extends DefaultComponent implements VerifiableC
     public static final String HTTP_PROXY_USE_DIGEST_AUTH = "httpProxyUseDigestAuth";
     public static final String HTTP_PROXY_AUTH_URI = "httpProxyAuthUri";
     public static final String HTTP_PROXY_REALM = "httpProxyRealm";
+    public static final String HTTP_CONNECTION_TIMEOUT = "httpConnectionTimeout";
+    public static final String HTTP_IDLE_TIMEOUT = "httpIdleTimeout";
 
     static final int CONNECTION_TIMEOUT = 60000;
-    static final int IDLE_TIMEOUT = 5000;
+    static final int IDLE_TIMEOUT = 10000;
     static final Pattern SOBJECT_NAME_PATTERN = Pattern.compile("^.*[\\?&]sObjectName=([^&,]+).*$");
     static final String APEX_CALL_PREFIX = OperationName.APEX_CALL.value() + "/";
 
@@ -149,6 +151,14 @@ public class SalesforceComponent extends DefaultComponent implements VerifiableC
         label = "common,advanced")
     private SalesforceEndpointConfig config;
 
+    @Metadata(description = "Timeout used by the HttpClient when waiting for response from the Salesforce server.",
+            label = "common", defaultValue = "" + IDLE_TIMEOUT)
+    private long httpClientIdleTimeout = IDLE_TIMEOUT;
+
+    @Metadata(description = "Connection timeout used by the HttpClient when connecting to the Salesforce server.",
+            label = "common", defaultValue = "" + CONNECTION_TIMEOUT)
+    private long httpClientConnectionTimeout = CONNECTION_TIMEOUT;
+
     @Metadata(description = "Used to set any properties that can be configured on the underlying HTTP client. Have a"
         + " look at properties of SalesforceHttpClient and the Jetty HttpClient for all available options.",
         label = "common,advanced")
@@ -541,6 +551,22 @@ public class SalesforceComponent extends DefaultComponent implements VerifiableC
         this.useGlobalSslContextParameters = useGlobalSslContextParameters;
     }
 
+    public long getHttpClientIdleTimeout() {
+        return httpClientIdleTimeout;
+    }
+
+    public void setHttpClientIdleTimeout(long httpClientIdleTimeout) {
+        this.httpClientIdleTimeout = httpClientIdleTimeout;
+    }
+
+    public long getHttpClientConnectionTimeout() {
+        return httpClientConnectionTimeout;
+    }
+
+    public void setHttpClientConnectionTimeout(long httpClientConnectionTimeout) {
+        this.httpClientConnectionTimeout = httpClientConnectionTimeout;
+    }
+
     public String getHttpProxyHost() {
         return httpProxyHost;
     }
@@ -734,6 +760,9 @@ public class SalesforceComponent extends DefaultComponent implements VerifiableC
         IntrospectionSupport.setProperties(typeConverter, httpClient,
             new HashMap<>(httpClientProperties));
 
+        final Long httpConnectionTimeout = typeConverter.convertTo(Long.class, httpClientProperties.get(HTTP_CONNECTION_TIMEOUT));
+        final Long httpIdleTimeout = typeConverter.convertTo(Long.class, httpClientProperties.get(HTTP_IDLE_TIMEOUT));
+
         final String httpProxyHost = typeConverter.convertTo(String.class, httpClientProperties.get(HTTP_PROXY_HOST));
         final Integer httpProxyPort = typeConverter.convertTo(Integer.class, httpClientProperties.get(HTTP_PROXY_PORT));
         final boolean isHttpProxySocks4 = typeConverter.convertTo(boolean.class,
@@ -754,6 +783,14 @@ public class SalesforceComponent extends DefaultComponent implements VerifiableC
         final boolean httpProxyUseDigestAuth = typeConverter.convertTo(boolean.class,
             httpClientProperties.get(HTTP_PROXY_USE_DIGEST_AUTH));
 
+        // set HTTP timeout settings
+        if (httpIdleTimeout != null) {
+            httpClient.setIdleTimeout(httpIdleTimeout);
+        }
+        if (httpConnectionTimeout != null) {
+            httpClient.setConnectTimeout(httpConnectionTimeout);
+        }
+
         // set HTTP proxy settings
         if (httpProxyHost != null && httpProxyPort != null) {
             Origin.Address proxyAddress = new Origin.Address(httpProxyHost, httpProxyPort);
@@ -790,6 +827,9 @@ public class SalesforceComponent extends DefaultComponent implements VerifiableC
     }
 
     private static void defineComponentPropertiesIn(final Map<String, Object> httpClientProperties, final SalesforceComponent salesforce) {
+        putValueIfGivenTo(httpClientProperties, HTTP_IDLE_TIMEOUT, salesforce::getHttpClientIdleTimeout);
+        putValueIfGivenTo(httpClientProperties, HTTP_CONNECTION_TIMEOUT, salesforce::getHttpClientConnectionTimeout);
+
         putValueIfGivenTo(httpClientProperties, HTTP_PROXY_HOST, salesforce::getHttpProxyHost);
         putValueIfGivenTo(httpClientProperties, HTTP_PROXY_PORT, salesforce::getHttpProxyPort);
         putValueIfGivenTo(httpClientProperties, HTTP_PROXY_INCLUDE, salesforce::getHttpProxyIncludedAddresses);
diff --git a/docs/components/modules/ROOT/pages/salesforce-component.adoc b/docs/components/modules/ROOT/pages/salesforce-component.adoc
index 90f4c61..4078ed4 100644
--- a/docs/components/modules/ROOT/pages/salesforce-component.adoc
+++ b/docs/components/modules/ROOT/pages/salesforce-component.adoc
@@ -601,7 +601,7 @@ for details on how to generated the DTO.
 
 
 // component options: START
-The Salesforce component supports 29 options, which are listed below.
+The Salesforce component supports 31 options, which are listed below.
 
 
 
@@ -624,6 +624,8 @@ The Salesforce component supports 29 options, which are listed below.
 | *longPollingTransport Properties* (common) | Used to set any properties that can be configured on the LongPollingTransport used by the BayeuxClient (CometD) used by the streaming api |  | Map
 | *sslContextParameters* (security) | SSL parameters to use, see SSLContextParameters class for all available options. |  | SSLContextParameters
 | *useGlobalSslContext Parameters* (security) | Enable usage of global SSL context parameters | false | boolean
+| *httpClientIdleTimeout* (common) | Timeout used by the HttpClient when waiting for response from the Salesforce server. | 10000 | long
+| *httpClientConnection Timeout* (common) | Connection timeout used by the HttpClient when connecting to the Salesforce server. | 60000 | long
 | *httpProxyHost* (proxy) | Hostname of the HTTP proxy server to use. |  | String
 | *httpProxyPort* (proxy) | Port number of the HTTP proxy server to use. |  | Integer
 | *httpProxyUsername* (security) | Username to use to authenticate against the HTTP proxy server. |  | String
@@ -737,7 +739,7 @@ When using Spring Boot make sure to use the following Maven dependency to have s
 ----
 
 
-The component supports 85 options, which are listed below.
+The component supports 87 options, which are listed below.
 
 
 
@@ -795,6 +797,8 @@ The component supports 85 options, which are listed below.
 | *camel.component.salesforce.config.serialize-nulls* | Should the NULL values of given DTO be serialized with empty (NULL) values. This affects only JSON data format. | false | Boolean
 | *camel.component.salesforce.config.update-topic* | Whether to update an existing Push Topic when using the Streaming API, defaults to false | false | Boolean
 | *camel.component.salesforce.enabled* | Enable salesforce component | true | Boolean
+| *camel.component.salesforce.http-client-connection-timeout* | Connection timeout used by the HttpClient when connecting to the Salesforce server. | 60000 | Long
+| *camel.component.salesforce.http-client-idle-timeout* | Timeout used by the HttpClient when waiting for response from the Salesforce server. | 10000 | Long
 | *camel.component.salesforce.http-client-properties* | Used to set any properties that can be configured on the underlying HTTP client. Have a look at properties of SalesforceHttpClient and the Jetty HttpClient for all available options. |  | Map
 | *camel.component.salesforce.http-proxy-auth-uri* | Used in authentication against the HTTP proxy server, needs to match the URI of the proxy server in order for the httpProxyUsername and httpProxyPassword to be used for authentication. |  | String
 | *camel.component.salesforce.http-proxy-excluded-addresses* | A list of addresses for which HTTP proxy server should not be used. |  | Set
diff --git a/platforms/spring-boot/components-starter/camel-salesforce-starter/src/main/java/org/apache/camel/component/salesforce/springboot/SalesforceComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-salesforce-starter/src/main/java/org/apache/camel/component/salesforce/springboot/SalesforceComponentConfiguration.java
index ba7c6df..459fe30 100644
--- a/platforms/spring-boot/components-starter/camel-salesforce-starter/src/main/java/org/apache/camel/component/salesforce/springboot/SalesforceComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-salesforce-starter/src/main/java/org/apache/camel/component/salesforce/springboot/SalesforceComponentConfiguration.java
@@ -153,6 +153,16 @@ public class SalesforceComponentConfiguration
      */
     private Boolean useGlobalSslContextParameters = false;
     /**
+     * Timeout used by the HttpClient when waiting for response from the
+     * Salesforce server.
+     */
+    private Long httpClientIdleTimeout = 10000L;
+    /**
+     * Connection timeout used by the HttpClient when connecting to the
+     * Salesforce server.
+     */
+    private Long httpClientConnectionTimeout = 60000L;
+    /**
      * Hostname of the HTTP proxy server to use.
      */
     private String httpProxyHost;
@@ -345,6 +355,22 @@ public class SalesforceComponentConfiguration
         this.useGlobalSslContextParameters = useGlobalSslContextParameters;
     }
 
+    public Long getHttpClientIdleTimeout() {
+        return httpClientIdleTimeout;
+    }
+
+    public void setHttpClientIdleTimeout(Long httpClientIdleTimeout) {
+        this.httpClientIdleTimeout = httpClientIdleTimeout;
+    }
+
+    public Long getHttpClientConnectionTimeout() {
+        return httpClientConnectionTimeout;
+    }
+
+    public void setHttpClientConnectionTimeout(Long httpClientConnectionTimeout) {
+        this.httpClientConnectionTimeout = httpClientConnectionTimeout;
+    }
+
     public String getHttpProxyHost() {
         return httpProxyHost;
     }