use of com.hotels.styx.api.WebServiceHandler in project styx by ExpediaGroup.
the class AdminServerBuilder method extensionEndpoints.
private static List<Route> extensionEndpoints(String root, String name, Map<String, HttpHandler> endpoints) {
List<AdminEndpointRoute> routes = extensionAdminEndpointRoutes(root, name, endpoints);
List<IndexHandler.Link> endpointLinks = routes.stream().map(AdminEndpointRoute::link).collect(toList());
WebServiceHandler handler = endpointLinks.isEmpty() ? new StaticBodyHttpHandler(HTML, format("This plugin (%s) does not expose any admin interfaces", name)) : new IndexHandler(endpointLinks);
Route indexRoute = new Route(adminPath(root, name), new HttpAggregator(MEGABYTE, handler));
return concatenate(indexRoute, routes);
}
use of com.hotels.styx.api.WebServiceHandler in project styx by ExpediaGroup.
the class HttpAggregatorTest method aggregatesRequestAndStreamsResponses.
@Test
public void aggregatesRequestAndStreamsResponses() {
AtomicReference<String> result = new AtomicReference<>();
WebServiceHandler webServiceHandler = (request, ctx) -> {
result.set(request.bodyAs(UTF_8));
return Eventual.of(response(OK).body("abcdef", UTF_8).build());
};
LiveHttpResponse response = Mono.from(new HttpAggregator(500, webServiceHandler).handle(LiveHttpRequest.post("/").body(ByteStream.from("ABCDEF", UTF_8)).build(), requestContext())).block();
assertThat(result.get(), is("ABCDEF"));
assertThat(Mono.from(response.aggregate(500)).block().bodyAs(UTF_8), is("abcdef"));
}
use of com.hotels.styx.api.WebServiceHandler in project styx by ExpediaGroup.
the class HttpMethodFilteringHandlerTest method failsIfRequestMethodIsNotSupported.
@Test
public void failsIfRequestMethodIsNotSupported() throws Exception {
WebServiceHandler handler = mock(WebServiceHandler.class);
HttpMethodFilteringHandler post = new HttpMethodFilteringHandler(GET, handler);
HttpRequest request = post("/some-uri").build();
HttpResponse response = Mono.from(post.handle(request, requestContext())).block();
assertThat(response.status(), is(METHOD_NOT_ALLOWED));
}
use of com.hotels.styx.api.WebServiceHandler in project styx by ExpediaGroup.
the class HttpMethodFilteringHandlerTest method delegatesTheRequestIfRequestMethodIsSupported.
@Test
public void delegatesTheRequestIfRequestMethodIsSupported() {
WebServiceHandler handler = mock(WebServiceHandler.class);
HttpMethodFilteringHandler post = new HttpMethodFilteringHandler(POST, handler);
HttpRequest request = post("/some-uri").build();
post.handle(request, mock(HttpInterceptor.Context.class));
verify(handler).handle(eq(request), any(HttpInterceptor.Context.class));
}
Aggregations