Search in sources :

Example 1 with HttpAggregator

use of com.hotels.styx.common.http.handler.HttpAggregator 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 HttpAggregator

use of com.hotels.styx.common.http.handler.HttpAggregator in project styx by ExpediaGroup.

the class StyxProxyTest method startsServerWithHttpConnector.

@Test
public void startsServerWithHttpConnector() {
    HttpInterceptor echoInterceptor = (request, chain) -> textResponse("Response from http connector");
    StandardHttpRouter handler = new StandardHttpRouter();
    InetServer styxServer = newBuilder().setProtocolConnector(connector(0)).bossExecutor(NettyExecutor.create("Test-Server-Boss", 1)).workerExecutor(NettyExecutor.create("Test-Server-Worker", 0)).handler(new HttpInterceptorPipeline(List.of(echoInterceptor), (request, context) -> new HttpAggregator(new StandardHttpRouter()).handle(request, context), false)).build();
    Service server = StyxServers.toGuavaService(styxServer);
    server.startAsync().awaitRunning();
    assertThat("Server should be running", server.isRunning());
    HttpResponse secureResponse = get("http://localhost:" + styxServer.inetAddress().getPort());
    assertThat(secureResponse.bodyAs(UTF_8), containsString("Response from http connector"));
    server.stopAsync().awaitTerminated();
    assertThat("Server should not be running", !server.isRunning());
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) LoggerFactory(org.slf4j.LoggerFactory) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) StyxHttpClient(com.hotels.styx.client.StyxHttpClient) HttpClient(com.hotels.styx.client.HttpClient) Disabled(org.junit.jupiter.api.Disabled) HttpConnectorConfig(com.hotels.styx.server.HttpConnectorConfig) StyxServers(com.hotels.styx.StyxServers) WebServerConnectorFactory(com.hotels.styx.server.netty.WebServerConnectorFactory) NettyServerBuilder(com.hotels.styx.server.netty.NettyServerBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StandardHttpRouter(com.hotels.styx.server.StandardHttpRouter) Eventual(com.hotels.styx.api.Eventual) Logger(org.slf4j.Logger) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HttpAggregator(com.hotels.styx.common.http.handler.HttpAggregator) NettyServerBuilder.newBuilder(com.hotels.styx.server.netty.NettyServerBuilder.newBuilder) NettyExecutor(com.hotels.styx.NettyExecutor) IOException(java.io.IOException) HttpRequest(com.hotels.styx.api.HttpRequest) HttpInterceptorPipeline(com.hotels.styx.routing.handlers.HttpInterceptorPipeline) Service(com.google.common.util.concurrent.Service) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test) List(java.util.List) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) OK(com.hotels.styx.api.HttpResponseStatus.OK) InetServer(com.hotels.styx.InetServer) ServerConnector(com.hotels.styx.server.netty.ServerConnector) StandardHttpRouter(com.hotels.styx.server.StandardHttpRouter) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) HttpInterceptorPipeline(com.hotels.styx.routing.handlers.HttpInterceptorPipeline) Service(com.google.common.util.concurrent.Service) HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) HttpAggregator(com.hotels.styx.common.http.handler.HttpAggregator) InetServer(com.hotels.styx.InetServer) Test(org.junit.jupiter.api.Test)

Aggregations

HttpAggregator (com.hotels.styx.common.http.handler.HttpAggregator)2 Service (com.google.common.util.concurrent.Service)1 InetServer (com.hotels.styx.InetServer)1 NettyExecutor (com.hotels.styx.NettyExecutor)1 StyxServers (com.hotels.styx.StyxServers)1 IndexHandler (com.hotels.styx.admin.handlers.IndexHandler)1 Eventual (com.hotels.styx.api.Eventual)1 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)1 HttpRequest (com.hotels.styx.api.HttpRequest)1 HttpResponse (com.hotels.styx.api.HttpResponse)1 OK (com.hotels.styx.api.HttpResponseStatus.OK)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 WebServiceHandler (com.hotels.styx.api.WebServiceHandler)1 HttpClient (com.hotels.styx.client.HttpClient)1 StyxHttpClient (com.hotels.styx.client.StyxHttpClient)1 StyxFutures.await (com.hotels.styx.common.StyxFutures.await)1 StaticBodyHttpHandler (com.hotels.styx.common.http.handler.StaticBodyHttpHandler)1 HttpInterceptorPipeline (com.hotels.styx.routing.handlers.HttpInterceptorPipeline)1 HttpConnectorConfig (com.hotels.styx.server.HttpConnectorConfig)1 StandardHttpRouter (com.hotels.styx.server.StandardHttpRouter)1