use of io.netty.handler.codec.http.HttpMethod in project janusgraph by JanusGraph.
the class HttpHMACAuthenticationHandler method channelRead.
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
if (msg instanceof FullHttpRequest) {
final FullHttpRequest req = (FullHttpRequest) msg;
final HttpMethod method = req.getMethod();
final Map<String, String> credentialsMap = getCredentialsMap(ctx, req);
if (credentialsMap == null) {
sendError(ctx, msg);
return;
}
if ("/session".equals(req.getUri()) && method.equals(HttpMethod.GET)) {
try {
credentialsMap.put(PROPERTY_GENERATE_TOKEN, "true");
authenticator.authenticate(credentialsMap);
} catch (Exception e) {
sendError(ctx, msg);
return;
}
replyWithToken(ctx, msg, credentialsMap.get(PROPERTY_TOKEN));
} else {
try {
authenticator.authenticate(credentialsMap);
ctx.fireChannelRead(req);
} catch (Exception e) {
sendError(ctx, msg);
}
}
}
}
use of io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class StreamingAsyncHttpClient method getFallbackSpanName.
@NotNull
protected String getFallbackSpanName(@NotNull HttpRequest downstreamRequest) {
try {
HttpMethod method = downstreamRequest.method();
String methodName = (method == null) ? null : method.name();
return HttpRequestTracingUtils.getFallbackSpanNameForHttpRequest("async_downstream_call", methodName);
} catch (Throwable t) {
logger.error("An unexpected error occurred while trying to extract fallback span name from Netty HttpRequest. " + "A hardcoded fallback name will be used as a last resort, however this error should be investigated " + "as it shouldn't be possible.", t);
return "async_downstream_call-UNKNOWN_HTTP_METHOD";
}
}
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);
}
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);
});
}
use of io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class EndpointMetricsHandlerDefaultImplTest method handleRequest_works_as_expected_for_request_that_hit_an_endpoint.
@DataProvider(value = { "GET | 99", "GET | 142", "GET | 242", "GET | 342", "GET | 404", "GET | 405", "GET | 442", "GET | 500", "GET | 542", "GET | 600", "POST | 99", "POST | 142", "POST | 242", "POST | 342", "POST | 404", "POST | 405", "POST | 442", "POST | 500", "POST | 542", "POST | 600", "PUT | 99", "PUT | 142", "PUT | 242", "PUT | 342", "PUT | 404", "PUT | 405", "PUT | 442", "PUT | 500", "PUT | 542", "PUT | 600", "DELETE | 99", "DELETE | 142", "DELETE | 242", "DELETE | 342", "DELETE | 404", "DELETE | 405", "DELETE | 442", "DELETE | 500", "DELETE | 542", "DELETE | 600", "PATCH | 99", "PATCH | 142", "PATCH | 242", "PATCH | 342", "PATCH | 404", "PATCH | 405", "PATCH | 442", "PATCH | 500", "PATCH | 542", "PATCH | 600", "null | 99", "null | 142", "null | 242", "null | 342", "null | 404", "null | 405", "null | 442", "null | 500", "null | 542", "null | 600" }, splitBy = "\\|")
@Test
public void handleRequest_works_as_expected_for_request_that_hit_an_endpoint(String requestMethodStr, int responseStatusCode) throws InterruptedException {
// given
HttpMethod requestMethod = (requestMethodStr == null) ? null : HttpMethod.valueOf(requestMethodStr);
doReturn(requestMethod).when(requestInfoMock).getMethod();
Endpoint<?> endpoint = serverConfig.appEndpoints().iterator().next();
String matchingPathTemplate = "/" + UUID.randomUUID().toString();
state.setEndpointForExecution(endpoint, matchingPathTemplate);
String endpointTimerAndMeterKey = instance.getTimerAndMeterMapKeyForEndpoint(endpoint);
int responseHttpStatusCodeXXValue = responseStatusCode / 100;
long elapsedTimeMillis = 42;
// when
instance.handleRequest(requestInfoMock, responseInfoMock, state, responseStatusCode, responseHttpStatusCodeXXValue, elapsedTimeMillis);
// then
// The all-requests timer should be updated with the elapsed time of the request
verify(instance.requests).update(elapsedTimeMillis, TimeUnit.MILLISECONDS);
// The timer for the relevant HTTP method for this request should be updated with the elapsed time of the request
verify(expectedRequestTimer(requestMethod, instance)).update(elapsedTimeMillis, TimeUnit.MILLISECONDS);
{
// The timer for the endpoint for this request should be updated with the elapsed time of the request
Timer expectedEndpointTimerUsed = instance.endpointRequestsTimers.get(endpointTimerAndMeterKey);
assertThat(expectedEndpointTimerUsed).isNotNull();
verify(expectedEndpointTimerUsed).update(elapsedTimeMillis, TimeUnit.MILLISECONDS);
}
final int httpStatusCodeXXValue = responseStatusCode / 100;
if (httpStatusCodeXXValue >= 1 && httpStatusCodeXXValue <= 5) {
// Inside the normal 1xx-5xx response codes.
// The correct 1xx, 2xx, 3xx, 4xx, or 5xx meter for all requests should be marked.
verify(instance.responses[httpStatusCodeXXValue - 1]).mark();
// The correct 1xx, 2xx, 3xx, 4xx, or 5xx meter for this request's endpoint should be marked.
Meter[] endpointResponseMeterArray = instance.endpointResponsesMeters.get(endpointTimerAndMeterKey);
assertThat(endpointResponseMeterArray).isNotNull();
verify(endpointResponseMeterArray[httpStatusCodeXXValue - 1]).mark();
} else {
// Outside the normal 1xx-5xx response codes, so none of the response meters should have been modified.
instance.endpointResponsesMeters.values().forEach(meterArray -> Stream.of(meterArray).forEach(Mockito::verifyNoInteractions));
}
}
Aggregations