Package io.netty.channel.embedded

Examples of io.netty.channel.embedded.EmbeddedChannel.writeInbound()


        return fullResponse;
    }

    public static FullHttpResponse decodeFullHttpResponse(final EmbeddedChannel channel) throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
        ch.writeInbound(channel.readOutbound());
        final HttpResponse response = ch.readInbound();
        final HttpContent content = ch.readInbound();
        final DefaultFullHttpResponse fullResponse = new DefaultFullHttpResponse(response.getProtocolVersion(),
                response.getStatus(), content.content());
        fullResponse.headers().add(response.headers());
View Full Code Here


        final FullHttpRequest httpRequest = createHttpRequest(HttpMethod.OPTIONS);

        httpRequest.headers().set(HttpHeaders.Names.ORIGIN, origin);
        httpRequest.headers().set(HttpHeaders.Names.ACCESS_CONTROL_REQUEST_HEADERS, corsHeaders);
        final EmbeddedChannel channel = new EmbeddedChannel(new CorsInboundHandler());
        channel.writeInbound(httpRequest);

        final HttpResponse response = channel.readOutbound();
        final HttpHeaders headers = response.headers();
        assertThat(headers.get(HttpHeaders.Names.CONTENT_TYPE), is("text/plain; charset=UTF-8"));
        assertThat(headers.get(HttpHeaders.Names.CACHE_CONTROL), is("max-age=31536000, public"));
View Full Code Here

    @Test
    public void verifyChannelAttributesNotPreflightRequestDefaults() {
        final FullHttpRequest httpRequest = createHttpRequest(HttpMethod.GET);
        final EmbeddedChannel channel = new EmbeddedChannel(new CorsInboundHandler());
        channel.writeInbound(httpRequest);
        final CorsMetadata corsMetadata = channel.attr(CorsInboundHandler.CORS).get();
        assertThat(corsMetadata.origin(), is("*"));
        assertThat(corsMetadata.hasHeaders(), is(false));
        assertThat((FullHttpRequest) channel.readInbound(), equalTo(httpRequest));
        channel.finish();
View Full Code Here

    public void verifyChannelAttributesNotPreflightRequest() {
        final HttpRequest httpRequest = createHttpRequest(HttpMethod.GET);
        httpRequest.headers().set(HttpHeaders.Names.ORIGIN, "example.se");
        httpRequest.headers().set(HttpHeaders.Names.ACCESS_CONTROL_REQUEST_HEADERS, "content-type");
        final EmbeddedChannel channel = new EmbeddedChannel(new CorsInboundHandler());
        channel.writeInbound(httpRequest);
        final CorsMetadata corsMetadata = channel.attr(CorsInboundHandler.CORS).get();
        assertThat(corsMetadata.origin(), is("example.se"));
        assertThat(corsMetadata.headers(), is("content-type"));
        assertThat((HttpRequest) channel.readInbound(), equalTo(httpRequest));
        channel.finish();
View Full Code Here

    @Test
    public void notificationWithNonExistingChannelId() throws Exception {
        final SimplePushServer simplePushServer = defaultPushServer();
        final EmbeddedChannel channel = createWebsocketChannel(simplePushServer);
        channel.writeInbound(notificationRequest("non-existing-channelId", 10L));
        final HttpResponse httpResponse = channel.readOutbound();
        assertThat(httpResponse.getStatus().code(), equalTo(200));
        channel.close();
    }
View Full Code Here

    }

    private HttpResponse sendNotification(final FullHttpRequest request,
                                          final SimplePushServer simplePushServer) throws Exception {
        final EmbeddedChannel ch = createWebsocketChannel(simplePushServer);
        ch.writeInbound(request);
        return (HttpResponse) ch.readOutbound();
    }

    private void registerUserAgent(final String uaid, final EmbeddedChannel ch) {
        UserAgents.getInstance().add(uaid, channelSession(ch));
View Full Code Here

        channel.close();
    }

    public static HttpResponse decodeHttpResponse(final EmbeddedChannel channel) {
        final EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
        ch.writeInbound(channel.readOutbound());
        return ch.readInbound();
    }

    public static FullHttpResponse decodeFullHttpResponse(final EmbeddedChannel channel) {
        final EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
View Full Code Here

        return ch.readInbound();
    }

    public static FullHttpResponse decodeFullHttpResponse(final EmbeddedChannel channel) {
        final EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
        ch.writeInbound(channel.outboundMessages().toArray());
        final HttpResponse response = ch.readInbound();
        final HttpContent content = ch.readInbound();
        final DefaultFullHttpResponse fullResponse;
        if (content != null) {
            fullResponse = new DefaultFullHttpResponse(response.getProtocolVersion(), response.getStatus(), content.content());
View Full Code Here

        final SimplePushServer pushServer = new DefaultSimplePushServer(new InMemoryDataStore(), simplePushConfig, privateKey);
        final SimplePushServiceFactory factory = new SimplePushServiceFactory(sockjsConf, pushServer);
        final EmbeddedChannel channel = createChannel(factory);
        final FullHttpRequest request = websocketUpgradeRequest(factory.config().prefix() + Transports.Type.WEBSOCKET.path());
        request.headers().set(Names.SEC_WEBSOCKET_PROTOCOL, "push-notification");
        channel.writeInbound(request);
        final FullHttpResponse response = decodeFullHttpResponse(channel);
        assertThat(response.getStatus(), is(HttpResponseStatus.SWITCHING_PROTOCOLS));
        assertThat(response.headers().get(HttpHeaders.Names.UPGRADE), equalTo("websocket"));
        assertThat(response.headers().get(HttpHeaders.Names.CONNECTION), equalTo("Upgrade"));
        assertThat(response.headers().get(Names.SEC_WEBSOCKET_PROTOCOL), equalTo("push-notification"));
View Full Code Here

        throw new IllegalArgumentException("Response is expected to be of type TextWebSocketFrame was: " + response);
    }

    private FullHttpResponse sendXhrOpenFrameRequest(final SockJsServiceFactory factory, final String sessionUrl) throws Exception {
        final EmbeddedChannel openChannel = createChannel(factory);
        openChannel.writeInbound(httpGetRequest(sessionUrl + Transports.Type.XHR.path()));
        final FullHttpResponse openFrameResponse = decodeFullHttpResponse(openChannel);
        openChannel.close();
        return openFrameResponse;
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.