Search in sources :

Example 36 with HttpMethod

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

the class SimpleProxyRouterEndpoint method getDownstreamRequestFirstChunkInfo.

@Override
@NotNull
public CompletableFuture<DownstreamRequestFirstChunkInfo> getDownstreamRequestFirstChunkInfo(@NotNull RequestInfo<?> request, @NotNull Executor longRunningTaskExecutor, @NotNull ChannelHandlerContext ctx) {
    HttpMethod method = request.getMethod();
    if (method == null) {
        CompletableFuture<DownstreamRequestFirstChunkInfo> errorResult = new CompletableFuture<>();
        errorResult.completeExceptionally(new IllegalArgumentException("Received a request with null request.getMethod(). This should never happen."));
        return errorResult;
    }
    return CompletableFuture.completedFuture(new DownstreamRequestFirstChunkInfo(downstreamDestinationHost, downstreamDestinationPort, isDownstreamCallHttps, generateSimplePassthroughRequest(request, HttpUtils.replaceUriPathVariables(request, downstreamDestinationUriPath), method, ctx), customCircuitBreaker, disableCircuitBreaker));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) HttpMethod(io.netty.handler.codec.http.HttpMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with HttpMethod

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

the class RequestInfoImpl method getMultipartParts.

/**
 * {@inheritDoc}
 */
@Override
@Nullable
public synchronized List<InterfaceHttpData> getMultipartParts() {
    if (!isMultipartRequest() || !isCompleteRequestWithAllChunks())
        return null;
    if (multipartData == null) {
        byte[] contentBytes = getRawContentBytes();
        HttpVersion httpVersion = getProtocolVersion();
        HttpMethod httpMethod = getMethod();
        // default them to something if null somehow slips through.
        if (httpVersion == null) {
            httpVersion = HttpVersion.HTTP_1_0;
        }
        if (httpMethod == null) {
            httpMethod = HttpMethod.POST;
        }
        HttpRequest fullHttpRequestForMultipartDecoder = (contentBytes == null) ? new DefaultFullHttpRequest(httpVersion, httpMethod, getUri()) : new DefaultFullHttpRequest(httpVersion, httpMethod, getUri(), Unpooled.wrappedBuffer(contentBytes));
        fullHttpRequestForMultipartDecoder.headers().add(getHeaders());
        multipartData = new HttpPostMultipartRequestDecoder(new DefaultHttpDataFactory(false), fullHttpRequestForMultipartDecoder, getContentCharset());
    }
    return multipartData.getBodyHttpDatas();
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpPostMultipartRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder) DefaultHttpDataFactory(io.netty.handler.codec.http.multipart.DefaultHttpDataFactory) HttpVersion(io.netty.handler.codec.http.HttpVersion) HttpMethod(io.netty.handler.codec.http.HttpMethod) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with HttpMethod

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

the class AsyncHttpClientHelperTest method getRequestBuilder_with_circuit_breaker_args_sets_values_as_expected.

@DataProvider(value = { "CONNECT", "DELETE", "GET", "HEAD", "POST", "OPTIONS", "PUT", "PATCH", "TRACE", "FOO_METHOD_DOES_NOT_EXIST" }, splitBy = "\\|")
@Test
public void getRequestBuilder_with_circuit_breaker_args_sets_values_as_expected(String methodName) {
    CircuitBreaker<Response> cbMock = mock(CircuitBreaker.class);
    List<Pair<Optional<CircuitBreaker<Response>>, Boolean>> variations = Arrays.asList(Pair.of(Optional.empty(), true), Pair.of(Optional.empty(), false), Pair.of(Optional.of(cbMock), true), Pair.of(Optional.of(cbMock), false));
    variations.forEach(variation -> {
        // given
        String url = "http://localhost/some/path";
        HttpMethod method = HttpMethod.valueOf(methodName);
        Optional<CircuitBreaker<Response>> cbOpt = variation.getLeft();
        boolean disableCb = variation.getRight();
        // when
        RequestBuilderWrapper rbw = helperSpy.getRequestBuilder(url, method, cbOpt, disableCb);
        // then
        verifyRequestBuilderWrapperGeneratedAsExpected(rbw, url, methodName, cbOpt, disableCb);
    });
}
Also used : Response(com.ning.http.client.Response) CircuitBreaker(com.nike.fastbreak.CircuitBreaker) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HttpMethod(io.netty.handler.codec.http.HttpMethod) Pair(com.nike.internal.util.Pair) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 39 with HttpMethod

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

the class AsyncHttpClientHelperTest method getRequestBuilder_delegates_to_helper_with_default_circuit_breaker_args.

@Test
public void getRequestBuilder_delegates_to_helper_with_default_circuit_breaker_args() {
    // given
    String url = UUID.randomUUID().toString();
    HttpMethod method = HttpMethod.valueOf(UUID.randomUUID().toString());
    RequestBuilderWrapper rbwMock = mock(RequestBuilderWrapper.class);
    doReturn(rbwMock).when(helperSpy).getRequestBuilder(anyString(), any(HttpMethod.class), any(Optional.class), anyBoolean());
    // when
    RequestBuilderWrapper rbw = helperSpy.getRequestBuilder(url, method);
    // then
    verify(helperSpy).getRequestBuilder(url, method, Optional.empty(), false);
    assertThat(rbw).isSameAs(rbwMock);
}
Also used : Optional(java.util.Optional) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 40 with HttpMethod

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

the class SignalFxEndpointMetricsHandlerTest method handleRequest_gracefully_handles_some_null_args.

@DataProvider(value = { "true   |   false   |   false", "false  |   true    |   false", "false  |   false   |   true", "true   |   true    |   true" }, splitBy = "\\|")
@Test
public void handleRequest_gracefully_handles_some_null_args(boolean endpointIsNull, boolean methodIsNull, boolean matchingPathTemplateIsNull) {
    // given
    int statusCode = 242;
    int statusCodeXXValue = 2;
    long elapsedTimeMillis = 42;
    Endpoint endpoint = (endpointIsNull) ? null : endpointMock;
    doReturn(endpoint).when(httpStateMock).getEndpointForExecution();
    String expectedEndpointClass = (endpointIsNull) ? "NONE" : endpoint.getClass().getName();
    HttpMethod method = (methodIsNull) ? null : httpMethod;
    doReturn(method).when(requestInfoMock).getMethod();
    String expectedMethodName = (methodIsNull) ? "NONE" : method.name();
    String pathTemplate = (matchingPathTemplateIsNull) ? null : matchingPathTemplate;
    doReturn(pathTemplate).when(httpStateMock).getMatchingPathTemplate();
    String expectedPathTemplate = (matchingPathTemplateIsNull) ? "NONE" : pathTemplate;
    // when
    handler.handleRequest(requestInfoMock, responseInfoMock, httpStateMock, statusCode, statusCodeXXValue, elapsedTimeMillis);
    // then
    verify(metricMetadataMock).forBuilder(requestTimerBuilderMock);
    verify(dimensionConfiguratorMock).setupMetricWithDimensions(timerBuilderTaggerMock, requestInfoMock, responseInfoMock, httpStateMock, statusCode, statusCodeXXValue, elapsedTimeMillis, endpoint, expectedEndpointClass, expectedMethodName, expectedPathTemplate);
    verify(timerBuilderTaggerMock).createOrGet(metricRegistryMock);
    verify(timerMock).update(elapsedTimeMillis, TimeUnit.MILLISECONDS);
}
Also used : Endpoint(com.nike.riposte.server.http.Endpoint) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Endpoint(com.nike.riposte.server.http.Endpoint) HttpMethod(io.netty.handler.codec.http.HttpMethod) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

HttpMethod (io.netty.handler.codec.http.HttpMethod)95 Test (org.junit.Test)51 HttpRequest (io.netty.handler.codec.http.HttpRequest)28 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)25 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)21 URI (java.net.URI)15 IOException (java.io.IOException)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)11 HttpVersion (io.netty.handler.codec.http.HttpVersion)11 DefaultHttpClient (org.jocean.http.client.impl.DefaultHttpClient)11 TestChannelCreator (org.jocean.http.client.impl.TestChannelCreator)11 TestChannelPool (org.jocean.http.client.impl.TestChannelPool)11 DefaultSignalClient (org.jocean.http.rosa.impl.DefaultSignalClient)11 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)11 Subscription (rx.Subscription)11 Action2 (rx.functions.Action2)11 ByteBuf (io.netty.buffer.ByteBuf)10 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)10 Map (java.util.Map)9