Search in sources :

Example 1 with WebServiceHandler

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);
}
Also used : StaticBodyHttpHandler(com.hotels.styx.common.http.handler.StaticBodyHttpHandler) IndexHandler(com.hotels.styx.admin.handlers.IndexHandler) HttpAggregator(com.hotels.styx.common.http.handler.HttpAggregator) WebServiceHandler(com.hotels.styx.api.WebServiceHandler)

Example 2 with WebServiceHandler

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"));
}
Also used : Eventual(com.hotels.styx.api.Eventual) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HttpResponse.response(com.hotels.styx.api.HttpResponse.response) Mono(reactor.core.publisher.Mono) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) Support.requestContext(com.hotels.styx.support.Support.requestContext) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) ByteStream(com.hotels.styx.api.ByteStream) WebServiceHandler(com.hotels.styx.api.WebServiceHandler) OK(com.hotels.styx.api.HttpResponseStatus.OK) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) WebServiceHandler(com.hotels.styx.api.WebServiceHandler) Test(org.junit.jupiter.api.Test)

Example 3 with WebServiceHandler

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));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) WebServiceHandler(com.hotels.styx.api.WebServiceHandler) Test(org.junit.jupiter.api.Test)

Example 4 with WebServiceHandler

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));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) Support.requestContext(com.hotels.styx.support.Support.requestContext) WebServiceHandler(com.hotels.styx.api.WebServiceHandler) Test(org.junit.jupiter.api.Test)

Aggregations

WebServiceHandler (com.hotels.styx.api.WebServiceHandler)4 Test (org.junit.jupiter.api.Test)3 HttpRequest (com.hotels.styx.api.HttpRequest)2 Support.requestContext (com.hotels.styx.support.Support.requestContext)2 IndexHandler (com.hotels.styx.admin.handlers.IndexHandler)1 ByteStream (com.hotels.styx.api.ByteStream)1 Eventual (com.hotels.styx.api.Eventual)1 HttpResponse (com.hotels.styx.api.HttpResponse)1 HttpResponse.response (com.hotels.styx.api.HttpResponse.response)1 OK (com.hotels.styx.api.HttpResponseStatus.OK)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 HttpAggregator (com.hotels.styx.common.http.handler.HttpAggregator)1 StaticBodyHttpHandler (com.hotels.styx.common.http.handler.StaticBodyHttpHandler)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.is (org.hamcrest.Matchers.is)1 Mono (reactor.core.publisher.Mono)1