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>CONNECTORSprotected booleanenableJmxprotected Stringhostprotected static org.slf4j.LoggerLOGprotected IntegermaxThreadsprotected org.eclipse.jetty.jmx.MBeanContainermbContainerprotected IntegerminThreadsprotected Integerportprotected Map<String,WebSocketFactory>socketFactoryprotected org.apache.camel.support.jsse.SSLContextParameterssslContextParametersprotected StringsslKeyPasswordprotected StringsslKeystoreprotected StringsslPasswordprotected StringstaticResourcesprotected org.eclipse.jetty.server.ServerstaticResourcesServerprotected Stringsubprotocolprotected org.eclipse.jetty.util.thread.ThreadPoolthreadPoolprotected booleanuseGlobalSslContextParameters
-
Constructor Summary
Constructors Constructor Description WebsocketComponent()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected WebsocketComponentServletaddServlet(NodeSynchronization sync, WebsocketProducerConsumer prodcon, String resourceUri)voidconnect(WebsocketProducerConsumer prodcon)Connects the URL specified on the endpoint to the specified processor.protected org.eclipse.jetty.servlet.ServletContextHandlercreateContext(org.eclipse.jetty.server.Server server, org.eclipse.jetty.server.Connector connector, List<org.eclipse.jetty.server.Handler> handlers)protected org.apache.camel.EndpointcreateEndpoint(String uri, String remaining, Map<String,Object> parameters)static StringcreatePathSpec(String remaining)protected org.eclipse.jetty.server.ServercreateServer()protected WebsocketComponentServletcreateServlet(NodeSynchronization sync, String pathSpec, Map<String,WebsocketComponentServlet> servlets, org.eclipse.jetty.servlet.ServletContextHandler handler)protected org.eclipse.jetty.server.ServercreateStaticResourcesServer(org.eclipse.jetty.server.Server server, org.eclipse.jetty.servlet.ServletContextHandler context, String home)protected org.eclipse.jetty.server.ServercreateStaticResourcesServer(org.eclipse.jetty.servlet.ServletContextHandler context, String host, int port, String home)voiddisconnect(WebsocketProducerConsumer prodcon)Disconnects the URL specified on the endpoint from the specified processor.protected voiddoStart()voiddoStop()static HashMap<String,org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef>getConnectors()StringgetHost()IntegergetMaxThreads()org.eclipse.jetty.jmx.MBeanContainergetMbContainer()IntegergetMinThreads()IntegergetPort()Map<String,WebSocketFactory>getSocketFactory()org.apache.camel.support.jsse.SSLContextParametersgetSslContextParameters()StringgetSslKeyPassword()StringgetSslKeystore()StringgetSslPassword()StringgetStaticResources()StringgetSubprotocol()SeegetSubprotocol()org.eclipse.jetty.util.thread.ThreadPoolgetThreadPool()booleanisEnableJmx()booleanisUseGlobalSslContextParameters()protected WebsocketEndpointnewEndpoint(String uri, String remaining)voidsetEnableJmx(boolean enableJmx)If this option is true, Jetty JMX support will be enabled for this endpoint.voidsetHost(String host)The hostname.voidsetMaxThreads(Integer maxThreads)To set a value for maximum number of threads in server thread pool.voidsetMinThreads(Integer minThreads)To set a value for minimum number of threads in server thread pool.voidsetPort(Integer port)The port number.voidsetSocketFactory(Map<String,WebSocketFactory> socketFactory)To configure a map which contains custom WebSocketFactory for sub protocols.voidsetSslContextParameters(org.apache.camel.support.jsse.SSLContextParameters sslContextParameters)To configure security using SSLContextParametersvoidsetSslKeyPassword(String sslKeyPassword)The password for the keystore when using SSL.voidsetSslKeystore(String sslKeystore)The path to the keystore.voidsetSslPassword(String sslPassword)The password when using SSL.voidsetStaticResources(String staticResources)Set a resource path for static resources (such as .html files etc).voidsetSubprotocol(String subprotocol)This is a comma-separated list of subprotocols that are supported by the application.voidsetThreadPool(org.eclipse.jetty.util.thread.ThreadPool threadPool)To use a custom thread pool for the server.voidsetUseGlobalSslContextParameters(boolean useGlobalSslContextParameters)Enable usage of global SSL context parameters.protected voidsetWebSocketComponentServletInitialParameter(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:
createEndpointin 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:
isUseGlobalSslContextParametersin interfaceorg.apache.camel.SSLContextParametersAware
-
setUseGlobalSslContextParameters
public void setUseGlobalSslContextParameters(boolean useGlobalSslContextParameters)
Enable usage of global SSL context parameters.- Specified by:
setUseGlobalSslContextParametersin 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:
doStartin classorg.apache.camel.support.DefaultComponent- Throws:
Exception
-
-