Search in sources :

Example 1 with HttpInterceptorPipeline

use of com.hotels.styx.routing.handlers.HttpInterceptorPipeline 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

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 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 HttpClient (com.hotels.styx.client.HttpClient)1 StyxHttpClient (com.hotels.styx.client.StyxHttpClient)1 StyxFutures.await (com.hotels.styx.common.StyxFutures.await)1 HttpAggregator (com.hotels.styx.common.http.handler.HttpAggregator)1 HttpInterceptorPipeline (com.hotels.styx.routing.handlers.HttpInterceptorPipeline)1 HttpConnectorConfig (com.hotels.styx.server.HttpConnectorConfig)1 StandardHttpRouter (com.hotels.styx.server.StandardHttpRouter)1 NettyServerBuilder (com.hotels.styx.server.netty.NettyServerBuilder)1 NettyServerBuilder.newBuilder (com.hotels.styx.server.netty.NettyServerBuilder.newBuilder)1 ServerConnector (com.hotels.styx.server.netty.ServerConnector)1