Search in sources :

Example 31 with HttpObject

use of io.netty.handler.codec.http.HttpObject in project cxf by apache.

the class NettyHttpClientHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof HttpObject) {
        if (msg instanceof HttpResponse) {
            // just make sure we can combine the request and response together
            HttpResponse response = (HttpResponse) msg;
            NettyHttpClientRequest request = sendedQueue.poll();
            request.setResponse(response);
            // calling the callback here
            request.getCxfResponseCallback().responseReceived(response);
        }
        if (msg instanceof LastHttpContent) {
            ctx.close();
        }
    } else {
        super.channelRead(ctx, msg);
    }
}
Also used : HttpObject(io.netty.handler.codec.http.HttpObject) HttpResponse(io.netty.handler.codec.http.HttpResponse) LastHttpContent(io.netty.handler.codec.http.LastHttpContent)

Example 32 with HttpObject

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

the class RiposteHandlerInternalUtilTest method getDecoderFailure_returns_DecoderResult_cause_when_it_is_a_failure.

@Test
public void getDecoderFailure_returns_DecoderResult_cause_when_it_is_a_failure() {
    // given
    HttpObject httpObjectMock = mock(HttpObject.class);
    Throwable expectedResult = mock(Throwable.class);
    doReturn(DecoderResult.failure(expectedResult)).when(httpObjectMock).decoderResult();
    // when
    Throwable result = implSpy.getDecoderFailure(httpObjectMock);
    // then
    assertThat(result).isEqualTo(expectedResult);
}
Also used : HttpObject(io.netty.handler.codec.http.HttpObject) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 33 with HttpObject

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

the class RoutingHandlerTest method doChannelRead_does_nothing_if_msg_is_not_HttpRequest.

@Test
public void doChannelRead_does_nothing_if_msg_is_not_HttpRequest() {
    // given
    String pathTemplate = "/some/path/with/{id}";
    Collection<String> pathTemplates = new ArrayList<String>() {

        {
            add(pathTemplate);
        }
    };
    doReturn(pathTemplates).when(matcherMock).matchingPathTemplates();
    HttpObject msg = mock(HttpObject.class);
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    verify(handlerSpy).doChannelRead(ctxMock, msg);
    verifyNoMoreInteractions(handlerSpy);
    verifyNoMoreInteractions(requestInfoMock);
    verifyNoMoreInteractions(stateMock);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) HttpObject(io.netty.handler.codec.http.HttpObject) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 34 with HttpObject

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

the class RiposteHandlerInternalUtilTest method getDecoderFailure_returns_null_when_DecoderResult_is_null.

@Test
public void getDecoderFailure_returns_null_when_DecoderResult_is_null() {
    // given
    HttpObject httpObjectMock = mock(HttpObject.class);
    doReturn(null).when(httpObjectMock).decoderResult();
    // when
    Throwable result = implSpy.getDecoderFailure(httpObjectMock);
    // then
    assertThat(result).isNull();
}
Also used : HttpObject(io.netty.handler.codec.http.HttpObject) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 35 with HttpObject

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

the class RiposteHandlerInternalUtilTest method getDecoderFailure_returns_null_when_DecoderResult_is_not_a_failure.

@DataProvider(value = { "true", "false" })
@Test
public void getDecoderFailure_returns_null_when_DecoderResult_is_not_a_failure(boolean isUnfinished) {
    // given
    HttpObject httpObjectMock = mock(HttpObject.class);
    DecoderResult nonFailureDecoderResult = (isUnfinished) ? DecoderResult.UNFINISHED : DecoderResult.SUCCESS;
    doReturn(nonFailureDecoderResult).when(httpObjectMock).decoderResult();
    // when
    Throwable result = implSpy.getDecoderFailure(httpObjectMock);
    // then
    assertThat(result).isNull();
}
Also used : HttpObject(io.netty.handler.codec.http.HttpObject) DecoderResult(io.netty.handler.codec.DecoderResult) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Test(org.junit.Test)

Aggregations

HttpObject (io.netty.handler.codec.http.HttpObject)66 Test (org.junit.Test)38 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)31 HttpContent (io.netty.handler.codec.http.HttpContent)29 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)27 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)25 ArrayList (java.util.ArrayList)19 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)16 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)14 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)14 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)14 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)9 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)9 HttpResponse (io.netty.handler.codec.http.HttpResponse)9 Subscription (rx.Subscription)9 Nettys4Test (org.jocean.http.util.Nettys4Test)8 TestSubscriber (rx.observers.TestSubscriber)8 HttpRequest (io.netty.handler.codec.http.HttpRequest)7 DisposableWrapper (org.jocean.idiom.DisposableWrapper)7 Channel (io.netty.channel.Channel)6