Class GuiceServerEndpointConfigurator
- java.lang.Object
-
- jakarta.websocket.server.ServerEndpointConfig.Configurator
-
- pl.morgwai.base.servlet.guice.scopes.GuiceServerEndpointConfigurator
-
- Direct Known Subclasses:
PingingEndpointConfigurator
public class GuiceServerEndpointConfigurator extends ServerEndpointConfig.Configurator
ObtainsEndpoint
instances fromGuice
(so that all dependencies are injected) and decorates them, so that lifecycle methods are executed withinWebsocketConnectionContext
andContainerCallContext
.In case of
Endpoints
annotated with @ServerEndpoint
, this class should be used asconfigurator
param of the annotation:@ServerEndpoint( value = "/websocket/mySocket", configurator = GuiceServerEndpointConfigurator.class) public class MyEndpoint {...}
NOTE: methods annotated with @
OnOpen
must have aSession
param.In case of
Endpoints
added programmatically, an instance of this configurator should be supplied as an argument toServerEndpointConfig.Builder.configurator(Configurator)
method:websocketContainer.addEndpoint(ServerEndpointConfig.Builder .create(MyEndpoint.class, "/websocket/mySocket") .configurator(new GuiceServerEndpointConfigurator()) .build());
-
-
Constructor Summary
Constructors Constructor Description GuiceServerEndpointConfigurator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected InvocationHandler
getAdditionalDecorator(Object endpoint)
Subclasses may override this method to further customizeEndpoints
.<EndpointT>
EndpointTgetEndpointInstance(Class<EndpointT> endpointClass)
Obtains an instance ofendpointClass
fromGuice
and creates a context-aware proxy for it, so thatEndpoint
lifecycle methods are executed withinContainerCallContext
andWebsocketConnectionContext
.protected HashSet<Class<? extends Annotation>>
getRequiredEndpointMethodAnnotationTypes()
Returns a set of annotations ofEndpoint
lifecycle methods that are required to be present inEndpoint
classes using this configurator.void
modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response)
-
Methods inherited from class jakarta.websocket.server.ServerEndpointConfig.Configurator
checkOrigin, getNegotiatedExtensions, getNegotiatedSubprotocol
-
-
-
-
Field Detail
-
log
protected static final Logger log
-
-
Method Detail
-
getEndpointInstance
public <EndpointT> EndpointT getEndpointInstance(Class<EndpointT> endpointClass) throws InstantiationException
Obtains an instance ofendpointClass
fromGuice
and creates a context-aware proxy for it, so thatEndpoint
lifecycle methods are executed withinContainerCallContext
andWebsocketConnectionContext
.- Overrides:
getEndpointInstance
in classServerEndpointConfig.Configurator
- Returns:
- a proxy for the newly created
endpointClass
instance. - Throws:
InstantiationException
-
getRequiredEndpointMethodAnnotationTypes
protected HashSet<Class<? extends Annotation>> getRequiredEndpointMethodAnnotationTypes()
Returns a set of annotations ofEndpoint
lifecycle methods that are required to be present inEndpoint
classes using this configurator. By default a singleton ofOnOpen
. Subclasses may override this method if needed by callingsuper
and adding their required annotations to the obtained set before returning it.
-
modifyHandshake
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response)
- Overrides:
modifyHandshake
in classServerEndpointConfig.Configurator
-
getAdditionalDecorator
protected InvocationHandler getAdditionalDecorator(Object endpoint)
Subclasses may override this method to further customizeEndpoints
.InvocationHandler.invoke(Object, Method, Object[])
method of the returned handler will be executed withinContainerCallContext
andWebsocketConnectionContext
. By default it returns a handler that simply invokes the given method onendpoint
.
-
-