Package pl.morgwai.base.servlet.scopes
Class GuiceServerEndpointConfigurator
- java.lang.Object
-
- jakarta.websocket.server.ServerEndpointConfig.Configurator
-
- pl.morgwai.base.servlet.scopes.GuiceServerEndpointConfigurator
-
- Direct Known Subclasses:
PingingEndpointConfigurator
public class GuiceServerEndpointConfigurator extends ServerEndpointConfig.Configurator
Automatically injects dependencies of endpoint instances and ensures that lifecycle methods of the created endpoints are executed withinWebsocketConnectionContext
andContainerCallContext
.For endpoints annotated with @
ServerEndpoint
, this class must 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.For endpoints added programmatically, a
ServerEndpointConfig
similar to the below should be used:websocketContainer.addEndpoint(ServerEndpointConfig.Builder .create(MyEndpoint.class, "/websocket/mySocket") .configurator(new GuiceServerEndpointConfigurator()) .build());
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
log
-
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 customize endpoints.<EndpointT>
EndpointTgetEndpointInstance(Class<EndpointT> endpointClass)
Creates a newendpointClass
instance and a proxy for it.protected List<Class<? extends Annotation>>
getRequiredEndpointMethodAnnotationTypes()
Returns a list of annotations of endpoint lifecycle methods that are required to be present.void
modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response)
Stores into the user properties theHttpSession
associated with therequest
.-
Methods inherited from class jakarta.websocket.server.ServerEndpointConfig.Configurator
checkOrigin, getNegotiatedExtensions, getNegotiatedSubprotocol
-
-
-
-
Method Detail
-
getEndpointInstance
public <EndpointT> EndpointT getEndpointInstance(Class<EndpointT> endpointClass) throws InstantiationException
Creates a newendpointClass
instance and a proxy for it. Injects dependencies of the newly created endpoint. The proxy ensures that endpoint's lifecycle methods are executed withinContainerCallContext
andWebsocketConnectionContext
.- Overrides:
getEndpointInstance
in classServerEndpointConfig.Configurator
- Returns:
- a proxy for a new
endpointClass
instance. - Throws:
InstantiationException
-
getRequiredEndpointMethodAnnotationTypes
protected List<Class<? extends Annotation>> getRequiredEndpointMethodAnnotationTypes()
Returns a list of annotations of endpoint lifecycle methods that are required to be present. By default a singleton ofOnOpen
. Subclasses may override this method if needed.
-
modifyHandshake
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response)
Stores into the user properties theHttpSession
associated with therequest
.- Overrides:
modifyHandshake
in classServerEndpointConfig.Configurator
-
getAdditionalDecorator
protected InvocationHandler getAdditionalDecorator(Object endpoint)
Subclasses may override this method to further customize endpoints.InvocationHandler.invoke(Object, Method, Object[])
method of the returned handler will be executed withinContainerCallContext
andWebsocketConnectionContext
. By default it returns a handler that simply invokes a given method onendpoint
.
-
-