From bfa1d1c80e74d659411653219e38f0abedf1b9a8 Mon Sep 17 00:00:00 2001 From: Malte Pickhan Date: Mon, 4 Apr 2022 20:59:59 +0200 Subject: [PATCH 01/10] #131 Add some explanation what the exception is used for. --- .../java/org/zalando/fahrschein/EventPublishingException.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java b/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java index d9e37ab8..947e19f6 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java @@ -6,7 +6,9 @@ import java.util.Formatter; import java.util.Locale; -@SuppressWarnings("serial") +/** + * Thrown in case the client wasn't able to publish the given Event to Nakadi. + */ public class EventPublishingException extends IOException { private final BatchItemResponse[] responses; From b5dba92c38a27ec555a4a3c656a9a30e00393afb Mon Sep 17 00:00:00 2001 From: Malte Pickhan Date: Mon, 4 Apr 2022 21:00:04 +0200 Subject: [PATCH 02/10] #131 Document public class and methods. --- .../org/zalando/fahrschein/NakadiClient.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java index 3f21f0d8..92a2ffeb 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java @@ -26,6 +26,9 @@ import static org.zalando.fahrschein.Preconditions.checkArgument; import static org.zalando.fahrschein.Preconditions.checkState; +/** + * General implementation of the Nakadi Client used within this Library. + */ public class NakadiClient { private static final Logger LOG = LoggerFactory.getLogger(NakadiClient.class); @@ -38,6 +41,14 @@ public class NakadiClient { private final ObjectMapper objectMapper; private final CursorManager cursorManager; + /** + * Returns a new Builder that will make use of the given request Factory and tries to connect to the give + * address. + * + * @param baseUri that we try to connect to + * @param clientHttpRequestFactory that we use for the execution of our HTTP Requests. + * @return A builder to initialize the client. Can be further modified later. + */ public static NakadiClientBuilder builder(URI baseUri, RequestFactory clientHttpRequestFactory) { return new NakadiClientBuilder(baseUri, clientHttpRequestFactory); } @@ -50,6 +61,12 @@ public static NakadiClientBuilder builder(URI baseUri, RequestFactory clientHttp this.cursorManager = cursorManager; } + /** + * Resolves a list of partitions for the given eventName. + * @param eventName that we want to resolve the partitions for. + * @return {@code List} or {@code null} in + * @throws IOException in case of network issues. + */ public List getPartitions(String eventName) throws IOException { final URI uri = baseUri.resolve(String.format("/event-types/%s/partitions", eventName)); final Request request = clientHttpRequestFactory.createRequest(uri, "GET"); @@ -60,7 +77,14 @@ public List getPartitions(String eventName) throws IOException { } } - public void publish(String eventName, List events) throws EventPublishingException, IOException { + /** + * Writes the given Events to the endpoint provided by the eventName. + * @param eventName where the event should be written to + * @param events that should be written + * @param Type of the Event + * @throws IOException in case we fail reaching Nakadi or we are unable to write the event. + */ + public void publish(String eventName, List events) throws IOException { final URI uri = baseUri.resolve(String.format("/event-types/%s/events", eventName)); final Request request = clientHttpRequestFactory.createRequest(uri, "POST"); From 0f6e97cb39c2ec14704fdbfff0fc47ad818bc767 Mon Sep 17 00:00:00 2001 From: Malte Date: Tue, 5 Apr 2022 13:18:55 +0200 Subject: [PATCH 03/10] Update fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java Co-authored-by: Oliver Trosien --- .../src/main/java/org/zalando/fahrschein/NakadiClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java index 92a2ffeb..2bc5cbbc 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java @@ -78,7 +78,7 @@ public List getPartitions(String eventName) throws IOException { } /** - * Writes the given Events to the endpoint provided by the eventName. + * Writes the given events to the endpoint provided by the eventName. * @param eventName where the event should be written to * @param events that should be written * @param Type of the Event From f85f97f5b5b9d53639e210fb994265e92685c407 Mon Sep 17 00:00:00 2001 From: Malte Date: Tue, 5 Apr 2022 13:19:01 +0200 Subject: [PATCH 04/10] Update fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java Co-authored-by: Oliver Trosien --- .../java/org/zalando/fahrschein/EventPublishingException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java b/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java index 947e19f6..663c222f 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java @@ -7,7 +7,7 @@ import java.util.Locale; /** - * Thrown in case the client wasn't able to publish the given Event to Nakadi. + * Thrown in case the client wasn't able to publish the given event to Nakadi. */ public class EventPublishingException extends IOException { private final BatchItemResponse[] responses; From aa9dba3a042ad28f595cac0e5bfa96746b28760c Mon Sep 17 00:00:00 2001 From: Malte Pickhan Date: Tue, 3 May 2022 23:06:22 +0200 Subject: [PATCH 05/10] #131 Rename clientHttpRequestFactory to requestFactory. --- .../org/zalando/fahrschein/NakadiClient.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java index 92a2ffeb..e1141785 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java @@ -36,7 +36,7 @@ public class NakadiClient { }; private final URI baseUri; - private final RequestFactory clientHttpRequestFactory; + private final RequestFactory requestFactory; private final ObjectMapper internalObjectMapper; private final ObjectMapper objectMapper; private final CursorManager cursorManager; @@ -46,16 +46,16 @@ public class NakadiClient { * address. * * @param baseUri that we try to connect to - * @param clientHttpRequestFactory that we use for the execution of our HTTP Requests. + * @param requestFactory that we use for the execution of our HTTP Requests. * @return A builder to initialize the client. Can be further modified later. */ - public static NakadiClientBuilder builder(URI baseUri, RequestFactory clientHttpRequestFactory) { - return new NakadiClientBuilder(baseUri, clientHttpRequestFactory); + public static NakadiClientBuilder builder(URI baseUri, RequestFactory requestFactory) { + return new NakadiClientBuilder(baseUri, requestFactory); } - NakadiClient(URI baseUri, RequestFactory clientHttpRequestFactory, ObjectMapper objectMapper, CursorManager cursorManager) { + NakadiClient(URI baseUri, RequestFactory requestFactory, ObjectMapper objectMapper, CursorManager cursorManager) { this.baseUri = baseUri; - this.clientHttpRequestFactory = clientHttpRequestFactory; + this.requestFactory = requestFactory; this.objectMapper = objectMapper; this.internalObjectMapper = DefaultObjectMapper.INSTANCE; this.cursorManager = cursorManager; @@ -69,7 +69,7 @@ public static NakadiClientBuilder builder(URI baseUri, RequestFactory clientHttp */ public List getPartitions(String eventName) throws IOException { final URI uri = baseUri.resolve(String.format("/event-types/%s/partitions", eventName)); - final Request request = clientHttpRequestFactory.createRequest(uri, "GET"); + final Request request = requestFactory.createRequest(uri, "GET"); try (final Response response = request.execute()) { try (final InputStream is = response.getBody()) { return internalObjectMapper.readValue(is, LIST_OF_PARTITIONS); @@ -86,7 +86,7 @@ public List getPartitions(String eventName) throws IOException { */ public void publish(String eventName, List events) throws IOException { final URI uri = baseUri.resolve(String.format("/event-types/%s/events", eventName)); - final Request request = clientHttpRequestFactory.createRequest(uri, "POST"); + final Request request = requestFactory.createRequest(uri, "POST"); request.getHeaders().setContentType(ContentType.APPLICATION_JSON); @@ -130,7 +130,7 @@ public void deleteSubscription(String subscriptionId) throws IOException { checkArgument(!subscriptionId.isEmpty(), "Subscription ID cannot be empty."); final URI uri = baseUri.resolve(String.format("/subscriptions/%s", subscriptionId)); - final Request request = clientHttpRequestFactory.createRequest(uri, "DELETE"); + final Request request = requestFactory.createRequest(uri, "DELETE"); request.getHeaders().setContentType(ContentType.APPLICATION_JSON); @@ -151,7 +151,7 @@ Subscription subscribe(String applicationName, Set eventNames, String co final SubscriptionRequest subscription = new SubscriptionRequest(applicationName, eventNames, consumerGroup, readFrom, initialCursors, authorization); final URI uri = baseUri.resolve("/subscriptions"); - final Request request = clientHttpRequestFactory.createRequest(uri, "POST"); + final Request request = requestFactory.createRequest(uri, "POST"); request.getHeaders().setContentType(ContentType.APPLICATION_JSON); @@ -172,11 +172,11 @@ Subscription subscribe(String applicationName, Set eventNames, String co public StreamBuilder.SubscriptionStreamBuilder stream(Subscription subscription) { checkState(cursorManager instanceof ManagedCursorManager, "Subscription api requires a ManagedCursorManager"); - return new StreamBuilders.SubscriptionStreamBuilderImpl(baseUri, clientHttpRequestFactory, cursorManager, objectMapper, subscription); + return new StreamBuilders.SubscriptionStreamBuilderImpl(baseUri, requestFactory, cursorManager, objectMapper, subscription); } public StreamBuilder.LowLevelStreamBuilder stream(String eventName) { - return new StreamBuilders.LowLevelStreamBuilderImpl(baseUri, clientHttpRequestFactory, cursorManager, objectMapper, eventName); + return new StreamBuilders.LowLevelStreamBuilderImpl(baseUri, requestFactory, cursorManager, objectMapper, eventName); } } From 14497a87de59037b1cb00535ee59ea06e9ba1afe Mon Sep 17 00:00:00 2001 From: Malte Pickhan Date: Tue, 3 May 2022 23:16:40 +0200 Subject: [PATCH 06/10] #131 Reintroduce throwing of EventPublishingException in order to give the chance to treat it dedicated. --- .../src/main/java/org/zalando/fahrschein/NakadiClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java index 6eb901d3..404b19ca 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java @@ -83,8 +83,9 @@ public List getPartitions(String eventName) throws IOException { * @param events that should be written * @param Type of the Event * @throws IOException in case we fail reaching Nakadi or we are unable to write the event. + * @throws EventPublishingException in case we fail reaching Nakadi or we are unable to write the event. */ - public void publish(String eventName, List events) throws IOException { + public void publish(String eventName, List events) throws EventPublishingException, IOException { final URI uri = baseUri.resolve(String.format("/event-types/%s/events", eventName)); final Request request = requestFactory.createRequest(uri, "POST"); From 0b1846dc533fb6d70f5afe47dcfcf2d60a57eaba Mon Sep 17 00:00:00 2001 From: Malte Date: Tue, 3 May 2022 23:17:53 +0200 Subject: [PATCH 07/10] Update fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java Co-authored-by: Oliver Trosien --- .../src/main/java/org/zalando/fahrschein/NakadiClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java index 404b19ca..9211ad90 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java @@ -42,7 +42,7 @@ public class NakadiClient { private final CursorManager cursorManager; /** - * Returns a new Builder that will make use of the given request Factory and tries to connect to the give + * Returns a new Builder that will make use of the given {@code RequestFactory} and tries to connect to the given * address. * * @param baseUri that we try to connect to From cffe8a46978a89799b1811ee42c8783fd576077f Mon Sep 17 00:00:00 2001 From: Malte Pickhan Date: Tue, 3 May 2022 23:19:19 +0200 Subject: [PATCH 08/10] #131 Fix javadoc --- .../src/main/java/org/zalando/fahrschein/NakadiClient.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java index 404b19ca..0841780b 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java @@ -42,10 +42,9 @@ public class NakadiClient { private final CursorManager cursorManager; /** - * Returns a new Builder that will make use of the given request Factory and tries to connect to the give - * address. + * Returns a new Builder that will make use of the given request Factory. * - * @param baseUri that we try to connect to + * @param baseUri that we will connect to * @param requestFactory that we use for the execution of our HTTP Requests. * @return A builder to initialize the client. Can be further modified later. */ From cae37e8b1e42bd355556a200f9beffa7cc841d39 Mon Sep 17 00:00:00 2001 From: Malte Pickhan Date: Wed, 4 May 2022 13:34:48 +0200 Subject: [PATCH 09/10] #131 Make it explicit in the Javadocs when EventPublishingException is thrown. --- .../src/main/java/org/zalando/fahrschein/NakadiClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java index d26a3376..8cd1c876 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClient.java @@ -81,8 +81,8 @@ public List getPartitions(String eventName) throws IOException { * @param eventName where the event should be written to * @param events that should be written * @param Type of the Event - * @throws IOException in case we fail reaching Nakadi or we are unable to write the event. - * @throws EventPublishingException in case we fail reaching Nakadi or we are unable to write the event. + * @throws IOException in case we fail to reach Nakadi + * @throws EventPublishingException In case Nakadi returns an Erroneous response */ public void publish(String eventName, List events) throws EventPublishingException, IOException { final URI uri = baseUri.resolve(String.format("/event-types/%s/events", eventName)); From af9983de442ceb72aabc67d38d818492f5bc7f99 Mon Sep 17 00:00:00 2001 From: Malte Pickhan Date: Wed, 4 May 2022 14:45:37 +0200 Subject: [PATCH 10/10] #131 Improve documentation on EventPublishingException and NakadiClientBuilder. --- .../org/zalando/fahrschein/EventPublishingException.java | 4 +++- .../java/org/zalando/fahrschein/NakadiClientBuilder.java | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java b/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java index 663c222f..bd7fff0b 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/EventPublishingException.java @@ -7,7 +7,9 @@ import java.util.Locale; /** - * Thrown in case the client wasn't able to publish the given event to Nakadi. + * Thrown in case the client wasn't able to publish the given batch of events to Nakadi. + * + * The response will contain an array of {@code BatchItemResponse}. */ public class EventPublishingException extends IOException { private final BatchItemResponse[] responses; diff --git a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClientBuilder.java b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClientBuilder.java index c529249d..39755977 100644 --- a/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClientBuilder.java +++ b/fahrschein/src/main/java/org/zalando/fahrschein/NakadiClientBuilder.java @@ -57,6 +57,14 @@ static RequestFactory wrapClientHttpRequestFactory(RequestFactory delegate, @Nul return requestFactory; } + /** + * Creates a new instance of {@code NakadiClient}. In case no {@code ObjectMapper} is provided, it's going to make + * use of {@code DefaultObjectMapper} that is making use of + * {@code PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES}. + * In case no {@code CursorManager} is provided it's going to make use of {@code ManagedCursorManager}. + * + * @return A fresh instance of {@code NakadiClient} + */ public NakadiClient build() { final RequestFactory clientHttpRequestFactory = wrapClientHttpRequestFactory(this.clientHttpRequestFactory, authorizationProvider); final CursorManager cursorManager = this.cursorManager != null ? this.cursorManager : new ManagedCursorManager(baseUri, clientHttpRequestFactory, true);