Issue #4903 - Improved behavior for Custom ServerEndpointConfig.Configurator
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
9bfc168329
commit
b22e306796
|
@ -173,8 +173,14 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
|||
if (isStarted() || isStarting())
|
||||
{
|
||||
ServerEndpointConfig.Configurator configurator = config.getConfigurator();
|
||||
|
||||
if (configurator == null)
|
||||
{
|
||||
throw new DeploymentException("Unable to deploy with null ServerEndpointConfig.Configurator");
|
||||
}
|
||||
|
||||
// only validate constructor and class modifiers on non-custom configurators
|
||||
if (configurator instanceof ContainerDefaultConfigurator)
|
||||
if (configurator.getClass() == ContainerDefaultConfigurator.class)
|
||||
{
|
||||
if (!ReflectUtils.isDefaultConstructable(endpointClass))
|
||||
{
|
||||
|
|
|
@ -96,6 +96,14 @@ public class PrivateEndpointTest
|
|||
}
|
||||
}
|
||||
|
||||
private class CustomPrivateEndpoint extends Endpoint
|
||||
{
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomEndpoint extends Endpoint implements MessageHandler.Whole<String>
|
||||
{
|
||||
public CustomEndpoint(String id)
|
||||
|
@ -182,6 +190,25 @@ public class PrivateEndpointTest
|
|||
assertNotNull(session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomPrivateEndpoint() throws Exception
|
||||
{
|
||||
ServerEndpointConfig config = ServerEndpointConfig.Builder.create(CustomPrivateEndpoint.class, "/")
|
||||
.configurator(new ServerEndpointConfig.Configurator()
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getEndpointInstance(Class<T> endpointClass)
|
||||
{
|
||||
return (T)new CustomPrivateEndpoint();
|
||||
}
|
||||
}).build();
|
||||
start(container -> container.addEndpoint(config));
|
||||
|
||||
Session session = client.connectToServer(new CustomEndpoint("client"), WSURI.toWebsocket(server.getURI().resolve("/")));
|
||||
assertNotNull(session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEndpointNoConfigurator()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue