Package org.atmosphere.websocket

Examples of org.atmosphere.websocket.WebSocket


                        future.getChannel().close();
                    } else {
                        websocketChannels.add(ctx.getChannel());

                        AtmosphereRequest r = createAtmosphereRequest(ctx, request);
                        WebSocket webSocket = new NettyWebSocket(ctx.getChannel(), framework.getAtmosphereConfig());

                        ctx.setAttachment(webSocket);
                        if (request.headers().contains("X-wakeUpNIO")) {
                            /**
                             * https://github.com/AsyncHttpClient/async-http-client/issues/471
                             *
                             * Netty 3.9.x has an issue and is unable to detect the websocket frame that will be produced if an AtmosphereInterceptor
                             * like the JavaScriptProtocol write bytes just after the handshake's header. The effect is the message is lost when Netty decode the Handshake
                             * request. This can be easily reproduced when wAsync is used with NettoSphere as server. For example, the following message
                             *
                             T 127.0.0.1:8080 -> 127.0.0.1:51295 [AP]
                             HTTP/1.1 101 Switching Protocols.
                             Upgrade: websocket.
                             Connection: Upgrade.
                             Sec-WebSocket-Accept: mFFTAW8KVZebToQFZZcFVWmJh8Y=.
                             .


                             T 127.0.0.1:8080 -> 127.0.0.1:51295 [AP]
                             .21808c569-099b-4d8f-b657-c5965df40449|1391270901601

                             can be lost because the Netty's Decoder fail to realize the handshake contained a response's body. The error doesn't occurs all the time but under
                             load happens more easily.
                             */
                            // Wake up the remote NIO Selector so Netty don't read the hanshake and the first message in a single read.
                            for (int i = 0; i < 512; i++) {
                                webSocket.write(" ");
                            }
                        }
                        webSocketProcessor.open(webSocket, r, AtmosphereResponse.newInstance(framework.getAtmosphereConfig(), r, webSocket));
                    }
                }
View Full Code Here


        Object o = ctx.getAttachment();

        if (o == null) return;

        if (WebSocket.class.isAssignableFrom(o.getClass())) {
            WebSocket webSocket = WebSocket.class.cast(o);
            AtmosphereResource r = webSocket.resource();

            logger.trace("Closing {}", r != null ? r.uuid() : "NULL");

            try {
                webSocketProcessor.close(webSocket, 1005);
View Full Code Here

public class MemoryWebSocketStoreTest extends Assert {
   
    @Test
    public void testAddAndRemove() throws Exception {
        MemoryWebSocketStore store = new MemoryWebSocketStore();
        WebSocket webSocket1 = EasyMock.createMock(WebSocket.class);
        WebSocket webSocket2 = EasyMock.createMock(WebSocket.class);
       
        String connectionKey1 = UUID.randomUUID().toString();
        String connectionKey2 = UUID.randomUUID().toString();
       
        store.addWebSocket(connectionKey1, webSocket1);
View Full Code Here

       
        assertEquals(0, store.getAllWebSockets().size());
    }

    private void verifyGet(MemoryWebSocketStore store, String ck, WebSocket ws, boolean exists) {
        WebSocket aws = store.getWebSocket(ck);
        String ack = store.getConnectionKey(ws);
        if (exists) {
            assertNotNull(aws);
            assertEquals(ws, aws);
            assertNotNull(ack);
View Full Code Here

            }
        } else {
            // look for connection key and get Websocket
            String connectionKey = in.getHeader(WebsocketConstants.CONNECTION_KEY, String.class);
            if (connectionKey != null) {
                WebSocket websocket = getEndpoint().getWebSocketStore().getWebSocket(connectionKey);
                log.debug("Sending to connection key {} -> {}", connectionKey, message);
                sendMessage(websocket, message);
            } else {
                throw new IllegalArgumentException("Failed to send message to single connection; connetion key not set.");
            }
View Full Code Here

public class MemoryWebSocketStoreTest extends Assert {
   
    @Test
    public void testAddAndRemove() throws Exception {
        MemoryWebSocketStore store = new MemoryWebSocketStore();
        WebSocket webSocket1 = EasyMock.createMock(WebSocket.class);
        WebSocket webSocket2 = EasyMock.createMock(WebSocket.class);
       
        String connectionKey1 = UUID.randomUUID().toString();
        String connectionKey2 = UUID.randomUUID().toString();
       
        store.addWebSocket(connectionKey1, webSocket1);
View Full Code Here

       
        assertEquals(0, store.getAllWebSockets().size());
    }

    private void verifyGet(MemoryWebSocketStore store, String ck, WebSocket ws, boolean exists) {
        WebSocket aws = store.getWebSocket(ck);
        String ack = store.getConnectionKey(ws);
        if (exists) {
            assertNotNull(aws);
            assertEquals(ws, aws);
            assertNotNull(ack);
View Full Code Here

    }

    @Test
    public void basicWorkflow() throws IOException, ServletException, ExecutionException, InterruptedException {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        final WebSocket w = new ArrayBaseWebSocket(b);
        final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault()
                .getWebSocketProcessor(framework);

        framework.addAtmosphereHandler("/*", new AtmosphereHandler() {

View Full Code Here

    }

    @Test
    public void encodeURLProxyTest() throws IOException, ServletException, ExecutionException, InterruptedException {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        final WebSocket w = new ArrayBaseWebSocket(b);
        final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault()
                .getWebSocketProcessor(framework);
        final AtomicReference<String> url = new AtomicReference<String>();

        framework.addAtmosphereHandler("/*", new AtmosphereHandler() {
View Full Code Here

    }

    @Test
    public void basicBackwardCompatbileWorkflow() throws Throwable {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        final WebSocket w = new ArrayBaseWebSocket(b);
        final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault()
                .getWebSocketProcessor(framework);

        framework.getBroadcasterFactory().remove("/*");

 
View Full Code Here

TOP

Related Classes of org.atmosphere.websocket.WebSocket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.