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

nfilotto pushed a commit to branch CAMEL-17792/doc-message-headers
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f957bd70c2d04a76620ad3f492a64c8daae3e22e
Author: Nicolas Filotto <[email protected]>
AuthorDate: Mon Mar 14 19:36:12 2022 +0100

    CAMEL-17792: Add doc about the message headers of camel-ahc
---
 .../org/apache/camel/component/ahc/ahc.json        | 13 +++++++++
 .../camel-ahc/src/main/docs/ahc-component.adoc     | 29 ++------------------
 .../apache/camel/component/ahc/AhcConstants.java   | 32 ++++++++++++++++++++++
 .../apache/camel/component/ahc/AhcEndpoint.java    |  2 +-
 .../camel/component/ahc/DefaultAhcBinding.java     | 16 +++++------
 .../camel/component/ahc/helper/AhcHelper.java      |  9 +++---
 6 files changed, 62 insertions(+), 39 deletions(-)

diff --git 
a/components/camel-ahc/src/generated/resources/org/apache/camel/component/ahc/ahc.json
 
b/components/camel-ahc/src/generated/resources/org/apache/camel/component/ahc/ahc.json
index f8686b0..789a166 100644
--- 
a/components/camel-ahc/src/generated/resources/org/apache/camel/component/ahc/ahc.json
+++ 
b/components/camel-ahc/src/generated/resources/org/apache/camel/component/ahc/ahc.json
@@ -32,6 +32,19 @@
     "sslContextParameters": { "kind": "property", "displayName": "Ssl Context 
Parameters", "group": "security", "label": "security", "required": false, 
"type": "object", "javaType": 
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false, 
"autowired": false, "secret": false, "description": "Reference to a 
org.apache.camel.support.jsse.SSLContextParameters in the Registry. Note that 
configuring this option will override any SSL\/TLS configuration options 
provided through [...]
     "useGlobalSslContextParameters": { "kind": "property", "displayName": "Use 
Global Ssl Context Parameters", "group": "security", "label": "security", 
"required": false, "type": "boolean", "javaType": "boolean", "deprecated": 
false, "autowired": false, "secret": false, "defaultValue": false, 
"description": "Enable usage of global SSL context parameters." }
   },
