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 1505c4dbebc21b5db466ec03cbbad2d5fed5d99a Author: Nicolas Filotto <[email protected]> AuthorDate: Wed Apr 6 15:30:56 2022 +0200 CAMEL-17792: Add doc about the message headers of camel-websocket --- .../camel/component/websocket/websocket.json | 7 +++++ .../src/main/docs/websocket-component.adoc | 36 ++-------------------- .../component/websocket/WebsocketConstants.java | 28 +++++++++++++++++ .../component/websocket/WebsocketEndpoint.java | 3 +- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/components/camel-websocket/src/generated/resources/org/apache/camel/component/websocket/websocket.json b/components/camel-websocket/src/generated/resources/org/apache/camel/component/websocket/websocket.json index 7e90559255d..397732ea3cd 100644 --- a/components/camel-websocket/src/generated/resources/org/apache/camel/component/websocket/websocket.json +++ b/components/camel-websocket/src/generated/resources/org/apache/camel/component/websocket/websocket.json @@ -39,6 +39,13 @@ "sslPassword": { "kind": "property", "displayName": "Ssl Password", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "description": "The password when using SSL." }, "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": "Producer: Sends the message to all clients which are currently connected. You can use the sendToAll option on the endpoint instead of using this header. Consumer: Connection key identifying an individual client connection. You can save this and specify [...] + "websocket.sendToAll": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "Boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Sends the message to all clients which are currently connected. You can use the sendToAll option on the endpoint instead of using this header." }, + "websocket.remoteAddress": { "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "java.net.InetSocketAddress", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Remote address of the websocket session." }, + "websocket.subprotocol": { "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "If a specific subprotocol was negotiated, it will be specfied in this header. Note that if you specify the any subprotocol to be supported, and a client requests a specific subprotocol, the connection will be accepted without a specific subprot [...] + "websocket.relativePath": { "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "If you specify a wildcard URI path for an endpoint, and a websocket client connects to that websocket endpoing, the relative path that the client specified will be provided in this header. For example, if you specified websocket:\/\/0.0.0.0:80 [...] + }, "properties": { "host": { "kind": "path", "displayName": "Host", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "0.0.0.0", "description": "The hostname. The default value is 0.0.0.0. Setting this option on the component will use the component configured value as default." }, "port": { "kind": "path", "displayName": "Port", "group": "common", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "9292", "description": "The port number. The default value is 9292. Setting this option on the component will use the component configured value as default." }, diff --git a/components/camel-websocket/src/main/docs/websocket-component.adoc b/components/camel-websocket/src/main/docs/websocket-component.adoc index 72c1b3526a6..ed2c3c9e5df 100644 --- a/components/camel-websocket/src/main/docs/websocket-component.adoc +++ b/components/camel-websocket/src/main/docs/websocket-component.adoc @@ -53,41 +53,11 @@ include::partial$component-endpoint-options.adoc[] // endpoint options: END +// component headers: START +include::partial$component-endpoint-headers.adoc[] +// component headers: END -== Message Headers - -The WebSocket component uses headers to provide information about incoming messages from consumer endpoints, or as processing instructions for producer endpoints sending outgoing messages. - -=== Headers from Consumers -[width="100%",cols="10%,90%",options="header",] -|======================================================================= -|Header Name |Description - -|`WebsocketConstants.CONNECTION_KEY` |Connection key identifying an individual client connection. You can save this and specify it again when routing to a producer endpoing in order to direct messages to a specific connected client. - -|`WebsocketConstants.REMOTE_ADDRESS` |Remote address of the websocket session. - -|`WebsocketConstants.SUBPROTOCOL` |If a specific subprotocol was negotiated, it will be specfied in this header. Note that if you specify the "any" subprotocol to be supported, and a client requests a specific subprotocol, the connection will be accepted without a specific subprotocol being used. You need to specifically support a given protocol by name if you want it returned to the client and to show up in the message header. - -|`WebsocketConstants.RELATIVE_PATH` |If you specify a wildcard URI path for an endpoint, and a websocket client connects to that websocket endpoing, the relative path that the client specified will be provided in this header. - -For example, if you specified `websocket://0.0.0.0:80/api/*` as your endpoint URI, and a client connects to the server at `ws://host.com/api/specialized/apipath` then `specialized/apipath` is provided in the relative path header of all messages from that client. - -|======================================================================= - -=== Headers for Producers -[width="100%",cols="10%,90%",options="header",] -|======================================================================= -|Header Name |Description - -|`WebsocketConstants.SEND_TO_ALL` |Sends the message to all clients which are currently connected. You can -use the `sendToAll` option on the endpoint instead of using this header. - -|`WebsocketConstants.CONNECTION_KEY` |Sends the message to the client with the given connection key. - -|======================================================================= - == Usage In this example we let Camel exposes a websocket server which clients diff --git a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConstants.java b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConstants.java index 08473ddb232..3036b0b4725 100644 --- a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConstants.java +++ b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConstants.java @@ -16,15 +16,43 @@ */ package org.apache.camel.component.websocket; +import org.apache.camel.spi.Metadata; + public final class WebsocketConstants { public static final int DEFAULT_PORT = 9292; public static final String DEFAULT_HOST = "0.0.0.0"; + @Metadata(description = "*Producer:* Sends the message to all clients which are currently connected. You can\n" + + "use the `sendToAll` option on the endpoint instead of using this header.\n" + + "*Consumer:* Connection key identifying an individual client connection. " + + "You can save this and specify it again when routing to a producer endpoing in order to direct messages to a specific connected client.", + javaType = "String") public static final String CONNECTION_KEY = "websocket.connectionKey"; + @Metadata(label = "producer", description = "Sends the message to all clients which are currently connected. " + + "You can use the sendToAll option on the endpoint instead of using this header.", + javaType = "Boolean") public static final String SEND_TO_ALL = "websocket.sendToAll"; + @Metadata(label = "consumer", description = "Remote address of the websocket session.", + javaType = "java.net.InetSocketAddress") public static final String REMOTE_ADDRESS = "websocket.remoteAddress"; + @Metadata(label = "consumer", + description = "If a specific subprotocol was negotiated, it will be specfied in this header. " + + "Note that if you specify the \"any\" subprotocol to be supported, and a client requests a specific subprotocol, " + + + "the connection will be accepted without a specific subprotocol being used. " + + "You need to specifically support a given protocol by name if you want it returned to the client and to show up in the message header.", + javaType = "String") public static final String SUBPROTOCOL = "websocket.subprotocol"; + @Metadata(label = "consumer", + description = "If you specify a wildcard URI path for an endpoint, and a websocket client connects to that websocket endpoing, " + + + "the relative path that the client specified will be provided in this header.\n" + + "\n" + + "For example, if you specified `websocket://0.0.0.0:80/api/*` as your endpoint URI, and a client connects to the server at `ws://host.com/api/specialized/apipath` " + + + "then `specialized/apipath` is provided in the relative path header of all messages from that client.", + javaType = "String") public static final String RELATIVE_PATH = "websocket.relativePath"; public static final String WS_PROTOCOL = "ws"; diff --git a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java index 441eb7673f3..16c2e13ebd9 100644 --- a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java +++ b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java @@ -38,7 +38,8 @@ import org.eclipse.jetty.server.Handler; * Expose websocket endpoints using Jetty. */ @UriEndpoint(firstVersion = "2.10.0", scheme = "websocket", title = "Jetty Websocket", - syntax = "websocket:host:port/resourceUri", category = { Category.WEBSOCKET }) + syntax = "websocket:host:port/resourceUri", category = { Category.WEBSOCKET }, + headersClass = WebsocketConstants.class) public class WebsocketEndpoint extends DefaultEndpoint { private WebsocketComponent component;
