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 2021/07/19 12:17:39 UTC
[camel] branch main updated: CAMEL-16237 : Allow to easily set
user-agent on component level (#5804)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new f77601c2 CAMEL-16237 : Allow to easily set user-agent on component level (#5804)
f77601c2 is described below
commit f77601c2ee9a3b2bb13a983577562daf5ca89c44
Author: erayerdem <42...@users.noreply.github.com>
AuthorDate: Mon Jul 19 15:17:12 2021 +0300
CAMEL-16237 : Allow to easily set user-agent on component level (#5804)
* Custom User Agent for Apache Http Client
* Adoc configured
* userAgent parameter moved to component options
* userAgent description Update
---
components/camel-http/src/main/docs/http-component.adoc | 6 ++++--
.../org/apache/camel/component/http/HttpEndpoint.java | 15 +++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/components/camel-http/src/main/docs/http-component.adoc b/components/camel-http/src/main/docs/http-component.adoc
index eb70653..97390fb 100644
--- a/components/camel-http/src/main/docs/http-component.adoc
+++ b/components/camel-http/src/main/docs/http-component.adoc
@@ -98,6 +98,8 @@ The HTTP component supports 37 options, which are listed below.
| *connectionRequestTimeout* (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). | -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). | -1 | int
| *socketTimeout* (timeout) | 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). | -1 | int
+| *userAgent* (producer) | Custom User-Agent name | | String
+
|===
// component options: END
@@ -129,17 +131,17 @@ with the following path and query parameters:
|===
-=== Query Parameters (50 parameters):
+=== Query Parameters (51 parameters):
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
+| *chunked* (producer) | If this option is false the Servlet will disable the HTTP streaming and set the content-length header on the response | true | boolean
| *disableStreamCache* (common) | Determines whether or not the raw input stream from Servlet is cached or not (Camel will read the stream into a in memory/overflow to file, Stream caching) cache. By default Camel will cache the Servlet input stream to support reading it multiple times to ensure it Camel can retrieve all data from the stream. However you can set this option to true when you for example need to access the raw stream, such as streaming it directly to a file or other persis [...]
| *headerFilterStrategy* (common) | To use a custom HeaderFilterStrategy to filter header to and from Camel message. | | HeaderFilterStrategy
| *httpBinding* (common) | To use a custom HttpBinding to control the mapping between Camel message and HttpClient. | | HttpBinding
| *bridgeEndpoint* (producer) | If the option is true, HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. You may also set the option throwExceptionOnFailure to be false to let the HttpProducer send all the fault response back. | false | boolean
-| *chunked* (producer) | If this option is false the Servlet will disable the HTTP streaming and set the content-length header on the response | true | boolean
| *clearExpiredCookies* (producer) | Whether to clear expired cookies before sending the HTTP request. This ensures the cookies store does not keep growing by adding new cookies which is newer removed when they are expired. If the component has disabled cookie management then this option is disabled too. | true | boolean
| *connectionClose* (producer) | Specifies whether a Connection Close header must be added to HTTP Request. By default connectionClose is false. | false | boolean
| *copyHeaders* (producer) | If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy. Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers). | true | boolean
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
index fdd282a..e174032 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
@@ -149,6 +149,9 @@ public class HttpEndpoint extends HttpCommonEndpoint {
+ " with many object allocations for the JVM garbage collector.")
private boolean skipResponseHeaders;
+ @UriParam(label = "producer,advanced", description = "Custom User-Agent name")
+ private String userAgent;
+
public HttpEndpoint() {
}
@@ -259,6 +262,10 @@ public class HttpEndpoint extends HttpCommonEndpoint {
// need to use noop cookiestore as we do not want to keep cookies in memory
clientBuilder.setDefaultCookieStore(new NoopCookieStore());
}
+ String userAgent = getUserAgent();
+ if (userAgent != null) {
+ clientBuilder.setUserAgent(userAgent);
+ }
LOG.debug("Setup the HttpClientBuilder {}", clientBuilder);
return clientBuilder.build();
@@ -570,6 +577,14 @@ public class HttpEndpoint extends HttpCommonEndpoint {
this.skipResponseHeaders = skipResponseHeaders;
}
+ public String getUserAgent() {
+ return userAgent;
+ }
+
+ public void setUserAgent(String userAgent) {
+ this.userAgent = userAgent;
+ }
+
@ManagedAttribute(description = "Maximum number of allowed persistent connections")
public int getClientConnectionsPoolStatsMax() {
ConnPoolControl<?> pool = null;