Search in sources :

Example 21 with HttpHandler

use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.

the class RouteHandlerAdapterTest method injectsToPipelineWhenRouteFound.

@Test
public void injectsToPipelineWhenRouteFound() {
    HttpHandler pipeline = mock(HttpHandler.class);
    when(pipeline.handle(any(LiveHttpRequest.class), any(HttpInterceptor.Context.class))).thenReturn(Eventual.of(respOk));
    HttpRouter router = mock(HttpRouter.class);
    when(router.route(any(LiveHttpRequest.class), any(HttpInterceptor.Context.class))).thenReturn(Optional.of(pipeline));
    LiveHttpResponse response = Mono.from(new RouteHandlerAdapter(router).handle(request, requestContext())).block();
    assertThat(response.status(), is(OK));
}
Also used : Support.requestContext(com.hotels.styx.support.Support.requestContext) HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) HttpRouter(com.hotels.styx.server.HttpRouter) Test(org.junit.jupiter.api.Test)

Example 22 with HttpHandler

use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.

the class StyxServer method httpServer.

private InetServer httpServer(StyxServerComponents components, ConnectorConfig connectorConfig, HttpHandler styxDataPlane) {
    Environment environment = components.environment();
    CharSequence styxInfoHeaderName = environment.configuration().styxHeaderConfig().styxInfoHeaderName();
    ResponseInfoFormat responseInfoFormat = new ResponseInfoFormat(environment);
    ServerConnector proxyConnector = new ProxyConnectorFactory(environment.configuration().proxyServerConfig(), environment.centralisedMetrics(), environment.errorListener(), environment.configuration().get(ENCODE_UNWISECHARS).orElse(""), (builder, request) -> builder.header(styxInfoHeaderName, responseInfoFormat.format(request)), environment.configuration().get("requestTracking", Boolean.class).orElse(false), environment.httpMessageFormatter(), environment.configuration().styxHeaderConfig().originIdHeaderName()).create(connectorConfig);
    return NettyServerBuilder.newBuilder().setMetricsRegistry(environment.metricRegistry()).bossExecutor(proxyBossExecutor).workerExecutor(proxyWorkerExecutor).setProtocolConnector(proxyConnector).handler(styxDataPlane).build();
}
Also used : ServerConnector(com.hotels.styx.server.netty.ServerConnector) DISABLED(io.netty.util.ResourceLeakDetector.Level.DISABLED) LOGBackConfigurer.shutdownLogging(com.hotels.styx.infrastructure.logging.LOGBackConfigurer.shutdownLogging) Registry(com.hotels.styx.api.extension.service.spi.Registry) ServiceManager(com.google.common.util.concurrent.ServiceManager) Stopwatch(com.hotels.styx.javaconvenience.Stopwatch) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) ENCODE_UNWISECHARS(com.hotels.styx.proxy.encoders.ConfigurableUnwiseCharsEncoder.ENCODE_UNWISECHARS) ConnectorConfig(com.hotels.styx.server.ConnectorConfig) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) ArrayList(java.util.ArrayList) StyxServers.toGuavaService(com.hotels.styx.StyxServers.toGuavaService) CharStreams(com.google.common.io.CharStreams) SchemaValidationException(com.hotels.styx.config.schema.SchemaValidationException) AbstractService(com.google.common.util.concurrent.AbstractService) BackendService(com.hotels.styx.api.extension.service.BackendService) System.getProperty(java.lang.System.getProperty) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) NettyServerBuilder(com.hotels.styx.server.netty.NettyServerBuilder) AbstractStyxService(com.hotels.styx.api.extension.service.spi.AbstractStyxService) Logger(org.slf4j.Logger) HttpHandler(com.hotels.styx.api.HttpHandler) StyxServerComponents(com.hotels.styx.startup.StyxServerComponents) IOException(java.io.IOException) Reader(java.io.Reader) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ResourceLeakDetector(io.netty.util.ResourceLeakDetector) CoreMetricsKt.registerCoreMetrics(com.hotels.styx.startup.CoreMetricsKt.registerCoreMetrics) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) InputStreamReader(java.io.InputStreamReader) InetSocketAddress(java.net.InetSocketAddress) String.format(java.lang.String.format) Service(com.google.common.util.concurrent.Service) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Resource(com.hotels.styx.api.Resource) Paths(java.nio.file.Paths) MeterRegistry(com.hotels.styx.api.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) LOGBackConfigurer.initLogging(com.hotels.styx.infrastructure.logging.LOGBackConfigurer.initLogging) BufferedReader(java.io.BufferedReader) Runtime.getRuntime(java.lang.Runtime.getRuntime) NotNull(org.jetbrains.annotations.NotNull) AdminServerBuilder(com.hotels.styx.admin.AdminServerBuilder) ServerConnector(com.hotels.styx.server.netty.ServerConnector) PrometheusConfig(io.micrometer.prometheus.PrometheusConfig)

Example 23 with HttpHandler

use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.

the class StaticPipelineBuilderTest method buildsInterceptorPipelineForBackendServices.

@Test
public void buildsInterceptorPipelineForBackendServices() throws Exception {
    HttpHandler handler = new StaticPipelineFactory(clientFactory, environment, registry, List.of(), executor, false).build();
    LiveHttpResponse response = Mono.from(handler.handle(get("/foo").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
}
Also used : HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HttpHandler (com.hotels.styx.api.HttpHandler)23 Test (org.junit.jupiter.api.Test)20 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)13 MeterRegistry (com.hotels.styx.api.MeterRegistry)11 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)11 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)10 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)9 Eventual (com.hotels.styx.api.Eventual)8 BackendService (com.hotels.styx.api.extension.service.BackendService)8 Registry (com.hotels.styx.api.extension.service.spi.Registry)8 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)7 OK (com.hotels.styx.api.HttpResponseStatus.OK)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 Mono (reactor.core.publisher.Mono)6 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)5 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)5 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)5 Support.requestContext (com.hotels.styx.support.Support.requestContext)5 Arrays.asList (java.util.Arrays.asList)5 Matchers.is (org.hamcrest.Matchers.is)5