From 5f796ac372eda429ef98b7b44ceb2fe6ecba21e9 Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser <23085769+hiddenalpha@users.noreply.github.com> Date: Thu, 27 Jul 2023 12:00:26 +0200 Subject: [PATCH 1/4] [SDCISA-12877] Implement another HttpClient method. --- .../core/event/SucceededAsyncResult.java | 32 +++++++++++++++++++ .../core/http/AbstractHttpClient.java | 10 +++++- .../gateleen/core/http/LocalHttpClient.java | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gateleen-core/src/main/java/org/swisspush/gateleen/core/event/SucceededAsyncResult.java diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/event/SucceededAsyncResult.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/event/SucceededAsyncResult.java new file mode 100644 index 000000000..d334d8bab --- /dev/null +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/event/SucceededAsyncResult.java @@ -0,0 +1,32 @@ +package org.swisspush.gateleen.core.event; + +import io.vertx.core.AsyncResult; + +/** Exists because I was not able to find such an implementation in vertx.jar */ +public class SucceededAsyncResult implements AsyncResult { + private final E result; + + public SucceededAsyncResult(E result) { + this.result = result; + } + + @Override + public E result() { + return result; + } + + @Override + public Throwable cause() { + return null; + } + + @Override + public boolean succeeded() { + return true; + } + + @Override + public boolean failed() { + return false; + } +} diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java index 05a1f6131..f77a57e03 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java @@ -4,7 +4,9 @@ import io.vertx.core.Future; import io.vertx.core.Handler; import io.vertx.core.MultiMap; +import io.vertx.core.Vertx; import io.vertx.core.http.*; +import org.swisspush.gateleen.core.event.SucceededAsyncResult; import java.util.List; import java.util.function.Function; @@ -16,6 +18,12 @@ */ public abstract class AbstractHttpClient implements HttpClient { + private final Vertx vertx; + + public AbstractHttpClient(Vertx vertx) { + this.vertx = vertx; + } + protected abstract HttpClientRequest doRequest(HttpMethod method, String uri); public HttpClientRequest options(String uri) { @@ -90,7 +98,7 @@ public Future request(HttpMethod httpMethod, String s, String @Override public void request(HttpMethod method, String requestURI, Handler> handler) { - throw new UnsupportedOperationException(); + vertx.runOnContext(v -> handler.handle(new SucceededAsyncResult<>(doRequest(method, requestURI)))); } @Override diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java index 1750f7d64..07848ea76 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java @@ -15,6 +15,7 @@ public class LocalHttpClient extends AbstractHttpClient { private Vertx vertx; public LocalHttpClient(Vertx vertx) { + super(vertx); this.vertx = vertx; } From 15d4b9f2cdce1a152293657b72edcda04c33c782 Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser <23085769+hiddenalpha@users.noreply.github.com> Date: Thu, 27 Jul 2023 15:24:50 +0200 Subject: [PATCH 2/4] [SDCISA-12877] Use Future to replace custom SucceededAsyncResult impl as requested in review --- .../core/event/SucceededAsyncResult.java | 32 ------------------- .../core/http/AbstractHttpClient.java | 5 +-- 2 files changed, 3 insertions(+), 34 deletions(-) delete mode 100644 gateleen-core/src/main/java/org/swisspush/gateleen/core/event/SucceededAsyncResult.java diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/event/SucceededAsyncResult.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/event/SucceededAsyncResult.java deleted file mode 100644 index d334d8bab..000000000 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/event/SucceededAsyncResult.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.swisspush.gateleen.core.event; - -import io.vertx.core.AsyncResult; - -/** Exists because I was not able to find such an implementation in vertx.jar */ -public class SucceededAsyncResult implements AsyncResult { - private final E result; - - public SucceededAsyncResult(E result) { - this.result = result; - } - - @Override - public E result() { - return result; - } - - @Override - public Throwable cause() { - return null; - } - - @Override - public boolean succeeded() { - return true; - } - - @Override - public boolean failed() { - return false; - } -} diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java index f77a57e03..537f588e3 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java @@ -6,11 +6,12 @@ import io.vertx.core.MultiMap; import io.vertx.core.Vertx; import io.vertx.core.http.*; -import org.swisspush.gateleen.core.event.SucceededAsyncResult; import java.util.List; import java.util.function.Function; +import static io.vertx.core.Future.succeededFuture; + /** * Base class with empty method implementations. * @@ -98,7 +99,7 @@ public Future request(HttpMethod httpMethod, String s, String @Override public void request(HttpMethod method, String requestURI, Handler> handler) { - vertx.runOnContext(v -> handler.handle(new SucceededAsyncResult<>(doRequest(method, requestURI)))); + vertx.runOnContext(v -> succeededFuture(doRequest(method, requestURI)).onComplete(handler)); } @Override From 99366986bad8d4448beb841d8045239c19298037 Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser <23085769+hiddenalpha@users.noreply.github.com> Date: Thu, 27 Jul 2023 15:40:00 +0200 Subject: [PATCH 3/4] [SDCISA-12877] Fix Another (unrelated) occurence in regard to https://blog.ometer.com/2011/07/24/callbacks-synchronous-and-asynchronous/ --- .../org/swisspush/gateleen/core/http/AbstractHttpClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java index 537f588e3..45a7cdb07 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/AbstractHttpClient.java @@ -80,7 +80,7 @@ public Future request(RequestOptions requestOptions) { @Override public void request(HttpMethod httpMethod, int i, String s, String s1, Handler> handler) { - Future.succeededFuture(doRequest(httpMethod, s1)).onComplete(handler); + vertx.runOnContext(v -> succeededFuture(doRequest(httpMethod, s1)).onComplete(handler)); } @Override From 08706034c4c5d1e5571ed85b071ac339e6a60fca Mon Sep 17 00:00:00 2001 From: "Andreas Fankhauser hiddenalpha.ch" <23085769+hiddenalpha@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:24:43 +0200 Subject: [PATCH 4/4] An empty commit without any changes just because I found no other way how to trigger another build.