You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/04/20 14:53:53 UTC

[6/7] camel git commit: Added camel-websocket docs to gitbook

Added camel-websocket docs to gitbook


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b33b8749
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b33b8749
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b33b8749

Branch: refs/heads/master
Commit: b33b8749db192172dc8057eee5b9f43dbdb8e25c
Parents: e3eb2c3
Author: Andrea Cosentino <an...@gmail.com>
Authored: Wed Apr 20 14:08:52 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Wed Apr 20 14:09:09 2016 +0200

----------------------------------------------------------------------
 .../src/main/docs/websocket.adoc                | 236 +++++++++++++++++++
 docs/user-manual/en/SUMMARY.md                  |   1 +
 2 files changed, 237 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b33b8749/components/camel-websocket/src/main/docs/websocket.adoc
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/main/docs/websocket.adoc b/components/camel-websocket/src/main/docs/websocket.adoc
new file mode 100644
index 0000000..ff0abcf
--- /dev/null
+++ b/components/camel-websocket/src/main/docs/websocket.adoc
@@ -0,0 +1,236 @@
+[[Websocket-WebsocketComponent]]
+Websocket Component
+~~~~~~~~~~~~~~~~~~~
+
+*Available as of Camel 2.10*
+
+The *websocket* component provides websocket
+link:endpoint.html[endpoints] for communicating with clients using
+websocket. The component uses Eclipse Jetty Server which implements the
+http://tools.ietf.org/html/rfc6455[IETF] specification (drafts and RFC
+6455). It supports the protocols ws:// and wss://. To use wss://
+protocol, the SSLContextParameters must be defined.
+
+
+*Version currently supported*
+
+Camel 2.18 uses Jetty 9
+
+[[Websocket-URIformat]]
+URI format
+^^^^^^^^^^
+
+[source,java]
+---------------------------------------------------
+websocket://hostname[:port][/resourceUri][?options]
+---------------------------------------------------
+
+You can append query options to the URI in the following format,
+`?option=value&option=value&...`
+
+[[Websocket-Options]]
+Websocket Options
+^^^^^^^^^^^^^^^^^
+
+
+// component options: START
+The Jetty Websocket component supports 12 options which are listed below.
+
+
+
+[width="100%",cols="2s,1m,8",options="header"]
+|=======================================================================
+| Name | Java Type | Description
+| staticResources | String | Set a resource path for static resources (such as .html files etc). The resources can be loaded from classpath if you prefix with classpath: otherwise the resources is loaded from file system or from JAR files. For example to load from root classpath use classpath:. or classpath:WEB-INF/static If not configured (eg null) then no static resource is in use.
+| host | String | The hostname. The default value is 0.0.0.0
+| port | Integer | The port number. The default value is 9292
+| sslKeyPassword | String | The password for the keystore when using SSL.
+| sslPassword | String | The password when using SSL.
+| sslKeystore | String | The path to the keystore.
+| enableJmx | boolean | If this option is true Jetty JMX support will be enabled for this endpoint. See Jetty JMX support for more details.
+| minThreads | Integer | To set a value for minimum number of threads in server thread pool.
+| maxThreads | Integer | To set a value for maximum number of threads in server thread pool.
+| threadPool | ThreadPool | To use a custom thread pool for the server.
+| sslContextParameters | SSLContextParameters | To configure security using SSLContextParameters
+| socketFactory | Map | To configure a map which contains custom WebSocketFactory for sub protocols. The key in the map is the sub protocol. The default key is reserved for the default implementation.
+|=======================================================================
+// component options: END
+
+
+
+
+// endpoint options: START
+The Jetty Websocket component supports 20 endpoint options which are listed below:
+
+[width="100%",cols="2s,1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Default | Java Type | Description
+| host | common | 0.0.0.0 | String | 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 | common | 9292 | Integer | The port number. The default value is 9292. Setting this option on the component will use the component configured value as default.
+| resourceUri | common |  | String | *Required* Name of the websocket channel to use
+| allowedOrigins | common |  | String | The CORS allowed origins. Use to allow all.
+| bufferSize | common | 8192 | Integer | Set the buffer size of the websocketServlet which is also the max frame byte size (default 8192)
+| crossOriginFilterOn | common | false | boolean | Whether to enable CORS
+| enableJmx | common | false | boolean | If this option is true Jetty JMX support will be enabled for this endpoint. See Jetty JMX support for more details.
+| filterPath | common |  | String | Context path for filtering CORS
+| maxBinaryMessageSize | common | -1 | Integer | Can be used to set the size in bytes that the websocket created by the websocketServlet may be accept before closing. (Default is -1 - or unlimited)
+| maxIdleTime | common | 300000 | Integer | Set the time in ms that the websocket created by the websocketServlet may be idle before closing. (default is 300000)
+| maxTextMessageSize | common |  | Integer | Can be used to set the size in characters that the websocket created by the websocketServlet may be accept before closing.
+| minVersion | common | 13 | Integer | Can be used to set the minimum protocol version accepted for the websocketServlet. (Default 13 - the RFC6455 version)
+| sessionSupport | common | false | boolean | Whether to enable session support which enables HttpSession for each http request.
+| sslContextParameters | common |  | SSLContextParameters | To configure security using SSLContextParameters
+| staticResources | common |  | String | Set a resource path for static resources (such as .html files etc). The resources can be loaded from classpath if you prefix with classpath: otherwise the resources is loaded from file system or from JAR files. For example to load from root classpath use classpath:. or classpath:WEB-INF/static If not configured (eg null) then no static resource is in use.
+| bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored.
+| exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
+| sendToAll | producer |  | Boolean | To send to all websocket subscribers. Can be used to configure on endpoint level instead of having to use the WebsocketConstants.SEND_TO_ALL header on the message.
+| exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange
+| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
+|=======================================================================
+// endpoint options: END
+
+ 
+
+[[Websocket-MessageHeaders]]
+Message Headers
+^^^^^^^^^^^^^^^
+
+The websocket component uses 2 headers to indicate to either send
+messages back to a single/current client, or to all clients.
+
+[width="100%",cols="10%,90%",options="header",]
+|=======================================================================
+
+|`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.
+|=======================================================================
+
+[[Websocket-Usage]]
+Usage
+^^^^^
+
+In this example we let Camel exposes a websocket server which clients
+can communicate with. The websocket server uses the default host and
+port, which would be `0.0.0.0:9292`. +
+ The example will send back an echo of the input. To send back a
+message, we need to send the transformed message to the same endpoint
+`"websocket://echo"`. This is needed +
+ because by default the messaging is InOnly.
+
+This example is part of an unit test, which you can find
+https://svn.apache.org/repos/asf/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java[here].
+As a client we use the link:ahc.html[AHC] library which offers support
+for web socket as well.
+
+Here is another example where webapp resources location have been
+defined to allow the Jetty Application Server to not only register the
+WebSocket servlet but also to expose web resources for the browser.
+Resources should be defined under the webapp directory.
+
+[source,java]
+-----------------------------------------------------------------------------------------------
+from("activemq:topic:newsTopic")
+   .routeId("fromJMStoWebSocket")
+   .to("websocket://localhost:8443/newsTopic?sendToAll=true&staticResources=classpath:webapp");
+-----------------------------------------------------------------------------------------------
+
+[[Websocket-SettingupSSLforWebSocketComponent]]
+Setting up SSL for WebSocket Component
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+[[Websocket-UsingtheJSSEConfigurationUtility]]
+Using the JSSE Configuration Utility
+++++++++++++++++++++++++++++++++++++
+
+As of Camel 2.10, the WebSocket component supports SSL/TLS configuration
+through the link:camel-configuration-utilities.html[Camel JSSE
+Configuration Utility].  This utility greatly decreases the amount of
+component specific code you need to write and is configurable at the
+endpoint and component levels.  The following examples demonstrate how
+to use the utility with the Cometd component.
+
+[[Websocket-Programmaticconfigurationofthecomponent]]
+Programmatic configuration of the component
+
+[source,java]
+-----------------------------------------------------------------------------------------------
+KeyStoreParameters ksp = new KeyStoreParameters();
+ksp.setResource("/users/home/server/keystore.jks");
+ksp.setPassword("keystorePassword");
+
+KeyManagersParameters kmp = new KeyManagersParameters();
+kmp.setKeyStore(ksp);
+kmp.setKeyPassword("keyPassword");
+
+TrustManagersParameters tmp = new TrustManagersParameters();
+tmp.setKeyStore(ksp);
+
+SSLContextParameters scp = new SSLContextParameters();
+scp.setKeyManagers(kmp);
+scp.setTrustManagers(tmp);
+
+CometdComponent commetdComponent = getContext().getComponent("cometds", CometdComponent.class);
+commetdComponent.setSslContextParameters(scp);
+-----------------------------------------------------------------------------------------------
+
+[[Websocket-SpringDSLbasedconfigurationofendpoint]]
+Spring DSL based configuration of endpoint
+
+[source,xml]
+-------------------------------------------------------------------------------------------
+...
+  <camel:sslContextParameters
+      id="sslContextParameters">
+    <camel:keyManagers
+        keyPassword="keyPassword">
+      <camel:keyStore
+          resource="/users/home/server/keystore.jks"
+          password="keystorePassword"/>
+    </camel:keyManagers>
+    <camel:trustManagers>
+      <camel:keyStore
+          resource="/users/home/server/keystore.jks"
+          password="keystorePassword"/>
+    </camel:trustManagers>
+  </camel:sslContextParameters>...
+...
+  <to uri="websocket://127.0.0.1:8443/test?sslContextParameters=#sslContextParameters"/>...
+-------------------------------------------------------------------------------------------
+
+[[Websocket-JavaDSLbasedconfigurationofendpoint]]
+Java DSL based configuration of endpoint
+
+[source,java]
+----------------------------------------------------------------------------------------------------------
+...
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                
+                String uri = "websocket://127.0.0.1:8443/test?sslContextParameters=#sslContextParameters";
+                
+                from(uri)
+                     .log(">>> Message received from WebSocket Client : ${body}")
+                     .to("mock:client")
+                     .loop(10)
+                         .setBody().constant(">> Welcome on board!")
+                         .to(uri);
+...
+----------------------------------------------------------------------------------------------------------
+
+[[Websocket-SeeAlso]]
+See Also
+^^^^^^^^
+
+* link:configuring-camel.html[Configuring Camel]
+* link:component.html[Component]
+* link:endpoint.html[Endpoint]
+* link:getting-started.html[Getting Started]
+
+* link:ahc.html[AHC]
+* link:jetty.html[Jetty]
+* link:twitter-websocket-example.html[Twitter Websocket Example]
+demonstrates how to poll a constant feed of twitter searches and publish
+results in real time using web socket to a web page.
+

http://git-wip-us.apache.org/repos/asf/camel/blob/b33b8749/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index 653b8cc..4c97057 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -171,6 +171,7 @@
     * [SJMS](sjms.adoc)
     * [SJMS Batch](sjms-batch.adoc)
     * [Twitter](twitter.adoc)
+    * [Websocket](websocket.adoc)
     * [XML Security](xmlsecurity.adoc)
     * [Yammer](yammer.adoc)
     * [ZooKeeper](zookeeper.adoc)