Issue #2559 - Use Configurator declared in ServerEndpointConfig over @ServerEndpoint annotation
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
e6e49bdc85
commit
a6547eaf83
|
@ -53,12 +53,13 @@ public class AnnotatedServerEndpointConfig implements ServerEndpointConfig
|
||||||
|
|
||||||
public AnnotatedServerEndpointConfig(WebSocketContainerScope containerScope, Class<?> endpointClass, ServerEndpoint anno, ServerEndpointConfig baseConfig) throws DeploymentException
|
public AnnotatedServerEndpointConfig(WebSocketContainerScope containerScope, Class<?> endpointClass, ServerEndpoint anno, ServerEndpointConfig baseConfig) throws DeploymentException
|
||||||
{
|
{
|
||||||
ServerEndpointConfig.Configurator configr = null;
|
// A manually declared Configurator (not the one from the annotation)
|
||||||
|
ServerEndpointConfig.Configurator manualConfigurator = null;
|
||||||
|
|
||||||
// Copy from base config
|
// Copy from base config
|
||||||
if (baseConfig != null)
|
if (baseConfig != null)
|
||||||
{
|
{
|
||||||
configr = baseConfig.getConfigurator();
|
manualConfigurator = baseConfig.getConfigurator();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decoders (favor provided config over annotation)
|
// Decoders (favor provided config over annotation)
|
||||||
|
@ -112,24 +113,24 @@ public class AnnotatedServerEndpointConfig implements ServerEndpointConfig
|
||||||
userProperties.putAll(baseConfig.getUserProperties());
|
userProperties.putAll(baseConfig.getUserProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerEndpointConfig.Configurator cfgr;
|
ServerEndpointConfig.Configurator resolvedConfigurator;
|
||||||
|
|
||||||
// Use ServerEndpointConfig provided configurator if declared
|
// Use ServerEndpointConfig provided configurator if declared
|
||||||
if (configr != null)
|
if ( (manualConfigurator != null) && !(manualConfigurator instanceof ContainerDefaultConfigurator) )
|
||||||
{
|
{
|
||||||
cfgr = configr;
|
resolvedConfigurator = manualConfigurator;
|
||||||
}
|
}
|
||||||
// Use Container Default if annotation based configurator is undeclared
|
// Use Container Default if annotation based configurator is undeclared
|
||||||
else if (anno.configurator() == ServerEndpointConfig.Configurator.class)
|
else if (anno.configurator() == ServerEndpointConfig.Configurator.class)
|
||||||
{
|
{
|
||||||
cfgr = new ContainerDefaultConfigurator();
|
resolvedConfigurator = new ContainerDefaultConfigurator();
|
||||||
}
|
}
|
||||||
// Use annotation declared configurator
|
// Use annotation declared configurator
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cfgr = anno.configurator().getDeclaredConstructor( ).newInstance();
|
resolvedConfigurator = anno.configurator().getDeclaredConstructor( ).newInstance();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -143,7 +144,7 @@ public class AnnotatedServerEndpointConfig implements ServerEndpointConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure all Configurators obtained are decorated
|
// Make sure all Configurators obtained are decorated
|
||||||
this.configurator = containerScope.getObjectFactory().decorate(cfgr);
|
this.configurator = containerScope.getObjectFactory().decorate(resolvedConfigurator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -52,11 +52,12 @@ public class PongContextListener implements ServletContextListener
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Configurator config = new Config();
|
Configurator config = new Config();
|
||||||
|
|
||||||
|
// Use manually declared Configurator
|
||||||
container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class,"/ping").configurator(config).build());
|
container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class,"/ping").configurator(config).build());
|
||||||
container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class,"/pong").configurator(config).build());
|
container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class,"/pong").configurator(config).build());
|
||||||
|
// Use annotation declared Configurator
|
||||||
container.addEndpoint(ServerEndpointConfig.Builder.create(PongSocket.class,"/ping-socket").build());
|
container.addEndpoint(ServerEndpointConfig.Builder.create(PongSocket.class,"/ping-socket").build());
|
||||||
container.addEndpoint(ServerEndpointConfig.Builder.create(PongSocket.class,"/pong-socket").build());
|
|
||||||
}
|
}
|
||||||
catch (DeploymentException e)
|
catch (DeploymentException e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue