Package io.netty.channel.embedded

Examples of io.netty.channel.embedded.EmbeddedChannel


        verifyHeaders(WebSocketVersion.V13);
    }

    private static void verifyHeaders(final WebSocketVersion version) throws Exception {
        final SockJsConfig config = SockJsConfig.withPrefix("/echo").build();
        final EmbeddedChannel ch = webSocketChannel(config);
        final FullHttpRequest request = webSocketUpgradeRequest("/websocket", version);
        ch.writeInbound(request);
        final HttpResponse response = decode(ch);
        assertThat(response.getStatus(), is(HttpResponseStatus.SWITCHING_PROTOCOLS));
        assertThat(response.headers().get(CONNECTION), equalTo("Upgrade"));
        assertThat(response.headers().get(UPGRADE), equalTo("websocket"));
        assertThat(response.headers().get(CONTENT_LENGTH), is(nullValue()));
View Full Code Here


public class HtmlFileTransportTest {

    @Test
    public void writeMissingCallback() {
        final String url = "/test/htmlfile?c=";
        final EmbeddedChannel ch = newHtmlFileChannel(url);
        ch.writeInbound(new DefaultHttpRequest(HTTP_1_1, GET, url));
        final HttpResponse response = ch.readOutbound();
        assertThat(response.getStatus(), equalTo(INTERNAL_SERVER_ERROR));
        assertThat(response.headers().get(CONTENT_TYPE), equalTo(Transports.CONTENT_TYPE_PLAIN));
        verifyNoCacheHeaders(response);
    }
View Full Code Here

    }

    @Test
    public void write() throws IOException {
        final String url = "/test/htmlfile?c=%63allback";
        final EmbeddedChannel ch = newHtmlFileChannel("/test/htmlfile?c=%63allback");
        ch.writeInbound(new DefaultHttpRequest(HTTP_1_1, GET, url));
        ch.writeOutbound(new OpenFrame());

        final HttpResponse response = ch.readOutbound();
        assertThat(response.getStatus(), equalTo(OK));
        assertThat(response.headers().get(CONTENT_TYPE), equalTo(Transports.CONTENT_TYPE_HTML));
        verifyNoCacheHeaders(response);

        final HttpContent headerChunk = ch.readOutbound();
        assertThat(headerChunk.content().readableBytes(), is(greaterThan(1024)));
        final String header = headerChunk.content().toString(UTF_8);
        assertThat(header, containsString("var c = parent.callback"));
        final HttpContent chunk = ch.readOutbound();
        assertThat(chunk.content().toString(UTF_8), equalTo("<script>\np(\"o\");\n</script>\r\n"));

        ch.write(new MessageFrame("x"));
        final HttpContent messageContent = ch.readOutbound();
        assertThat(messageContent.content().toString(UTF_8), equalTo("<script>\np(\"a[\\\"x\\\"]\");\n</script>\r\n"));
    }
View Full Code Here

    }

    private static EmbeddedChannel newStreamingChannel(final SockJsConfig config, final String path) {
        final HttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, path);
        final HtmlFileTransport transport = new HtmlFileTransport(config, request);
        return new EmbeddedChannel(transport);
    }
View Full Code Here

    @Test
    public void flush() {
        final SockJsConfig config = SockJsConfig.withPrefix("/test").cookiesNeeded().build();
        final XhrPollingTransport transport = new XhrPollingTransport(config, request("", HttpVersion.HTTP_1_1));
        final EmbeddedChannel channel = new EmbeddedChannel(transport);
        channel.writeOutbound(new OpenFrame());
        final FullHttpResponse response = channel.readOutbound();
        assertThat(response.getStatus(), equalTo(HttpResponseStatus.OK));
        assertThat(response.content().toString(CharsetUtil.UTF_8), equalTo("o" + '\n'));
        assertThat(response.getProtocolVersion(), equalTo(HttpVersion.HTTP_1_1));
        SockJsTestUtil.verifyDefaultResponseHeaders(response, Transports.CONTENT_TYPE_JAVASCRIPT);
        channel.finish();
    }
View Full Code Here

    }

    private static FullHttpResponse processHttpRequest(final FullHttpRequest request) {
        final JsonpSendTransport transport = new JsonpSendTransport(SockJsConfig.withPrefix("/test")
                .cookiesNeeded().build());
        final EmbeddedChannel channel = new EmbeddedChannel(transport);
        channel.writeInbound(request);
        final FullHttpResponse response = channel.readOutbound();
        channel.finish();
        return response;
    }
View Full Code Here

    private static final int PRELUDE_SIZE = 2048 + 1;

    @Test
    public void messageReceived() {
        final EmbeddedChannel ch = newStreamingChannel();
        ch.writeOutbound(new OpenFrame());

        final HttpResponse response = ch.readOutbound();
        assertThat(response.getStatus(), equalTo(HttpResponseStatus.OK));
        assertThat(response.headers().get(CONTENT_TYPE), equalTo(Transports.CONTENT_TYPE_JAVASCRIPT));
        assertThat(response.headers().get(TRANSFER_ENCODING), equalTo(CHUNKED.toString()));
        SockJsTestUtil.assertCORSHeaders(response, "*");
        SockJsTestUtil.verifyNoCacheHeaders(response);

        final DefaultHttpContent prelude = ch.readOutbound();
        assertThat(prelude.content().readableBytes(), is(PRELUDE_SIZE));
        prelude.content().readBytes(Unpooled.buffer(PRELUDE_SIZE));

        final DefaultHttpContent openResponse = ch.readOutbound();
        assertThat(openResponse.content().toString(CharsetUtil.UTF_8), equalTo("o\n"));
        ch.finish();
    }
View Full Code Here

    }

    private static EmbeddedChannel newStreamingChannel(final SockJsConfig config) {
        final HttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/xhr-streaming");
        final XhrStreamingTransport transport = new XhrStreamingTransport(config, request);
        return new EmbeddedChannel(transport);
    }
View Full Code Here

public class WebSocketSendHandlerTest {

    @Test
    public void messageReceived() throws Exception {
        final EmbeddedChannel ch = createWebsocketChannel(SockJsConfig.withPrefix("/echo").build());
        ch.writeOutbound(new MessageFrame("testing"));
        final TextWebSocketFrame textFrame = ch.readOutbound();
        assertThat(textFrame.content().toString(CharsetUtil.UTF_8), equalTo("a[\"testing\"]"));
        textFrame.release();
    }
View Full Code Here

        assertThat(textFrame.content().toString(CharsetUtil.UTF_8), equalTo("a[\"testing\"]"));
        textFrame.release();
    }

    private static EmbeddedChannel createWebsocketChannel(final SockJsConfig config) {
        return new EmbeddedChannel(
                new WebSocket13FrameDecoder(true, false, 2048),
                new WebSocketTransport(config),
                new WebSocketSendHandler());
    }
View Full Code Here

TOP

Related Classes of io.netty.channel.embedded.EmbeddedChannel

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.