Search in sources :

Example 21 with DefaultHttpHeaders

use of io.netty.handler.codec.http.DefaultHttpHeaders in project motan by weibocom.

the class NettyHttpRequestHandlerTest method testChannelRead0.

@Test
public void testChannelRead0() throws Exception {
    final MessageHandler messageHandler = mockery.mock(MessageHandler.class);
    final ChannelHandlerContext ctx = mockery.mock(ChannelHandlerContext.class);
    final FullHttpResponse response = mockery.mock(FullHttpResponse.class);
    mockery.checking(new Expectations() {

        {
            allowing(ctx).write(with(any(FullHttpResponse.class)));
            will(new CustomAction("verify") {

                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    FullHttpResponse actualResponse = (FullHttpResponse) invocation.getParameter(0);
                    assertNotNull(actualResponse);
                    assertEquals(response, actualResponse);
                    return null;
                }
            });
            allowing(ctx).flush();
            will(returnValue(null));
            allowing(ctx).close();
            will(returnValue(null));
            atLeast(1).of(messageHandler).handle(with(any(Channel.class)), with(anything()));
            will(returnValue(response));
            allowing(response).headers();
            will(returnValue(new DefaultHttpHeaders()));
        }
    });
    FullHttpRequest httpRequest = buildHttpRequest("anyPath");
    NettyHttpRequestHandler handler = new NettyHttpRequestHandler(null, messageHandler);
    handler.channelRead0(ctx, httpRequest);
}
Also used : Expectations(org.jmock.Expectations) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) MessageHandler(com.weibo.api.motan.transport.MessageHandler) Invocation(org.jmock.api.Invocation) CustomAction(org.jmock.lib.action.CustomAction) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) Channel(com.weibo.api.motan.transport.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) Test(org.junit.Test)

Example 22 with DefaultHttpHeaders

use of io.netty.handler.codec.http.DefaultHttpHeaders in project undertow by undertow-io.

the class WebSocketTestClient method connect.

/**
     * Connect the WebSocket client
     *
     * @throws Exception
     */
public WebSocketTestClient connect() throws Exception {
    String protocol = uri.getScheme();
    if (!"ws".equals(protocol)) {
        throw new IllegalArgumentException("Unsupported protocol: " + protocol);
    }
    final WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, version, null, false, new DefaultHttpHeaders());
    EventLoopGroup group = new NioEventLoopGroup();
    final CountDownLatch handshakeLatch = new CountDownLatch(1);
    bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer() {

        @Override
        protected void initChannel(Channel channel) throws Exception {
            ChannelPipeline p = channel.pipeline();
            p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), new WSClientHandler(handshaker, handshakeLatch));
        }
    });
    // Connect
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(uri.getHost(), uri.getPort()));
    future.syncUninterruptibly();
    ch = future.channel();
    handshaker.handshake(ch).syncUninterruptibly();
    handshakeLatch.await();
    return this;
}
Also used : WebSocketClientHandshaker(io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker) ChannelFuture(io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) ExecutionException(java.util.concurrent.ExecutionException) ChannelPipeline(io.netty.channel.ChannelPipeline) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) ChannelInitializer(io.netty.channel.ChannelInitializer) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 23 with DefaultHttpHeaders

use of io.netty.handler.codec.http.DefaultHttpHeaders in project tesla by linking12.

the class HttpFiltersRunner method createResponse.

private HttpResponse createResponse(HttpResponseStatus httpResponseStatus, HttpRequest originalRequest) {
    HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add("Transfer-Encoding", "chunked");
    HttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, httpResponseStatus);
    httpResponse.headers().add(httpHeaders);
    return httpResponse;
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Example 24 with DefaultHttpHeaders

use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.

the class HttpServletResponseWrapperForResponseInfoTest method beforeMethod.

@Before
public void beforeMethod() {
    headers = new DefaultHttpHeaders();
    responseInfoMock = mock(ResponseInfo.class);
    doReturn(headers).when(responseInfoMock).getHeaders();
    wrapper = new HttpServletResponseWrapperForResponseInfo<>(responseInfoMock);
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) Before(org.junit.Before)

Example 25 with DefaultHttpHeaders

use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.

the class RequestInfoImpl method dummyInstanceForUnknownRequests.

/**
     * Creates a new RequestInfo that represents unknown requests. Usually only needed in error situations. The URI,
     * query params, and headers will be tagged with {@link #NONE_OR_UNKNOWN_TAG} to indicate that the request was
     * unknown.
     */
public static RequestInfoImpl<?> dummyInstanceForUnknownRequests() {
    HttpHeaders headers = new DefaultHttpHeaders().set(NONE_OR_UNKNOWN_TAG, "true");
    QueryStringDecoder queryParams = new QueryStringDecoder("/?" + NONE_OR_UNKNOWN_TAG + "=true");
    return new RequestInfoImpl(NONE_OR_UNKNOWN_TAG, null, headers, null, queryParams, null, null, null, null, false, true, false);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders)

Aggregations

DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)51 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)38 Test (org.testng.annotations.Test)20 Test (org.junit.Test)18 Cookie (io.netty.handler.codec.http.cookie.Cookie)14 DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)12 HttpTest (org.asynchttpclient.testserver.HttpTest)12 AsyncCompletionHandlerAdapter (org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter)11 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)9 Charset (java.nio.charset.Charset)8 HttpResponseHeaders (org.asynchttpclient.HttpResponseHeaders)6 HttpRequest (io.netty.handler.codec.http.HttpRequest)5 RequestInfo (com.nike.riposte.server.http.RequestInfo)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Map (java.util.Map)4 ByteBuf (io.netty.buffer.ByteBuf)3 Channel (io.netty.channel.Channel)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3