use of com.hotels.styx.api.HttpHandler 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());
});
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class BackendServicesRouterTest method removesExistingServicesBeforeAddingNewOnes.
@Test
public void removesExistingServicesBeforeAddingNewOnes() throws Exception {
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(added(appB()));
router.onChange(new Registry.Changes.Builder<BackendService>().added(newBackendServiceBuilder(appB()).id("X").build()).removed(appB()).build());
LiveHttpRequest request = get("/appB/").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue("X"));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class BackendServicesRouterTest method selectsUsingPathWithNoSubsequentCharacters.
@Test
public void selectsUsingPathWithNoSubsequentCharacters() throws Exception {
Registry.Changes<BackendService> changes = added(appA().newCopy().path("/").build(), appB().newCopy().path("/appB/").build());
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(changes);
LiveHttpRequest request = get("/appB/").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_B));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class BackendServicesRouterTest method selectsApplicationBasedOnPathIfAppsAreProvidedInOppositeOrder.
@Test
public void selectsApplicationBasedOnPathIfAppsAreProvidedInOppositeOrder() throws Exception {
Registry.Changes<BackendService> changes = added(appB().newCopy().path("/appB/hotel/details.html").build(), appA().newCopy().path("/").build());
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(changes);
LiveHttpRequest request = get("/appB/hotel/details.html").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_B));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class BackendServicesRouterTest method updatesRoutesOnBackendServicesChange.
@Test
public void updatesRoutesOnBackendServicesChange() throws Exception {
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
LiveHttpRequest request = get("/appB/").build();
router.onChange(added(appB()));
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_B));
router.onChange(new Registry.Changes.Builder<BackendService>().build());
Optional<HttpHandler> route2 = router.route(request, context);
assertThat(proxyTo(route2, request).header(ORIGIN_ID_DEFAULT), isValue(APP_B));
}
Aggregations