Search in sources :

Example 1 with RequestHandler

use of com.github.tomakehurst.wiremock.http.RequestHandler in project styx by ExpediaGroup.

the class MockOriginServer method newHandler.

private static HttpHandler newHandler(RequestHandler wireMockHandler) {
    return (httpRequest, ctx) -> httpRequest.aggregate(MAX_CONTENT_LENGTH).map(fullRequest -> {
        LOGGER.info("Received: {}\n{}", new Object[] { fullRequest.url(), fullRequest.body() });
        return fullRequest;
    }).flatMap(fullRequest -> {
        Request wmRequest = new WiremockStyxRequestAdapter(fullRequest);
        com.github.tomakehurst.wiremock.http.Response wmResponse = wireMockHandler.handle(wmRequest);
        return Eventual.of(toStyxResponse(wmResponse).stream());
    });
}
Also used : UrlMatchingStrategy(com.github.tomakehurst.wiremock.client.UrlMatchingStrategy) RequestHandler(com.github.tomakehurst.wiremock.http.RequestHandler) FILES_ROOT(com.github.tomakehurst.wiremock.WireMockServer.FILES_ROOT) ServiceManager(com.google.common.util.concurrent.ServiceManager) WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) LoggerFactory(org.slf4j.LoggerFactory) StubRequestHandler(com.github.tomakehurst.wiremock.http.StubRequestHandler) Optional.absent(com.google.common.base.Optional.absent) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) AdminRequestHandler(com.github.tomakehurst.wiremock.http.AdminRequestHandler) HttpConnectorConfig(com.hotels.styx.server.HttpConnectorConfig) WireMock(com.github.tomakehurst.wiremock.client.WireMock) NotImplementedRequestDelayControl(com.github.tomakehurst.wiremock.global.NotImplementedRequestDelayControl) Unpooled(io.netty.buffer.Unpooled) StyxServers(com.hotels.styx.StyxServers) ByteBuf(io.netty.buffer.ByteBuf) BasicResponseRenderer(com.github.tomakehurst.wiremock.http.BasicResponseRenderer) WireMockApp(com.github.tomakehurst.wiremock.core.WireMockApp) Request(com.github.tomakehurst.wiremock.http.Request) WireMock.configureFor(com.github.tomakehurst.wiremock.client.WireMock.configureFor) Collections.emptyMap(java.util.Collections.emptyMap) Eventual(com.hotels.styx.api.Eventual) Logger(org.slf4j.Logger) WiremockResponseConverter.toStyxResponse(com.hotels.styx.servers.WiremockResponseConverter.toStyxResponse) RequestPatternBuilder(com.github.tomakehurst.wiremock.client.RequestPatternBuilder) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) HttpHandler(com.hotels.styx.api.HttpHandler) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HttpsConnectorConfig(com.hotels.styx.server.HttpsConnectorConfig) HttpServers(com.hotels.styx.server.HttpServers) List(java.util.List) StubResponseRenderer(com.github.tomakehurst.wiremock.http.StubResponseRenderer) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) InetServer(com.hotels.styx.InetServer) ProxyResponseRenderer(com.github.tomakehurst.wiremock.http.ProxyResponseRenderer) Request(com.github.tomakehurst.wiremock.http.Request)

Example 2 with RequestHandler

use of com.github.tomakehurst.wiremock.http.RequestHandler in project styx by ExpediaGroup.

the class MockOriginServer method newHandler.

