Search in sources :

Example 1 with WebSocketReconnectHandler

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()));
}
Also used : WebSocketReconnectHandler(io.undertow.websockets.jsr.WebSocketReconnectHandler) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) IOException(java.io.IOException) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) URI(java.net.URI) CloseReason(javax.websocket.CloseReason) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Session(javax.websocket.Session) BeforeClass(org.junit.BeforeClass)

Aggregations

DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 DeploymentManager (io.undertow.servlet.api.DeploymentManager)1 ServletContainer (io.undertow.servlet.api.ServletContainer)1 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)1 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)1 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)1 WebSocketReconnectHandler (io.undertow.websockets.jsr.WebSocketReconnectHandler)1 IOException (java.io.IOException)1 URI (java.net.URI)1 CloseReason (javax.websocket.CloseReason)1 Session (javax.websocket.Session)1 BeforeClass (org.junit.BeforeClass)1