use of io.undertow.websockets.jsr.WebSocketReconnectHandler in project undertow by undertow-io.
the class ClientEndpointReconnectTestCase method setup.
@BeforeClass
public static void setup() throws Exception {
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(ClientEndpointReconnectTestCase.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(ClientEndpointReconnectTestCase.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(new DefaultByteBufferPool(true, 8192)).setWorker(DefaultServer.getWorker()).addEndpoint(DisconnectServerEndpoint.class).addEndpoint(AnnotatedClientReconnectEndpoint.class).addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {
@Override
public void ready(ServerWebSocketContainer container) {
deployment = container;
}
}).setReconnectHandler(new WebSocketReconnectHandler() {
@Override
public long disconnected(CloseReason closeReason, URI connectionUri, Session session, int disconnectCount) {
if (disconnectCount < 3) {
return 1;
} else {
return -1;
}
}
@Override
public long reconnectFailed(IOException exception, URI connectionUri, Session session, int failedCount) {
failed = true;
return -1;
}
})).setDeploymentName("servletContext.war");
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", manager.start()));
}
Aggregations