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/08/07 08:31:13 UTC

[camel] branch master updated: 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 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 c30da59  CAMEL-13796: Allow to configure idle and connection timeout on camel-salesforce http client and increaase default a bit
c30da59 is described below

commit c30da59f07ca72859082dd2ec09cc250aa15e79f
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        |  4 ++-
 .../component/salesforce/SalesforceComponent.java  | 42 +++++++++++++++++++++-
 .../SalesforceComponentConfiguration.java          | 26 ++++++++++++++
 3 files changed, 70 insertions(+), 2 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 aa0f9fe..4091fc8 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
@@ -619,7 +619,7 @@ for details on how to generate the DTO.
 
 
 // component options: START
-The Salesforce component supports 30 options, which are listed below.
+The Salesforce component supports 32 options, which are listed below.
 
 
 
@@ -642,6 +642,8 @@ The Salesforce component supports 30 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
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 0f2c291..c042be7 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
@@ -76,9 +76,11 @@ public class SalesforceComponent extends DefaultComponent implements SSLContextP
     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() + "/";
 
@@ -145,6 +147,14 @@ public class SalesforceComponent extends DefaultComponent implements SSLContextP
         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")
@@ -538,6 +548,22 @@ public class SalesforceComponent extends DefaultComponent implements SSLContextP
         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;
     }
@@ -723,6 +749,9 @@ public class SalesforceComponent extends DefaultComponent implements SSLContextP
         PropertyBindingSupport.bindProperties(camelContext, 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,
@@ -743,6 +772,14 @@ public class SalesforceComponent extends DefaultComponent implements SSLContextP
         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);
@@ -779,6 +816,9 @@ public class SalesforceComponent extends DefaultComponent implements SSLContextP
     }
 
     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/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 283cbcb..0e28857 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;
@@ -350,6 +360,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;
     }