Class WebsocketComponent
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.DefaultComponent
-
- org.apache.camel.component.websocket.WebsocketComponent
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.CamelContextAware
,org.apache.camel.Component
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.SSLContextParametersAware
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
@Component("websocket") public class WebsocketComponent extends org.apache.camel.support.DefaultComponent implements org.apache.camel.SSLContextParametersAware
-
-
Field Summary
Fields Modifier and Type Field Description protected static HashMap<String,org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef>
CONNECTORS
protected boolean
enableJmx
protected String
host
protected static org.slf4j.Logger
LOG
protected Integer
maxThreads
protected org.eclipse.jetty.jmx.MBeanContainer
mbContainer
protected Integer
minThreads
protected Integer
port
protected Map<String,WebSocketFactory>
socketFactory
protected org.apache.camel.support.jsse.SSLContextParameters
sslContextParameters
protected String
sslKeyPassword
protected String
sslKeystore
protected String
sslPassword
protected String
staticResources
protected org.eclipse.jetty.server.Server
staticResourcesServer
protected String
subprotocol
protected org.eclipse.jetty.util.thread.ThreadPool
threadPool
protected boolean
useGlobalSslContextParameters
-
Constructor Summary
Constructors Constructor Description WebsocketComponent()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected WebsocketComponentServlet
addServlet(NodeSynchronization sync, WebsocketProducerConsumer prodcon, String resourceUri)
void
connect(WebsocketProducerConsumer prodcon)
Connects the URL specified on the endpoint to the specified processor.protected org.eclipse.jetty.servlet.ServletContextHandler
createContext(org.eclipse.jetty.server.Server server, org.eclipse.jetty.server.Connector connector, List<org.eclipse.jetty.server.Handler> handlers)
protected org.apache.camel.Endpoint
createEndpoint(String uri, String remaining, Map<String,Object> parameters)
static String
createPathSpec(String remaining)
protected org.eclipse.jetty.server.Server
createServer()
protected WebsocketComponentServlet
createServlet(NodeSynchronization sync, String pathSpec, Map<String,WebsocketComponentServlet> servlets, org.eclipse.jetty.servlet.ServletContextHandler handler)
protected org.eclipse.jetty.server.Server
createStaticResourcesServer(org.eclipse.jetty.server.Server server, org.eclipse.jetty.servlet.ServletContextHandler context, String home)
protected org.eclipse.jetty.server.Server
createStaticResourcesServer(org.eclipse.jetty.servlet.ServletContextHandler context, String host, int port, String home)
void
disconnect(WebsocketProducerConsumer prodcon)
Disconnects the URL specified on the endpoint from the specified processor.protected void
doStart()
void
doStop()
static HashMap<String,org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef>
getConnectors()
String
getHost()
Integer
getMaxThreads()
org.eclipse.jetty.jmx.MBeanContainer
getMbContainer()
Integer
getMinThreads()
Integer
getPort()
Map<String,WebSocketFactory>
getSocketFactory()
org.apache.camel.support.jsse.SSLContextParameters
getSslContextParameters()
String
getSslKeyPassword()
String
getSslKeystore()
String
getSslPassword()
String
getStaticResources()
String
getSubprotocol()
SeegetSubprotocol()
org.eclipse.jetty.util.thread.ThreadPool
getThreadPool()
boolean
isEnableJmx()
boolean
isUseGlobalSslContextParameters()
protected WebsocketEndpoint
newEndpoint(String uri, String remaining)
void
setEnableJmx(boolean enableJmx)
If this option is true, Jetty JMX support will be enabled for this endpoint.void
setHost(String host)
The hostname.void
setMaxThreads(Integer maxThreads)
To set a value for maximum number of threads in server thread pool.void
setMinThreads(Integer minThreads)
To set a value for minimum number of threads in server thread pool.void
setPort(Integer port)
The port number.void
setSocketFactory(Map<String,WebSocketFactory> socketFactory)
To configure a map which contains custom WebSocketFactory for sub protocols.void
setSslContextParameters(org.apache.camel.support.jsse.SSLContextParameters sslContextParameters)
To configure security using SSLContextParametersvoid
setSslKeyPassword(String sslKeyPassword)
The password for the keystore when using SSL.void
setSslKeystore(String sslKeystore)
The path to the keystore.void
setSslPassword(String sslPassword)
The password when using SSL.void
setStaticResources(String staticResources)
Set a resource path for static resources (such as .html files etc).void
setSubprotocol(String subprotocol)
This is a comma-separated list of subprotocols that are supported by the application.void
setThreadPool(org.eclipse.jetty.util.thread.ThreadPool threadPool)
To use a custom thread pool for the server.void
setUseGlobalSslContextParameters(boolean useGlobalSslContextParameters)
Enable usage of global SSL context parameters.protected void
setWebSocketComponentServletInitialParameter(org.eclipse.jetty.servlet.ServletContextHandler context, WebsocketEndpoint endpoint)
-
Methods inherited from class org.apache.camel.support.DefaultComponent
afterConfiguration, createEndpoint, createEndpoint, doBuild, doInit, getAndRemoveOrResolveReferenceParameter, getAndRemoveOrResolveReferenceParameter, getAndRemoveParameter, getAndRemoveParameter, getCamelContext, getComponentPropertyConfigurer, getDefaultName, getEndpointPropertyConfigurer, getExtension, getSupportedExtensions, ifStartsWithReturnRemainder, isAutowiredEnabled, isBridgeErrorHandler, isLazyStartProducer, registerExtension, registerExtension, resolveAndRemoveReferenceListParameter, resolveAndRemoveReferenceListParameter, resolveAndRemoveReferenceParameter, resolveAndRemoveReferenceParameter, resolveRawParameterValues, setAutowiredEnabled, setBridgeErrorHandler, setCamelContext, setLazyStartProducer, setProperties, setProperties, setProperties, useIntrospectionOnEndpoint, useRawUri, validateParameters, validateURI
-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.camel.CamelContextAware
getCamelContext, setCamelContext
-
Methods inherited from interface org.apache.camel.SSLContextParametersAware
retrieveGlobalSslContextParameters
-
-
-
-
Field Detail
-
LOG
protected static final org.slf4j.Logger LOG
-
CONNECTORS
protected static final HashMap<String,org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef> CONNECTORS
-
socketFactory
protected Map<String,WebSocketFactory> socketFactory
-
staticResourcesServer
protected org.eclipse.jetty.server.Server staticResourcesServer
-
mbContainer
protected org.eclipse.jetty.jmx.MBeanContainer mbContainer
-
sslContextParameters
@Metadata(label="security") protected org.apache.camel.support.jsse.SSLContextParameters sslContextParameters
-
useGlobalSslContextParameters
@Metadata(label="security", defaultValue="false") protected boolean useGlobalSslContextParameters
-
threadPool
@Metadata(label="advanced") protected org.eclipse.jetty.util.thread.ThreadPool threadPool
-
port
@Metadata(defaultValue="9292") protected Integer port
-
minThreads
@Metadata(label="advanced") protected Integer minThreads
-
maxThreads
@Metadata(label="advanced") protected Integer maxThreads
-
enableJmx
@Metadata(label="advanced") protected boolean enableJmx
-
host
@Metadata(defaultValue="0.0.0.0") protected String host
-
staticResources
@Metadata(label="consumer") protected String staticResources
-
sslKeyPassword
@Metadata(label="security", secret=true) protected String sslKeyPassword
-
sslPassword
@Metadata(label="security", secret=true) protected String sslPassword
-
sslKeystore
@Metadata(label="security", secret=true) protected String sslKeystore
-
subprotocol
@Metadata(label="advanced", defaultValue="any") protected String subprotocol
-
-
Method Detail
-
connect
public void connect(WebsocketProducerConsumer prodcon) throws Exception
Connects the URL specified on the endpoint to the specified processor.- Throws:
Exception
-
disconnect
public void disconnect(WebsocketProducerConsumer prodcon) throws Exception
Disconnects the URL specified on the endpoint from the specified processor.- Throws:
Exception
-
getMbContainer
public org.eclipse.jetty.jmx.MBeanContainer getMbContainer()
-
createEndpoint
protected org.apache.camel.Endpoint createEndpoint(String uri, String remaining, Map<String,Object> parameters) throws Exception
- Specified by:
createEndpoint
in classorg.apache.camel.support.DefaultComponent
- Throws:
Exception
-
newEndpoint
protected WebsocketEndpoint newEndpoint(String uri, String remaining)
-
setWebSocketComponentServletInitialParameter
protected void setWebSocketComponentServletInitialParameter(org.eclipse.jetty.servlet.ServletContextHandler context, WebsocketEndpoint endpoint)
-
createServer
protected org.eclipse.jetty.server.Server createServer() throws Exception
- Throws:
Exception
-
createStaticResourcesServer
protected org.eclipse.jetty.server.Server createStaticResourcesServer(org.eclipse.jetty.server.Server server, org.eclipse.jetty.servlet.ServletContextHandler context, String home) throws Exception
- Throws:
Exception
-
createStaticResourcesServer
protected org.eclipse.jetty.server.Server createStaticResourcesServer(org.eclipse.jetty.servlet.ServletContextHandler context, String host, int port, String home) throws Exception
- Throws:
Exception
-
addServlet
protected WebsocketComponentServlet addServlet(NodeSynchronization sync, WebsocketProducerConsumer prodcon, String resourceUri) throws Exception
- Throws:
Exception
-
createServlet
protected WebsocketComponentServlet createServlet(NodeSynchronization sync, String pathSpec, Map<String,WebsocketComponentServlet> servlets, org.eclipse.jetty.servlet.ServletContextHandler handler)
-
createContext
protected org.eclipse.jetty.servlet.ServletContextHandler createContext(org.eclipse.jetty.server.Server server, org.eclipse.jetty.server.Connector connector, List<org.eclipse.jetty.server.Handler> handlers)
-
getStaticResources
public String getStaticResources()
-
setStaticResources
public void setStaticResources(String staticResources)
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.
-
getHost
public String getHost()
-
setHost
public void setHost(String host)
The hostname. The default value is 0.0.0.0
-
getPort
public Integer getPort()
-
setPort
public void setPort(Integer port)
The port number. The default value is 9292
-
getSslKeyPassword
public String getSslKeyPassword()
-
getSslPassword
public String getSslPassword()
-
getSslKeystore
public String getSslKeystore()
-
setSslKeyPassword
public void setSslKeyPassword(String sslKeyPassword)
The password for the keystore when using SSL.
-
setSslPassword
public void setSslPassword(String sslPassword)
The password when using SSL.
-
setSslKeystore
public void setSslKeystore(String sslKeystore)
The path to the keystore.
-
setEnableJmx
public void setEnableJmx(boolean enableJmx)
If this option is true, Jetty JMX support will be enabled for this endpoint. See Jetty JMX support for more details.
-
isEnableJmx
public boolean isEnableJmx()
-
getMinThreads
public Integer getMinThreads()
-
setMinThreads
public void setMinThreads(Integer minThreads)
To set a value for minimum number of threads in server thread pool. MaxThreads/minThreads or threadPool fields are required due to switch to Jetty9. The default values for minThreads is 1.
-
getMaxThreads
public Integer getMaxThreads()
-
setMaxThreads
public void setMaxThreads(Integer maxThreads)
To set a value for maximum number of threads in server thread pool. MaxThreads/minThreads or threadPool fields are required due to switch to Jetty9. The default values for maxThreads is 1 + 2 * noCores.
-
getThreadPool
public org.eclipse.jetty.util.thread.ThreadPool getThreadPool()
-
setThreadPool
public void setThreadPool(org.eclipse.jetty.util.thread.ThreadPool threadPool)
To use a custom thread pool for the server. MaxThreads/minThreads or threadPool fields are required due to switch to Jetty9.
-
getSslContextParameters
public org.apache.camel.support.jsse.SSLContextParameters getSslContextParameters()
-
setSslContextParameters
public void setSslContextParameters(org.apache.camel.support.jsse.SSLContextParameters sslContextParameters)
To configure security using SSLContextParameters
-
isUseGlobalSslContextParameters
public boolean isUseGlobalSslContextParameters()
- Specified by:
isUseGlobalSslContextParameters
in interfaceorg.apache.camel.SSLContextParametersAware
-
setUseGlobalSslContextParameters
public void setUseGlobalSslContextParameters(boolean useGlobalSslContextParameters)
Enable usage of global SSL context parameters.- Specified by:
setUseGlobalSslContextParameters
in interfaceorg.apache.camel.SSLContextParametersAware
-
getSubprotocol
public String getSubprotocol()
SeegetSubprotocol()
-
setSubprotocol
public void setSubprotocol(String subprotocol)
This is a comma-separated list of subprotocols that are supported by the application. The list is in priority order. The first subprotocol on this list that is proposed by the client is the one that will be accepted. If no subprotocol on this list is proposed by the client, then the websocket connection is refused. The special value 'any' means that any subprotocol is acceptable. 'any' can be used on its own, or as a failsafe at the end of a list of more specific protocols. 'any' will also match the case where no subprotocol is proposed by the client.
-
getSocketFactory
public Map<String,WebSocketFactory> getSocketFactory()
-
setSocketFactory
public void setSocketFactory(Map<String,WebSocketFactory> socketFactory)
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.
-
getConnectors
public static HashMap<String,org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef> getConnectors()
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.DefaultComponent
- Throws:
Exception
-
-