Issue #4407 - merge annotated ServerEndpointConfig with provided config
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
b400d00f03
commit
af2a9cfd5b
|
@ -280,7 +280,7 @@ public class JavaxWebSocketClientContainer extends JavaxWebSocketContainer imple
|
||||||
return new EmptyClientEndpointConfig();
|
return new EmptyClientEndpointConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EndpointConfig readAnnotatedConfig(Object endpoint, EndpointConfig config) throws DeploymentException
|
private EndpointConfig readAnnotatedConfig(Object endpoint, EndpointConfig config) throws DeploymentException
|
||||||
{
|
{
|
||||||
ClientEndpoint anno = endpoint.getClass().getAnnotation(ClientEndpoint.class);
|
ClientEndpoint anno = endpoint.getClass().getAnnotation(ClientEndpoint.class);
|
||||||
if (anno != null)
|
if (anno != null)
|
||||||
|
|
|
@ -166,18 +166,6 @@ public class JavaxWebSocketServerContainer extends JavaxWebSocketClientContainer
|
||||||
return new UndefinedServerEndpointConfig(endpoint.getClass());
|
return new UndefinedServerEndpointConfig(endpoint.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EndpointConfig readAnnotatedConfig(Object endpoint, EndpointConfig config) throws DeploymentException
|
|
||||||
{
|
|
||||||
ServerEndpoint anno = endpoint.getClass().getAnnotation(ServerEndpoint.class);
|
|
||||||
if (anno != null)
|
|
||||||
{
|
|
||||||
// Overwrite Config from Annotation
|
|
||||||
// TODO: should we merge with provided config?
|
|
||||||
return new AnnotatedServerEndpointConfig(this, endpoint.getClass(), anno, config);
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addEndpoint(Class<?> endpointClass) throws DeploymentException
|
public void addEndpoint(Class<?> endpointClass) throws DeploymentException
|
||||||
{
|
{
|
||||||
|
@ -192,10 +180,7 @@ public class JavaxWebSocketServerContainer extends JavaxWebSocketClientContainer
|
||||||
{
|
{
|
||||||
ServerEndpoint anno = endpointClass.getAnnotation(ServerEndpoint.class);
|
ServerEndpoint anno = endpointClass.getAnnotation(ServerEndpoint.class);
|
||||||
if (anno == null)
|
if (anno == null)
|
||||||
{
|
throw new DeploymentException(String.format("Class must be @%s annotated: %s", ServerEndpoint.class.getName(), endpointClass.getName()));
|
||||||
throw new DeploymentException(String.format("Class must be @%s annotated: %s",
|
|
||||||
ServerEndpoint.class.getName(), endpointClass.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerEndpointConfig config = new AnnotatedServerEndpointConfig(this, endpointClass, anno);
|
ServerEndpointConfig config = new AnnotatedServerEndpointConfig(this, endpointClass, anno);
|
||||||
addEndpointMapping(config);
|
addEndpointMapping(config);
|
||||||
|
@ -214,36 +199,36 @@ public class JavaxWebSocketServerContainer extends JavaxWebSocketClientContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addEndpoint(ServerEndpointConfig config) throws DeploymentException
|
public void addEndpoint(ServerEndpointConfig providedConfig) throws DeploymentException
|
||||||
{
|
{
|
||||||
if (config == null)
|
if (providedConfig == null)
|
||||||
{
|
|
||||||
throw new DeploymentException("ServerEndpointConfig is null");
|
throw new DeploymentException("ServerEndpointConfig is null");
|
||||||
}
|
|
||||||
|
|
||||||
if (isStarted() || isStarting())
|
if (isStarted() || isStarting())
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
Class<?> endpointClass = providedConfig.getEndpointClass();
|
||||||
{
|
|
||||||
LOG.debug("addEndpoint({}) path={} endpoint={}", config, config.getPath(), config.getEndpointClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// If we have annotations merge the annotated ServerEndpointConfig with the provided one.
|
||||||
|
ServerEndpoint anno = endpointClass.getAnnotation(ServerEndpoint.class);
|
||||||
|
ServerEndpointConfig config = (anno == null) ? providedConfig
|
||||||
|
: new AnnotatedServerEndpointConfig(this, endpointClass, anno, providedConfig);
|
||||||
|
|
||||||
|
if (LOG.isDebugEnabled())
|
||||||
|
LOG.debug("addEndpoint({}) path={} endpoint={}", config, config.getPath(), endpointClass);
|
||||||
|
|
||||||
addEndpointMapping(config);
|
addEndpointMapping(config);
|
||||||
}
|
}
|
||||||
catch (WebSocketException e)
|
catch (WebSocketException e)
|
||||||
{
|
{
|
||||||
throw new DeploymentException("Unable to deploy: " + config.getEndpointClass().getName(), e);
|
throw new DeploymentException("Unable to deploy: " + endpointClass.getName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (deferredEndpointConfigs == null)
|
if (deferredEndpointConfigs == null)
|
||||||
{
|
|
||||||
deferredEndpointConfigs = new ArrayList<>();
|
deferredEndpointConfigs = new ArrayList<>();
|
||||||
}
|
deferredEndpointConfigs.add(providedConfig);
|
||||||
deferredEndpointConfigs.add(config);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,11 +127,11 @@ public class AnnotatedServerEndpointTest
|
||||||
this.path = "/override";
|
this.path = "/override";
|
||||||
this.subprotocol = "override";
|
this.subprotocol = "override";
|
||||||
|
|
||||||
//assertResponse("configurator", EchoSocketConfigurator.class.getName());
|
assertResponse("configurator", EchoSocketConfigurator.class.getName());
|
||||||
assertResponse("text-max", "111,222");
|
assertResponse("text-max", "111,222");
|
||||||
assertResponse("binary-max", "333,444");
|
assertResponse("binary-max", "333,444");
|
||||||
//assertResponse("decoders", DateDecoder.class.getName());
|
assertResponse("decoders", DateDecoder.class.getName());
|
||||||
//assertResponse("encoders", TimeEncoder.class.getName());
|
assertResponse("encoders", TimeEncoder.class.getName());
|
||||||
assertResponse("subprotocols", "override");
|
assertResponse("subprotocols", "override");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue