public static HttpResponse waitForResponse(Eventual<LiveHttpResponse> responseObs) { return Mono.from(responseObs.flatMap(response -> response.aggregate(120*1024))).block(); }
private Eventual<LiveHttpResponse> putNewState(LiveHttpRequest request, HttpInterceptor.Context context) { return Eventual.of(request) .flatMap(this::requestedUpdate) .map(this::applyUpdate); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { return chain.proceed(request) .flatMap(response -> response.aggregate(this.maxContentLength)) .flatMap(fullResponse -> Eventual.from(asyncEvent(this.delayMillis)) .map(x -> fullResponse)) .map(HttpResponse::stream); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { return chain.proceed(request) .flatMap(response -> Eventual.from(processAsynchronously(response, config.delayMillis()))); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { return request.aggregate(config.maxContentLength()) .flatMap(fullHttpRequest -> Eventual.from(asyncOperation(config.delayMillis()))) .map(outcome -> request.newBuilder().header("X-Outcome", outcome.result())) .flatMap(x -> chain.proceed(request)); } }
@Test public void exposesNameAndStatusViaAdminInterface() throws ExecutionException, InterruptedException { DerivedStyxService service = new DerivedStyxService("derived-service", new CompletableFuture<>()); HttpResponse response = Mono.from(service.adminInterfaceHandlers().get("status").handle(get, MOCK_CONTEXT) .flatMap(r -> r.aggregate(1024))).block(); assertThat(response.bodyAs(UTF_8), is("{ name: \"derived-service\" status: \"CREATED\" }")); }
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()); }); }
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()); }); } }
@Test public void flatMapsValues() { Eventual<String> eventual = Eventual.of("hello") .flatMap(it -> Eventual.of(it + " world")); StepVerifier.create(eventual) .expectNext("hello world") .verifyComplete(); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { String header = xHcomPluginsHeader(request); final String configPath = environment.pluginConfig(String.class); String pluginsList = environment.configuration().get("plugins.active").get(); LiveHttpRequest newRequest = request.newBuilder() .header(X_HCOM_PLUGINS_HEADER, header) .header(X_HCOM_PLUGINS_CONFIGURATION_PATH, configPath) .header(X_HCOM_PLUGINS_LIST, pluginsList) .header("X-Hcom-Styx-Started", styxStarted) .header("X-Hcom-Styx-Stopped", styxStopped) .build(); Function<ByteBuf, String> byteBufStringFunction = byteBuf -> byteBuf.toString(Charsets.UTF_8); return chain.proceed(newRequest) .flatMap(response -> response.aggregate(1 * 1024 * 1024)) .map(response -> response.newBuilder() .header(X_HCOM_PLUGINS_HEADER, header) .header(X_HCOM_PLUGINS_CONFIGURATION_PATH, configPath) .header(X_HCOM_PLUGINS_LIST, pluginsList) .header("X-Hcom-Styx-Started", styxStarted) .header("X-Hcom-Styx-Stopped", styxStopped) .build()) .map(HttpResponse::stream); }