From a7f87cf6cb0bc0df24bc40e84be95cae903648b3 Mon Sep 17 00:00:00 2001 From: Francesco Guardiani Date: Thu, 10 Dec 2020 19:28:02 +0100 Subject: [PATCH] Javadocs to http mods (#320) Signed-off-by: Francesco Guardiani --- .../http/restful/ws/CloudEventsProvider.java | 10 +++-- .../http/restful/ws/StructuredEncoding.java | 5 ++- .../http/restful/ws/impl/Utils.java | 28 ------------- .../http/vertx/VertxMessageFactory.java | 42 +++++++++---------- pom.xml | 2 + 5 files changed, 31 insertions(+), 56 deletions(-) delete mode 100644 http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/Utils.java diff --git a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/CloudEventsProvider.java b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/CloudEventsProvider.java index bfa36069..04a60cac 100644 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/CloudEventsProvider.java +++ b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/CloudEventsProvider.java @@ -24,7 +24,6 @@ import io.cloudevents.core.provider.EventFormatProvider; import io.cloudevents.http.restful.ws.impl.RestfulWSClientMessageWriter; import io.cloudevents.http.restful.ws.impl.RestfulWSMessageFactory; import io.cloudevents.http.restful.ws.impl.RestfulWSMessageWriter; -import io.cloudevents.http.restful.ws.impl.Utils; import io.cloudevents.rw.CloudEventWriter; import javax.ws.rs.Consumes; @@ -47,7 +46,7 @@ import java.util.Arrays; import java.util.Optional; /** - * This provider implements {@link CloudEvent} encoding and decoding for Jax-Rs Resources and {@link javax.ws.rs.client.Client} + * This provider implements {@link CloudEvent} encoding and decoding for Jax-Rs Resources and with {@link javax.ws.rs.client.Client}. */ @Provider @Consumes(MediaType.WILDCARD) @@ -133,7 +132,7 @@ public class CloudEventsProvider implements MessageBodyReader, Messa @Override public void filter(ClientRequestContext requestContext) throws IOException { - if (Utils.isCloudEventEntity(requestContext.getEntity())) { + if (isCloudEventEntity(requestContext.getEntity())) { EventFormat format = EventFormatProvider.getInstance().resolveFormat(requestContext.getMediaType().toString()); if (format != null) { @@ -150,4 +149,9 @@ public class CloudEventsProvider implements MessageBodyReader, Messa } } } + + private static boolean isCloudEventEntity(Object obj) { + return obj != null && CloudEvent.class.isAssignableFrom(obj.getClass()); + } + } diff --git a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/StructuredEncoding.java b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/StructuredEncoding.java index 0344ba0d..0e98a8fe 100644 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/StructuredEncoding.java +++ b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/StructuredEncoding.java @@ -30,8 +30,9 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) public @interface StructuredEncoding { /** - * Specify the content type of the structured mode - * (used to resolve the {@link io.cloudevents.core.format.EventFormat} through the {@link io.cloudevents.core.provider.EventFormatProvider}) + * Specify the content type of the structured mode. + * This values will be used to resolve the {@link io.cloudevents.core.format.EventFormat} through + * the {@link io.cloudevents.core.provider.EventFormatProvider}. */ String value(); } diff --git a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/Utils.java b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/Utils.java deleted file mode 100644 index ec90403f..00000000 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/Utils.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2018-Present The CloudEvents Authors - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package io.cloudevents.http.restful.ws.impl; - -import io.cloudevents.CloudEvent; - -public class Utils { - - public static boolean isCloudEventEntity(Object obj) { - return obj != null && CloudEvent.class.isAssignableFrom(obj.getClass()); - } - -} diff --git a/http/vertx/src/main/java/io/cloudevents/http/vertx/VertxMessageFactory.java b/http/vertx/src/main/java/io/cloudevents/http/vertx/VertxMessageFactory.java index c474aef3..9a5bbf01 100644 --- a/http/vertx/src/main/java/io/cloudevents/http/vertx/VertxMessageFactory.java +++ b/http/vertx/src/main/java/io/cloudevents/http/vertx/VertxMessageFactory.java @@ -11,7 +11,10 @@ import io.cloudevents.http.vertx.impl.VertxWebClientRequestMessageWriterImpl; import io.cloudevents.lang.Nullable; import io.cloudevents.rw.CloudEventRWException; import io.cloudevents.rw.CloudEventWriter; -import io.vertx.core.*; +import io.vertx.core.AsyncResult; +import io.vertx.core.Future; +import io.vertx.core.Handler; +import io.vertx.core.MultiMap; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpHeaders; import io.vertx.core.http.HttpServerRequest; @@ -23,7 +26,7 @@ import javax.annotation.ParametersAreNonnullByDefault; /** * This class provides a collection of methods to create {@link io.cloudevents.core.message.MessageReader} - * and {@link io.cloudevents.core.message.MessageWriter} for Vert.x HTTP Server and Web Client. + * and {@link io.cloudevents.core.message.MessageWriter} for Vert.x {@link io.vertx.core.http.HttpServer} and {@link io.vertx.ext.web.client.WebClient}. */ @ParametersAreNonnullByDefault public final class VertxMessageFactory { @@ -36,7 +39,8 @@ public final class VertxMessageFactory { * * @param headers Http headers * @param body nullable buffer of the body - * @return a Message implementation with potentially an unknown encoding + * @return a {@link MessageReader} implementation + * @throws CloudEventRWException if the encoding is unknown or something went wrong while parsing the headers */ public static MessageReader createReader(MultiMap headers, @Nullable Buffer body) throws CloudEventRWException { return MessageUtils.parseStructuredOrBinaryMessage( @@ -55,28 +59,19 @@ public final class VertxMessageFactory { } /** - * Build a {@link MessageReader} starting from an {@link HttpServerRequest} + * Build a {@link MessageReader} starting from an {@link HttpServerRequest}. * - * @param request - * @return + * @param request the input request + * @return a succeeded {@link Future} with the {@link MessageReader}, + * otherwise a failed {@link Future} if something went wrong while reading the body or while creating the {@link MessageReader} */ public static Future createReader(HttpServerRequest request) { - Promise prom = Promise.promise(); - - request.exceptionHandler(prom::tryFail); - request.bodyHandler(b -> { - try { - prom.complete(createReader(request.headers(), b)); - } catch (final Exception e) { - prom.fail(e); - } - }); - return prom.future(); + return request + .body() + .map(b -> createReader(request.headers(), b)); } /** - * @param request - * @param handler * @see #createReader(HttpServerRequest) */ public static void createReader(HttpServerRequest request, Handler> handler) { @@ -84,12 +79,13 @@ public final class VertxMessageFactory { } /** - * Build a {@link MessageReader} starting from an {@link io.vertx.ext.web.client.HttpResponse} + * Build a {@link MessageReader} starting from an {@link HttpResponse}. * - * @param response - * @return + * @param response the input web client response + * @return a {@link MessageReader} implementation + * @throws CloudEventRWException if the encoding is unknown or something went wrong while parsing the headers */ - public static MessageReader createReader(HttpResponse response) { + public static MessageReader createReader(HttpResponse response) throws CloudEventRWException { return createReader(response.headers(), response.body()); } diff --git a/pom.xml b/pom.xml index ecf7625d..fead163f 100644 --- a/pom.xml +++ b/pom.xml @@ -160,6 +160,8 @@ https://docs.spring.io/spring-framework/docs/current/javadoc-api/ + https://vertx.io/docs/apidocs/ + https://jakarta.ee/specifications/platform/8/apidocs/