Search in sources :

Example 46 with WebSocket

use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.

the class PathTest method testSingletonManagedWebSocketPathMessage.

@Test
public void testSingletonManagedWebSocketPathMessage() throws IOException, ServletException {
    instanceCount = 0;
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    final WebSocket w = new ArrayBaseWebSocket(b);
    final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/singleton/ws/bar").method("GET").build();
    processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
    assertEquals(instanceCount, 0);
    assertNotNull(r.get());
    assertEquals(MyInterceptor.invokationCount, 1);
    assertEquals(r.get(), "/singleton/ws/bar");
}
Also used : AtmosphereRequestImpl(org.atmosphere.cpr.AtmosphereRequestImpl) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) WebSocketProcessor(org.atmosphere.websocket.WebSocketProcessor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WebSocket(org.atmosphere.websocket.WebSocket) Test(org.testng.annotations.Test)

Example 47 with WebSocket

use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.

the class EmbeddedWebSocketHandler method webSocket.

private WebSocket webSocket(InputStream inputStream) {
    WebSocket webSocket = webSockets.get(inputStream);
    if (webSocket == null) {
        webSocket = new ArrayBaseWebSocket();
        webSockets.put(inputStream, webSocket);
        AtmosphereRequest request = AtmosphereRequestImpl.newInstance().header("Connection", "Upgrade").header("Upgrade", "websocket").pathInfo(requestURI);
        try {
            processor.open(webSocket, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, webSocket));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return webSocket;
}
Also used : AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) IOException(java.io.IOException) WebSocket(org.atmosphere.websocket.WebSocket)

Aggregations

WebSocket (org.atmosphere.websocket.WebSocket)47 ByteArrayOutputStream (java.io.ByteArrayOutputStream)41 WebSocketProcessor (org.atmosphere.websocket.WebSocketProcessor)41 Test (org.testng.annotations.Test)39 IOException (java.io.IOException)25 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 WebSocketEventListenerAdapter (org.atmosphere.websocket.WebSocketEventListenerAdapter)6 AtmosphereRequest (org.atmosphere.cpr.AtmosphereRequest)5 HashMap (java.util.HashMap)4 ExecutionException (java.util.concurrent.ExecutionException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 WebSocketEventListener (org.atmosphere.websocket.WebSocketEventListener)4 Reader (java.io.Reader)3 ServletException (jakarta.servlet.ServletException)2 Cookie (jakarta.servlet.http.Cookie)2 HashSet (java.util.HashSet)2 ServletException (javax.servlet.ServletException)2 Cookie (javax.servlet.http.Cookie)2 AtmosphereRequestImpl (org.atmosphere.cpr.AtmosphereRequestImpl)2 WebSocketHandlerAdapter (org.atmosphere.websocket.WebSocketHandlerAdapter)2