Skip to content

Commit

Permalink
Issue #4903 - Improved behavior for Custom ServerEndpointConfig.Confi…
Browse files Browse the repository at this point in the history
…gurator

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Jun 10, 2020
1 parent 9bfc168 commit b22e306
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,14 @@ public void addEndpoint(ServerEndpointConfig config) throws DeploymentException
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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public void onMessage(String message)
}
}

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)
Expand Down Expand Up @@ -182,6 +190,25 @@ public <T> T getEndpointInstance(Class<T> endpointClass)
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()
{
Expand Down

0 comments on commit b22e306

Please sign in to comment.