private static HttpHandler newHandler(String originId, RequestHandler wireMockHandler) {
    return (httpRequest, ctx) -> httpRequest.aggregate(MAX_CONTENT_LENGTH).map(fullRequest -> {
        LOGGER.info("{} received: {}\n{}", new Object[] { originId, fullRequest.url(), fullRequest.body() });
        return fullRequest;
    }).flatMap(fullRequest -> {
        Request wmRequest = new WiremockStyxRequestAdapter(fullRequest);
        com.github.tomakehurst.wiremock.http.Response wmResponse = wireMockHandler.handle(wmRequest);
        return Eventual.of(toStyxResponse(wmResponse).stream());
    });
}
Also used : UrlMatchingStrategy(com.github.tomakehurst.wiremock.client.UrlMatchingStrategy) RequestHandler(com.github.tomakehurst.wiremock.http.RequestHandler) FILES_ROOT(com.github.tomakehurst.wiremock.WireMockServer.FILES_ROOT) ServiceManager(com.google.common.util.concurrent.ServiceManager) WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) LoggerFactory(org.slf4j.LoggerFactory) StubRequestHandler(com.github.tomakehurst.wiremock.http.StubRequestHandler) Optional.absent(com.google.common.base.Optional.absent) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) AdminRequestHandler(com.github.tomakehurst.wiremock.http.AdminRequestHandler) HttpConnectorConfig(com.hotels.styx.server.HttpConnectorConfig) WireMock(com.github.tomakehurst.wiremock.client.WireMock) NotImplementedRequestDelayControl(com.github.tomakehurst.wiremock.global.NotImplementedRequestDelayControl) Unpooled(io.netty.buffer.Unpooled) StyxServers(com.hotels.styx.StyxServers) ByteBuf(io.netty.buffer.ByteBuf) BasicResponseRenderer(com.github.tomakehurst.wiremock.http.BasicResponseRenderer) WireMockApp(com.github.tomakehurst.wiremock.core.WireMockApp) Request(com.github.tomakehurst.wiremock.http.Request) WireMock.configureFor(com.github.tomakehurst.wiremock.client.WireMock.configureFor) Collections.emptyMap(java.util.Collections.emptyMap) Eventual(com.hotels.styx.api.Eventual) Logger(org.slf4j.Logger) WiremockResponseConverter.toStyxResponse(com.hotels.styx.servers.WiremockResponseConverter.toStyxResponse) RequestPatternBuilder(com.github.tomakehurst.wiremock.client.RequestPatternBuilder) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) HttpHandler(com.hotels.styx.api.HttpHandler) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HttpsConnectorConfig(com.hotels.styx.server.HttpsConnectorConfig) HttpServers(com.hotels.styx.server.HttpServers) List(java.util.List) StubResponseRenderer(com.github.tomakehurst.wiremock.http.StubResponseRenderer) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) InetServer(com.hotels.styx.InetServer) ProxyResponseRenderer(com.github.tomakehurst.wiremock.http.ProxyResponseRenderer) Request(com.github.tomakehurst.wiremock.http.Request)

Aggregations

FILES_ROOT (com.github.tomakehurst.wiremock.WireMockServer.FILES_ROOT)2 MappingBuilder (com.github.tomakehurst.wiremock.client.MappingBuilder)2 RequestPatternBuilder (com.github.tomakehurst.wiremock.client.RequestPatternBuilder)2 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 UrlMatchingStrategy (com.github.tomakehurst.wiremock.client.UrlMatchingStrategy)2 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 WireMock.configureFor (com.github.tomakehurst.wiremock.client.WireMock.configureFor)2 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)2 WireMockApp (com.github.tomakehurst.wiremock.core.WireMockApp)2 WireMockConfiguration (com.github.tomakehurst.wiremock.core.WireMockConfiguration)2 NotImplementedRequestDelayControl (com.github.tomakehurst.wiremock.global.NotImplementedRequestDelayControl)2 AdminRequestHandler (com.github.tomakehurst.wiremock.http.AdminRequestHandler)2 BasicResponseRenderer (com.github.tomakehurst.wiremock.http.BasicResponseRenderer)2 ProxyResponseRenderer (com.github.tomakehurst.wiremock.http.ProxyResponseRenderer)2 Request (com.github.tomakehurst.wiremock.http.Request)2 RequestHandler (com.github.tomakehurst.wiremock.http.RequestHandler)2 StubRequestHandler (com.github.tomakehurst.wiremock.http.StubRequestHandler)2 StubResponseRenderer (com.github.tomakehurst.wiremock.http.StubResponseRenderer)2 Optional.absent (com.google.common.base.Optional.absent)2 ServiceManager (com.google.common.util.concurrent.ServiceManager)2