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 f1be6bfb4436b4e772c160400093efba49d344bd Author: Nicolas Filotto <[email protected]> AuthorDate: Wed Apr 6 10:39:47 2022 +0200 CAMEL-17792: Add doc about the message headers of camel-undertow --- .../apache/camel/component/undertow/undertow.json | 17 +++++++++ .../src/main/docs/undertow-component.adoc | 4 ++- .../undertow/DefaultUndertowHttpBinding.java | 18 +++++----- .../component/undertow/UndertowConstants.java | 41 ++++++++++++++++++++++ .../camel/component/undertow/UndertowConsumer.java | 4 +-- .../camel/component/undertow/UndertowEndpoint.java | 2 +- .../camel/component/undertow/UndertowHelper.java | 10 +++--- .../camel/component/undertow/UndertowProducer.java | 2 +- 8 files changed, 79 insertions(+), 19 deletions(-) diff --git a/components/camel-undertow/src/generated/resources/org/apache/camel/component/undertow/undertow.json b/components/camel-undertow/src/generated/resources/org/apache/camel/component/undertow/undertow.json index 845f6159601..c0e9d0c608b 100644 --- a/components/camel-undertow/src/generated/resources/org/apache/camel/component/undertow/undertow.json +++ b/components/camel-undertow/src/generated/resources/org/apache/camel/component/undertow/undertow.json @@ -35,6 +35,23 @@ "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": "To configure security using SSLContextParameters" }, "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": { + "websocket.connectionKey": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "An identifier of WebSocketChannel through which the message was received or should be sent." }, + "websocket.connectionKey.list": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "List<String>", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The list of websocket connection keys" }, + "websocket.sendToAll": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "Boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "To send to all websocket subscribers. Can be used to configure on endpoint level, instead of having to use the UndertowConstants.SEND_TO_ALL header on the message." }, + "websocket.eventType": { "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "Integer", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The numeric identifier of the type of websocket event" }, + "websocket.eventTypeEnum": { "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "org.apache.camel.component.undertow.UndertowConstants.EventType", "enum": [ "ONOPEN", "ONCLOSE", "ONERROR" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The type of websocket event" }, + "websocket.channel": { "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "io.undertow.websockets.core.WebSocketChannel", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The WebSocketChannel through which the message was received" }, + "websocket.exchange": { "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "io.undertow.websockets.spi.WebSocketHttpExchange", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The exchange for the websocket transport, only available for ON_OPEN events" }, + "CamelHttpResponseCode": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "Integer", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The http response code" }, + "Content-Type": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The content type" }, + "CamelHttpCharacterEncoding": { "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The http character encoding" }, + "CamelHttpPath": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The http path" }, + "CamelHttpQuery": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The http query" }, + "CamelHttpUri": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The http URI" }, + "CamelHttpMethod": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The http method" }, + "Host": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The host http header" } + }, "properties": { "httpURI": { "kind": "path", "displayName": "Http URI", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.net.URI", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The url of the HTTP endpoint to use." }, "useStreaming": { "kind": "parameter", "displayName": "Use Streaming", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "For HTTP endpoint: if true, text and binary messages will be wrapped as java.io.InputStream before they are passed to an Exchange; otherwise they will be passed as byte. For WebSocket endpoint: if true, text and binary me [...] diff --git a/components/camel-undertow/src/main/docs/undertow-component.adoc b/components/camel-undertow/src/main/docs/undertow-component.adoc index 52347352063..db78238dbd3 100644 --- a/components/camel-undertow/src/main/docs/undertow-component.adoc +++ b/components/camel-undertow/src/main/docs/undertow-component.adoc @@ -60,7 +60,9 @@ include::partial$component-endpoint-options.adoc[] // endpoint options: START // endpoint options: END - +// component headers: START +include::partial$component-endpoint-headers.adoc[] +// component headers: END == Message Headers diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java index 3cfe0acc044..193ad6849c7 100644 --- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java @@ -208,7 +208,7 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding { path = path.substring(endpointPath.length()); } } - headersMap.put(Exchange.HTTP_PATH, path); + headersMap.put(UndertowConstants.HTTP_PATH, path); if (LOG.isTraceEnabled()) { LOG.trace("HTTP-Method {}", httpExchange.getRequestMethod()); @@ -280,12 +280,12 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding { } // NOTE: these headers is applied using the same logic as camel-http/camel-jetty to be consistent - headersMap.put(Exchange.HTTP_METHOD, httpExchange.getRequestMethod().toString()); + headersMap.put(UndertowConstants.HTTP_METHOD, httpExchange.getRequestMethod().toString()); // strip query parameters from the uri headersMap.put(Exchange.HTTP_URL, httpExchange.getRequestURL()); // uri is without the host and port - headersMap.put(Exchange.HTTP_URI, httpExchange.getRequestURI()); - headersMap.put(Exchange.HTTP_QUERY, httpExchange.getQueryString()); + headersMap.put(UndertowConstants.HTTP_URI, httpExchange.getRequestURI()); + headersMap.put(UndertowConstants.HTTP_QUERY, httpExchange.getQueryString()); headersMap.put(Exchange.HTTP_RAW_QUERY, httpExchange.getQueryString()); } @@ -293,7 +293,7 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding { public void populateCamelHeaders(ClientResponse response, Map<String, Object> headersMap, Exchange exchange) { LOG.trace("populateCamelHeaders: {}", exchange.getMessage().getHeaders()); - headersMap.put(Exchange.HTTP_RESPONSE_CODE, response.getResponseCode()); + headersMap.put(UndertowConstants.HTTP_RESPONSE_CODE, response.getResponseCode()); for (HttpString name : response.getResponseHeaders().getHeaderNames()) { // mapping the content-type @@ -331,7 +331,7 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding { Exception exception = camelExchange.getException(); int code = determineResponseCode(camelExchange, body); - message.getHeaders().put(Exchange.HTTP_RESPONSE_CODE, code); + message.getHeaders().put(UndertowConstants.HTTP_RESPONSE_CODE, code); httpExchange.setStatusCode(code); //copy headers from Message to Response @@ -363,7 +363,7 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding { // the body should be the serialized java object of the exception body = ByteBuffer.wrap(bos.toByteArray()); // force content type to be serialized java object - message.setHeader(Exchange.CONTENT_TYPE, "application/x-java-serialized-object"); + message.setHeader(UndertowConstants.CONTENT_TYPE, "application/x-java-serialized-object"); } else { // we failed due an exception so print it as plain text StringWriter sw = new StringWriter(); @@ -373,7 +373,7 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding { // the body should then be the stacktrace body = ByteBuffer.wrap(sw.toString().getBytes()); // force content type to be text/plain as that is what the stacktrace is - message.setHeader(Exchange.CONTENT_TYPE, "text/plain"); + message.setHeader(UndertowConstants.CONTENT_TYPE, "text/plain"); } // and mark the exception as failure handled, as we handled it by returning it as the response @@ -401,7 +401,7 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding { int defaultCode = failed ? 500 : 200; Message message = camelExchange.getMessage(); - Integer currentCode = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class); + Integer currentCode = message.getHeader(UndertowConstants.HTTP_RESPONSE_CODE, Integer.class); int codeToUse = currentCode == null ? defaultCode : currentCode; if (codeToUse != 500) { diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConstants.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConstants.java index 300066050aa..fc9f76c956b 100644 --- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConstants.java +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConstants.java @@ -16,16 +16,57 @@ */ package org.apache.camel.component.undertow; +import io.undertow.util.Headers; +import io.undertow.websockets.core.WebSocketChannel; +import org.apache.camel.Exchange; +import org.apache.camel.spi.Metadata; + public final class UndertowConstants { + /** + * An identifier of {@link WebSocketChannel} through which the {@code message} was received or should be sent. + */ + @Metadata(javaType = "String") public static final String CONNECTION_KEY = "websocket.connectionKey"; + @Metadata(label = "producer", description = "The list of websocket connection keys", javaType = "List<String>") public static final String CONNECTION_KEY_LIST = "websocket.connectionKey.list"; + /** + * To send to all websocket subscribers. Can be used to configure on endpoint level, instead of having to use the + * {@code UndertowConstants.SEND_TO_ALL} header on the message. + */ + @Metadata(javaType = "Boolean") public static final String SEND_TO_ALL = "websocket.sendToAll"; + @Metadata(label = "consumer", description = "The numeric identifier of the type of websocket event", javaType = "Integer") public static final String EVENT_TYPE = "websocket.eventType"; + @Metadata(label = "consumer", description = "The type of websocket event", + javaType = "org.apache.camel.component.undertow.UndertowConstants.EventType") public static final String EVENT_TYPE_ENUM = "websocket.eventTypeEnum"; + /** + * The {@link WebSocketChannel} through which the {@code message} was received + */ + @Metadata(label = "consumer", javaType = "io.undertow.websockets.core.WebSocketChannel") public static final String CHANNEL = "websocket.channel"; + @Metadata(label = "consumer", description = "The exchange for the websocket transport, only available for ON_OPEN events", + javaType = "io.undertow.websockets.spi.WebSocketHttpExchange") public static final String EXCHANGE = "websocket.exchange"; + @Metadata(description = "The http response code", javaType = "Integer") + public static final String HTTP_RESPONSE_CODE = Exchange.HTTP_RESPONSE_CODE; + @Metadata(description = "The content type", javaType = "String") + public static final String CONTENT_TYPE = Exchange.CONTENT_TYPE; + @Metadata(label = "consumer", description = "The http character encoding", javaType = "String") + public static final String HTTP_CHARACTER_ENCODING = Exchange.HTTP_CHARACTER_ENCODING; + @Metadata(description = "The http path", javaType = "String") + public static final String HTTP_PATH = Exchange.HTTP_PATH; + @Metadata(description = "The http query", javaType = "String") + public static final String HTTP_QUERY = Exchange.HTTP_QUERY; + @Metadata(description = "The http URI", javaType = "String") + public static final String HTTP_URI = Exchange.HTTP_URI; + @Metadata(label = "producer", description = "The http method", javaType = "String") + public static final String HTTP_METHOD = Exchange.HTTP_METHOD; + @Metadata(label = "producer", description = "The host http header", javaType = "String") + public static final String HOST_STRING = Headers.HOST_STRING; + /** * WebSocket peers related events the {@link UndertowConsumer} sends to the Camel route. */ diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java index 87a82432aa4..d3041cb5783 100644 --- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java @@ -251,7 +251,7 @@ public class UndertowConsumer extends DefaultConsumer implements HttpHandler, Su if (body == null) { LOG.trace("No payload to send as reply for exchange: {}", camelExchange); // respect Content-Type assigned from HttpBinding if any - String contentType = camelExchange.getIn().getHeader(Exchange.CONTENT_TYPE, + String contentType = camelExchange.getIn().getHeader(UndertowConstants.CONTENT_TYPE, MimeMappings.DEFAULT_MIME_MAPPINGS.get("txt"), String.class); httpExchange.getResponseHeaders().put(ExchangeHeaders.CONTENT_TYPE, contentType); httpExchange.getResponseSender().send(""); // empty body @@ -355,7 +355,7 @@ public class UndertowConsumer extends DefaultConsumer implements HttpHandler, Su } exchange.setProperty(ExchangePropertyKey.CHARSET_NAME, httpExchange.getRequestCharset()); - in.setHeader(Exchange.HTTP_CHARACTER_ENCODING, httpExchange.getRequestCharset()); + in.setHeader(UndertowConstants.HTTP_CHARACTER_ENCODING, httpExchange.getRequestCharset()); exchange.setIn(in); return exchange; diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java index acd15e357c3..bdd70e83b39 100644 --- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java @@ -59,7 +59,7 @@ import org.xnio.Options; * Expose HTTP and WebSocket endpoints and access external HTTP/WebSocket servers. */ @UriEndpoint(firstVersion = "2.16.0", scheme = "undertow", title = "Undertow", syntax = "undertow:httpURI", - category = { Category.HTTP, Category.WEBSOCKET }, lenientProperties = true) + category = { Category.HTTP, Category.WEBSOCKET }, lenientProperties = true, headersClass = UndertowConstants.class) public class UndertowEndpoint extends DefaultEndpoint implements AsyncEndpoint, HeaderFilterStrategyAware, DiscoverableService { private static final Logger LOG = LoggerFactory.getLogger(UndertowEndpoint.class); diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHelper.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHelper.java index 45fbbfc0548..c07e41d87ca 100644 --- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHelper.java +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHelper.java @@ -60,7 +60,7 @@ public final class UndertowHelper { } // 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(UndertowConstants.HTTP_PATH, String.class); // NOW the HTTP_PATH is just related path, we don't need to trim it if (path != null) { if (path.startsWith("/")) { @@ -96,7 +96,7 @@ public final class UndertowHelper { String queryString = (String) exchange.getIn().removeHeader(Exchange.REST_HTTP_QUERY); // is a query string provided in the endpoint URI or in a header (header overrules endpoint) if (queryString == null) { - queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class); + queryString = exchange.getIn().getHeader(UndertowConstants.HTTP_QUERY, String.class); } if (queryString == null) { queryString = endpoint.getHttpURI().getRawQuery(); @@ -137,9 +137,9 @@ public final class UndertowHelper { throws URISyntaxException { // 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(UndertowConstants.HTTP_QUERY, String.class); // We need also check the HTTP_URI header query part - String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class); + String uriString = exchange.getIn().getHeader(UndertowConstants.HTTP_URI, String.class); // resolve placeholders in uriString try { uriString = exchange.getContext().resolvePropertyPlaceholders(uriString); @@ -156,7 +156,7 @@ public final class UndertowHelper { // compute what method to use either GET or POST HttpString answer; - String m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, String.class); + String m = exchange.getIn().getHeader(UndertowConstants.HTTP_METHOD, String.class); if (m != null) { // always use what end-user provides in a header // must be in upper case diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowProducer.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowProducer.java index b0b4be167db..d60b0034ece 100644 --- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowProducer.java +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowProducer.java @@ -132,7 +132,7 @@ public class UndertowProducer extends DefaultAsyncProducer { // Set the Host header final Message message = camelExchange.getIn(); - final String host = message.getHeader(Headers.HOST_STRING, String.class); + final String host = message.getHeader(UndertowConstants.HOST_STRING, String.class); if (endpoint.isPreserveHostHeader()) { requestHeaders.put(Headers.HOST, Optional.ofNullable(host).orElseGet(uri::getAuthority)); } else {
