Issue #4903 - Improved behavior for Custom ServerEndpointConfig.Configurator

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2020-06-10 17:03:26 -05:00
parent 9bfc168329
commit b22e306796
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
2 changed files with 34 additions and 1 deletions

View File

@ -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))
{

View File

@ -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()
{