+  "headers": {
+    "CamelHttpResponseCode": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "int", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "The HTTP response code from the external server. Is 200 for 
OK." },
+    "CamelHttpResponseText": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "java.lang.String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The Http response status text" },
+    "Content-Length": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "int", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "The content length of the response" },
+    "CamelHttpMethod": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "java.lang.String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The http method to execute" },
+    "Content-Encoding": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "java.lang.String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The HTTP content encoding. Is set on both the IN and OUT 
message to provide a content encoding, such as `gzip`." },
+    "Content-Type": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "java.lang.String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The HTTP content type. Is set on both the IN and OUT 
message to provide a content type, such as `text\/html`" },
+    "Location": { "kind": "header", "displayName": "", "group": "producer", 
"label": "", "required": false, "javaType": "java.lang.String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "The redirect location" },
+    "CamelHttpUri": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "java.lang.String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "URI to call. Will override existing URI set directly on 
the endpoint." },
+    "CamelHttpPath": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "java.lang.String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "Request URI's path, the header will be used to build the 
request URI with the HTTP_URI. If the path is start with \"\/\", http producer 
will try to find the relative path based on the Exchange.HTTP_BASE_URI header 
or the `exchange.getFromEndpoint().g [...]
+    "CamelHttpBaseUri": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "java.lang.String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The base of the path to append to the URI" },
+    "CamelHttpQuery": { "kind": "header", "displayName": "", "group": 
"producer", "label": "", "required": false, "javaType": "java.lang.String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "*Camel 2.11 onwards:* URI parameters. Will override 
existing URI parameters set directly on the endpoint." }
+  },
   "properties": {
     "httpUri": { "kind": "path", "displayName": "Http Uri", "group": 
"producer", "label": "", "required": true, "type": "string", "javaType": 
"java.net.URI", "deprecated": false, "deprecationNote": "", "autowired": false, 
"secret": false, "description": "The URI to use such as 
http:\/\/hostname:port\/path" },
     "bridgeEndpoint": { "kind": "parameter", "displayName": "Bridge Endpoint", 
"group": "producer", "label": "", "required": false, "type": "boolean", 
"javaType": "boolean", "deprecated": false, "autowired": false, "secret": 
false, "defaultValue": false, "description": "If the option is true, then the 
Exchange.HTTP_URI header is ignored, and use the endpoint's URI for request. 
You may also set the throwExceptionOnFailure to be false to let the AhcProducer 
send all the fault response back." },
diff --git a/components/camel-ahc/src/main/docs/ahc-component.adoc 
b/components/camel-ahc/src/main/docs/ahc-component.adoc
index 991e266..b81be90 100644
--- a/components/camel-ahc/src/main/docs/ahc-component.adoc
+++ b/components/camel-ahc/src/main/docs/ahc-component.adoc
@@ -59,32 +59,9 @@ include::partial$component-endpoint-options.adoc[]
 
 // endpoint options: END
 
-
-== Message Headers
-
-[width="100%",cols="10%,10%,80%",options="header",]
-|=======================================================================
-|Name |Type |Description
-|`Exchange.HTTP_URI` |`String` |URI to call. Will override existing URI set 
directly on the endpoint.
-
-|`Exchange.HTTP_PATH` |`String` |Request URI's path, the header will be used 
to build the request URI
-with the HTTP_URI. If the path is start with "/", http producer will try
-to find the relative path based on the Exchange.HTTP_BASE_URI header or
-the `exchange.getFromEndpoint().getEndpointUri();`
-
-|`Exchange.HTTP_QUERY` |`String` |*Camel 2.11 onwards:* URI parameters. Will 
override existing URI
-parameters set directly on the endpoint.
-
-|`Exchange.HTTP_RESPONSE_CODE` |`int` |The HTTP response code from the 
external server. Is 200 for OK.
-
-|`Exchange.HTTP_CHARACTER_ENCODING` |`String` |Character encoding.
-
-|`Exchange.CONTENT_TYPE` |`String` |The HTTP content type. Is set on both the 
IN and OUT message to provide
-a content type, such as `text/html`.
-
-|`Exchange.CONTENT_ENCODING` |`String` |The HTTP content encoding. Is set on 
both the IN and OUT message to
-provide a content encoding, such as `gzip`.
-|=======================================================================
+// component headers: START
+include::partial$component-endpoint-headers.adoc[]
+// component headers: END
 
 == Message Body
 
diff --git 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcConstants.java
 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcConstants.java
index f900a5b..8660327 100644
--- 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcConstants.java
+++ 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcConstants.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.ahc;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.Metadata;
+
 /**
  *
  */
@@ -23,6 +26,35 @@ public final class AhcConstants {
 
     public static final String CONTENT_TYPE_JAVA_SERIALIZED_OBJECT = 
"application/x-java-serialized-object";
     public static final String CONTENT_TYPE_WWW_FORM_URLENCODED = 
"application/x-www-form-urlencoded";
+    @Metadata(description = "The HTTP response code from the external server. 
Is 200 for OK.",
+              javaType = "int")
+    public static final String HTTP_RESPONSE_CODE = 
Exchange.HTTP_RESPONSE_CODE;
+    @Metadata(description = "The Http response status text", javaType = 
"java.lang.String")
+    public static final String HTTP_RESPONSE_TEXT = 
Exchange.HTTP_RESPONSE_TEXT;
+    @Metadata(description = "The content length of the response", javaType = 
"int")
+    public static final String CONTENT_LENGTH = Exchange.CONTENT_LENGTH;
+    @Metadata(description = "The http method to execute", javaType = 
"java.lang.String")
+    public static final String HTTP_METHOD = Exchange.HTTP_METHOD;
+    @Metadata(description = "The HTTP content encoding. Is set on both the IN 
and OUT message to provide a content encoding, such as `gzip`.",
+              javaType = "java.lang.String")
+    public static final String CONTENT_ENCODING = Exchange.CONTENT_ENCODING;
+    @Metadata(description = "The HTTP content type. Is set on both the IN and 
OUT message to provide a content type, such as `text/html`",
+              javaType = "java.lang.String")
+    public static final String CONTENT_TYPE = Exchange.CONTENT_TYPE;
+    @Metadata(description = "The redirect location", javaType = 
"java.lang.String")
+    public static final String LOCATION = "Location";
+    @Metadata(description = "URI to call. Will override existing URI set 
directly on the endpoint.",
+              javaType = "java.lang.String")
+    public static final String HTTP_URI = Exchange.HTTP_URI;
+    @Metadata(description = "Request URI's path, the header will be used to 
build the request URI with the HTTP_URI. " +
+                            "If the path is start with \"/\", http producer 
will try to find the relative path based on the Exchange.HTTP_BASE_URI header 
or the `exchange.getFromEndpoint().getEndpointUri()`.",
+              javaType = "java.lang.String")
+    public static final String HTTP_PATH = Exchange.HTTP_PATH;
+    @Metadata(description = "The base of the path to append to the URI", 
javaType = "java.lang.String")
+    public static final String HTTP_BASE_URI = Exchange.HTTP_BASE_URI;
+    @Metadata(description = "*Camel 2.11 onwards:* URI parameters. Will 
override existing URI parameters set directly on the endpoint.",
+              javaType = "java.lang.String")
+    public static final String HTTP_QUERY = Exchange.HTTP_QUERY;
 
     private AhcConstants() {
     }
diff --git 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcEndpoint.java
 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcEndpoint.java
index 61b70ec..bf1a4f8 100644
--- 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcEndpoint.java
+++ 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcEndpoint.java
@@ -47,7 +47,7 @@ import org.asynchttpclient.DefaultAsyncHttpClientConfig;
  * Call external HTTP services using <a 
href="http://github.com/sonatype/async-http-client";>Async Http Client</a>.
  */
 @UriEndpoint(firstVersion = "2.8.0", scheme = "ahc", title = "Async HTTP 
Client (AHC)", syntax = "ahc:httpUri",
-             producerOnly = true, category = { Category.HTTP }, 
lenientProperties = true)
+             producerOnly = true, category = { Category.HTTP }, 
lenientProperties = true, headersClass = AhcConstants.class)
 public class AhcEndpoint extends DefaultEndpoint implements AsyncEndpoint, 
HeaderFilterStrategyAware {
 
     private AsyncHttpClient client;
diff --git 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
index 3c9f906..0af6c5c 100644
--- 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
+++ 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
@@ -92,7 +92,7 @@ public class DefaultAhcBinding implements AhcBinding {
 
     protected String extractMethod(Exchange exchange) {
         // prefer method from header
-        String method = exchange.getIn().getHeader(Exchange.HTTP_METHOD, 
String.class);
+        String method = exchange.getIn().getHeader(AhcConstants.HTTP_METHOD, 
String.class);
         if (method != null) {
             return method;
         }
@@ -254,8 +254,8 @@ public class DefaultAhcBinding implements AhcBinding {
         // to avoid overriding existing headers with old values
         // Just filter the http protocol headers 
         MessageHelper.copyHeaders(exchange.getIn(), exchange.getMessage(), 
httpProtocolHeaderFilterStrategy, false);
-        exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE, 
responseStatus.getStatusCode());
-        exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_TEXT, 
responseStatus.getStatusText());
+        exchange.getMessage().setHeader(AhcConstants.HTTP_RESPONSE_CODE, 
responseStatus.getStatusCode());
+        exchange.getMessage().setHeader(AhcConstants.HTTP_RESPONSE_TEXT, 
responseStatus.getStatusText());
     }
 
     @Override
@@ -293,13 +293,13 @@ public class DefaultAhcBinding implements AhcBinding {
         os.close();
         InputStream is = new ByteArrayInputStream(os.toByteArray());
 
-        String contentEncoding = 
exchange.getMessage().getHeader(Exchange.CONTENT_ENCODING, String.class);
+        String contentEncoding = 
exchange.getMessage().getHeader(AhcConstants.CONTENT_ENCODING, String.class);
         if (!exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, 
Boolean.class)) {
             is = GZIPHelper.uncompressGzip(contentEncoding, is);
         }
 
         // Honor the character encoding
-        String contentType = 
exchange.getMessage().getHeader(Exchange.CONTENT_TYPE, String.class);
+        String contentType = 
exchange.getMessage().getHeader(AhcConstants.CONTENT_TYPE, String.class);
         if (contentType != null) {
             // find the charset and set it to the Exchange
             AhcHelper.setCharsetFromContentType(contentType, exchange);
@@ -340,7 +340,7 @@ public class DefaultAhcBinding implements AhcBinding {
             Object body, int statusCode, String statusText) {
         Exception answer;
 
-        if (endpoint.isTransferException() && body != null && body instanceof 
Exception) {
+        if (endpoint.isTransferException() && body instanceof Exception) {
             // if the response was a serialized exception then use that
             return (Exception) body;
         }
@@ -354,7 +354,7 @@ public class DefaultAhcBinding implements AhcBinding {
         Map<String, String> headers = extractResponseHeaders(exchange);
 
         if (statusCode >= 300 && statusCode < 400) {
-            String redirectLocation = 
exchange.getMessage().getHeader("Location", String.class);
+            String redirectLocation = 
exchange.getMessage().getHeader(AhcConstants.LOCATION, String.class);
             if (redirectLocation != null) {
                 answer = new AhcOperationFailedException(url, statusCode, 
statusText, redirectLocation, headers, copy);
             } else {
@@ -383,6 +383,6 @@ public class DefaultAhcBinding implements AhcBinding {
 
     private void populateResponse(Exchange exchange, Object body, int 
contentLength) {
         exchange.getMessage().setBody(body);
-        exchange.getMessage().setHeader(Exchange.CONTENT_LENGTH, 
contentLength);
+        exchange.getMessage().setHeader(AhcConstants.CONTENT_LENGTH, 
contentLength);
     }
 }
diff --git 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/helper/AhcHelper.java
 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/helper/AhcHelper.java
index 30a3eb9..d1d4e40 100644
--- 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/helper/AhcHelper.java
+++ 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/helper/AhcHelper.java
@@ -28,6 +28,7 @@ import java.net.URISyntaxException;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePropertyKey;
 import org.apache.camel.RuntimeExchangeException;
+import org.apache.camel.component.ahc.AhcConstants;
 import org.apache.camel.component.ahc.AhcEndpoint;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.URISupport;
@@ -104,7 +105,7 @@ public final class AhcHelper {
     private static String doCreateURL(Exchange exchange, AhcEndpoint endpoint) 
{
         String uri = null;
         if (!(endpoint.isBridgeEndpoint())) {
-            uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
+            uri = exchange.getIn().getHeader(AhcConstants.HTTP_URI, 
String.class);
         }
         if (uri == null) {
             uri = endpoint.getHttpUri().toASCIIString();
@@ -114,7 +115,7 @@ public final class AhcHelper {
         uri = resolvePlaceholdersInURI(exchange, uri);
 
         // append HTTP_PATH to HTTP_URI if it is provided in the header
-        String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, 
String.class);
+        String path = exchange.getIn().getHeader(AhcConstants.HTTP_PATH, 
String.class);
         if (path != null) {
             if (path.startsWith("/")) {
                 URI baseURI;
@@ -156,7 +157,7 @@ public final class AhcHelper {
 
     private static URI getBaseURI(Exchange exchange) throws URISyntaxException 
{
         URI baseURI;
-        String baseURIString = 
exchange.getIn().getHeader(Exchange.HTTP_BASE_URI, String.class);
+        String baseURIString = 
exchange.getIn().getHeader(AhcConstants.HTTP_BASE_URI, String.class);
         if (baseURIString == null) {
             if (exchange.getFromEndpoint() != null) {
                 baseURIString = exchange.getFromEndpoint().getEndpointUri();
@@ -189,7 +190,7 @@ public final class AhcHelper {
     public static URI createURI(Exchange exchange, String url, AhcEndpoint 
endpoint) throws URISyntaxException {
         URI uri = new URI(url);
         // is a query string provided in the endpoint URI or in a header 
(header overrules endpoint)
-        String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, 
String.class);
+        String queryString = 
exchange.getIn().getHeader(AhcConstants.HTTP_QUERY, String.class);
         if (queryString == null) {
             queryString = endpoint.getHttpUri().getRawQuery();
         }

Reply via email to