4.2. Implementing WebSocket on Tomcat
- Configuring write timeout
- Configuring incoming binary messages
- Configuring incoming text messages
- Configuring additional programmatic deployment
- Configuring callbacks for asynchronous writes
- Configuring timeout for IO operations while establishing the connections
You can change the write timeout in blocking mode by using the org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT
property. The property accepts values in milliseconds. The default value is 20000 milliseconds (20 seconds).
To configure incoming binary messages, MessageHandler.Partial
must be defined. If MessageHandler.Partial
is not defined then incoming binary messages must be buffered so that the entire message is delivered in a single call to MessageHandler.Whole
.
org.apache.tomcat.websocket.binaryBufferSize
.
To configure incoming text messages, MessageHandler.Partial
must be defined. If MessageHandler.Partial
is not defined then incoming text messages must be buffered so that the entire message is delivered in a single call to MessageHandler.Whole
.
org.apache.tomcat.websocket.textBufferSize
.
Java WebSocket specification 1.0 does not allow programmatic deployment after the first endpoint has started a WebSocket handshake. However, Tomcat by default allows additional programmatic deployment. Additional programmatic deployment can be done by using the servlet context initialization parameter org.apache.tomcat.websocket.noAddAfterHandshake
.
org.apache.tomcat.websocket.STRICT_SPEC_COMPLIANCE
to true to change the default setting.
Callbacks for asynchronous writes need to be performed on a different thread to the thread that initiated the write. The container thread pool is not exposed via the Servlet API. Hence the WebSocket implementation has to provide its own thread pool.
org.apache.tomcat.websocket.executorCoreSize
The core size of the executor thread pool. If not set, the default of 0 (zero) is used.org.apache.tomcat.websocket.executorMaxSize
The maximum permitted size of the executor thread pool. If not set, the default of 10 is used.org.apache.tomcat.websocket.executorKeepAliveTimeSeconds
The maximum time an idle thread will remain in the executor thread pool until it is terminated. If not specified, the default of 60 seconds is used.
The timeout for IO operations while establishing the connections is controlled by userProperties
of the provided javax.websocket.ClientEndpointConfig
. You can change timeout by changing the org.apache.tomcat.websocket.IO_TIMEOUT_MS
property. The property accepts the values in milliseconds. The default value is 5000 (5 seconds).
userProperties
of the provided javax.websocket.ClientEndpointConfig
.
org.apache.tomcat.websocket.SSL_CONTEXT
org.apache.tomcat.websocket.SSL_PROTOCOLS
org.apache.tomcat.websocket.SSL_TRUSTSTORE
org.apache.tomcat.websocket.SSL_TRUSTSTORE_PWD
org.apache.tomcat.websocket.SSL_TRUSTSTORE
and org.apache.tomcat.websocket.SSL_TRUSTSTORE_PWD
properties are ignored if the org.apache.tomcat.websocket.SSL_CONTEXT
property is set.