diff --git a/plugin-examples/src/main/java/com/hotels/styx/ExamplePlugin.java b/plugin-examples/src/main/java/com/hotels/styx/ExamplePlugin.java index 3efeb7e3c5..2b5cd4caeb 100644 --- a/plugin-examples/src/main/java/com/hotels/styx/ExamplePlugin.java +++ b/plugin-examples/src/main/java/com/hotels/styx/ExamplePlugin.java @@ -18,7 +18,9 @@ import com.hotels.styx.api.HttpHandler; import com.hotels.styx.api.HttpRequest; import com.hotels.styx.api.HttpResponse; -import com.hotels.styx.api.StyxObservable; +import com.hotels.styx.api.Eventual; +import com.hotels.styx.api.LiveHttpRequest; +import com.hotels.styx.api.LiveHttpResponse; import com.hotels.styx.api.plugins.spi.Plugin; import java.util.Map; @@ -56,7 +58,7 @@ public ExamplePlugin(ExamplePluginConfig config) { * @return */ @Override - public StyxObservable intercept(HttpRequest request, Chain chain) { + public Eventual intercept(LiveHttpRequest request, Chain chain) { /* the intercept method is where you can modify the request, modify the response and handle side-effects. @@ -68,7 +70,7 @@ public StyxObservable intercept(HttpRequest request, Chain chain) * */ // Here is a simple example of modifying an incoming request. - HttpRequest newRequest = request.newBuilder() + LiveHttpRequest newRequest = request.newBuilder() .header("myRequestHeader", config.requestHeaderValue()) .build(); diff --git a/plugin-examples/src/test/java/com/hotels/styx/ExamplePluginTest.java b/plugin-examples/src/test/java/com/hotels/styx/ExamplePluginTest.java index 2bc7c33bdf..5b884a3da1 100644 --- a/plugin-examples/src/test/java/com/hotels/styx/ExamplePluginTest.java +++ b/plugin-examples/src/test/java/com/hotels/styx/ExamplePluginTest.java @@ -15,15 +15,19 @@ */ package com.hotels.styx; +import com.hotels.styx.api.Buffer; +import com.hotels.styx.api.Eventual; import com.hotels.styx.api.HttpInterceptor; import com.hotels.styx.api.HttpRequest; import com.hotels.styx.api.HttpResponse; -import com.hotels.styx.api.StyxObservable; +import com.hotels.styx.api.Eventual; +import com.hotels.styx.api.LiveHttpRequest; +import com.hotels.styx.api.LiveHttpResponse; import org.testng.annotations.Test; -import static com.hotels.styx.api.HttpRequest.get; -import static com.hotels.styx.api.HttpResponse.response; +import static com.hotels.styx.api.LiveHttpRequest.get; +import static com.hotels.styx.api.LiveHttpResponse.response; import static com.hotels.styx.api.HttpResponseStatus.OK; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -44,15 +48,16 @@ public void addsExtraHeaders() throws Exception { HttpInterceptor.Chain chain = request -> { assertThat(request.header("myRequestHeader").orElse(null), is("foo")); - return StyxObservable.of(response(OK).build()); + return Eventual.of(response(OK).build()); }; // an example request you expect your plugin to receive - HttpRequest request = get("/foo") + LiveHttpRequest request = get("/foo") .build(); + //The method StyxFutures.await() in styx-common wraps future.get() including appropriate Exception handling. - HttpResponse response = plugin.intercept(request, chain).asCompletableFuture().get(); + LiveHttpResponse response = plugin.intercept(request, chain).asCompletableFuture().get(); assertThat(response.header("myResponseheader").orElse(null), is("bar")); } }