use of com.hotels.styx.api.HttpResponseStatus.NOT_FOUND in project styx by ExpediaGroup.
the class UrlPatternRouter method handle.
@Override
public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) {
for (RouteDescriptor route : alternatives) {
if (request.method().equals(route.method())) {
Matcher match = route.uriPattern().matcher(request.path());
LOGGER.debug("Request path '{}' matching against route pattern '{}' matches: {}", new Object[] { request.path(), route.uriPattern(), match.matches() });
if (match.matches()) {
Map<String, String> placeholders = route.placeholderNames().stream().collect(toMap(name -> name, match::group));
context.add(PLACEHOLDERS_KEY, placeholders);
try {
return route.handler().handle(request, context);
} catch (Exception cause) {
LOGGER.error("ERROR: {} {}", new Object[] { request.method(), request.path(), cause });
return Eventual.of(response(INTERNAL_SERVER_ERROR).build());
}
}
}
}
return Eventual.of(response(NOT_FOUND).build());
}
use of com.hotels.styx.api.HttpResponseStatus.NOT_FOUND in project styx by ExpediaGroup.
the class UrlRequestHealthCheckTest method declaresOriginUnhealthyOnNon200Ok.
@Test
public void declaresOriginUnhealthyOnNon200Ok() {
HttpClient client = request -> respondWith(NOT_FOUND);
new UrlRequestHealthCheck("/version.txt", metrics).check(client, someOrigin, state -> this.originState = state);
assertThat(originState, is(UNHEALTHY));
assertThat(metrics.getRegistry().find("proxy.client.originHealthCheckFailures").tags("originId", someOrigin.id().toString(), "appId", someOrigin.applicationId().toString()).counter().count(), is(1.0));
assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(1));
}
use of com.hotels.styx.api.HttpResponseStatus.NOT_FOUND in project styx by ExpediaGroup.
the class UrlRequestHealthCheckTest method sendsTheHealthCheckRequestToTheGivenUrl.
@Test
public void sendsTheHealthCheckRequestToTheGivenUrl() {
HttpClient client = request -> {
requestedUrl = request.url().path();
return respondWith(NOT_FOUND);
};
new UrlRequestHealthCheck("/version-foo.txt", metrics).check(client, someOrigin, state -> {
});
assertThat(requestedUrl, is("/version-foo.txt"));
}
Aggregations