Skip to content

Commit a7f87cf

Browse files
Javadocs to http mods (cloudevents#320)
Signed-off-by: Francesco Guardiani <[email protected]>
1 parent 711277e commit a7f87cf

File tree

5 files changed

+31
-56
lines changed

5 files changed

+31
-56
lines changed

http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/CloudEventsProvider.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.cloudevents.http.restful.ws.impl.RestfulWSClientMessageWriter;
2525
import io.cloudevents.http.restful.ws.impl.RestfulWSMessageFactory;
2626
import io.cloudevents.http.restful.ws.impl.RestfulWSMessageWriter;
27-
import io.cloudevents.http.restful.ws.impl.Utils;
2827
import io.cloudevents.rw.CloudEventWriter;
2928

3029
import javax.ws.rs.Consumes;
@@ -47,7 +46,7 @@
4746
import java.util.Optional;
4847

4948
/**
50-
* This provider implements {@link CloudEvent} encoding and decoding for Jax-Rs Resources and {@link javax.ws.rs.client.Client}
49+
* This provider implements {@link CloudEvent} encoding and decoding for Jax-Rs Resources and with {@link javax.ws.rs.client.Client}.
5150
*/
5251
@Provider
5352
@Consumes(MediaType.WILDCARD)
@@ -133,7 +132,7 @@ private <V extends MessageWriter<V, Void> & CloudEventWriter<Void>> void writeSt
133132

134133
@Override
135134
public void filter(ClientRequestContext requestContext) throws IOException {
136-
if (Utils.isCloudEventEntity(requestContext.getEntity())) {
135+
if (isCloudEventEntity(requestContext.getEntity())) {
137136
EventFormat format = EventFormatProvider.getInstance().resolveFormat(requestContext.getMediaType().toString());
138137

139138
if (format != null) {
@@ -150,4 +149,9 @@ public void filter(ClientRequestContext requestContext) throws IOException {
150149
}
151150
}
152151
}
152+
153+
private static boolean isCloudEventEntity(Object obj) {
154+
return obj != null && CloudEvent.class.isAssignableFrom(obj.getClass());
155+
}
156+
153157
}

http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/StructuredEncoding.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
@Retention(RetentionPolicy.RUNTIME)
3131
public @interface StructuredEncoding {
3232
/**
33-
* Specify the content type of the structured mode
34-
* (used to resolve the {@link io.cloudevents.core.format.EventFormat} through the {@link io.cloudevents.core.provider.EventFormatProvider})
33+
* Specify the content type of the structured mode.
34+
* This values will be used to resolve the {@link io.cloudevents.core.format.EventFormat} through
35+
* the {@link io.cloudevents.core.provider.EventFormatProvider}.
3536
*/
3637
String value();
3738
}

http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/Utils.java

-28
This file was deleted.

http/vertx/src/main/java/io/cloudevents/http/vertx/VertxMessageFactory.java

+19-23
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import io.cloudevents.lang.Nullable;
1212
import io.cloudevents.rw.CloudEventRWException;
1313
import io.cloudevents.rw.CloudEventWriter;
14-
import io.vertx.core.*;
14+
import io.vertx.core.AsyncResult;
15+
import io.vertx.core.Future;
16+
import io.vertx.core.Handler;
17+
import io.vertx.core.MultiMap;
1518
import io.vertx.core.buffer.Buffer;
1619
import io.vertx.core.http.HttpHeaders;
1720
import io.vertx.core.http.HttpServerRequest;
@@ -23,7 +26,7 @@
2326

2427
/**
2528
* This class provides a collection of methods to create {@link io.cloudevents.core.message.MessageReader}
26-
* and {@link io.cloudevents.core.message.MessageWriter} for Vert.x HTTP Server and Web Client.
29+
* and {@link io.cloudevents.core.message.MessageWriter} for Vert.x {@link io.vertx.core.http.HttpServer} and {@link io.vertx.ext.web.client.WebClient}.
2730
*/
2831
@ParametersAreNonnullByDefault
2932
public final class VertxMessageFactory {
@@ -36,7 +39,8 @@ private VertxMessageFactory() {
3639
*
3740
* @param headers Http headers
3841
* @param body nullable buffer of the body
39-
* @return a Message implementation with potentially an unknown encoding
42+
* @return a {@link MessageReader} implementation
43+
* @throws CloudEventRWException if the encoding is unknown or something went wrong while parsing the headers
4044
*/
4145
public static MessageReader createReader(MultiMap headers, @Nullable Buffer body) throws CloudEventRWException {
4246
return MessageUtils.parseStructuredOrBinaryMessage(
@@ -55,41 +59,33 @@ public static MessageReader createReader(MultiMap headers, @Nullable Buffer body
5559
}
5660

5761
/**
58-
* Build a {@link MessageReader} starting from an {@link HttpServerRequest}
62+
* Build a {@link MessageReader} starting from an {@link HttpServerRequest}.
5963
*
60-
* @param request
61-
* @return
64+
* @param request the input request
65+
* @return a succeeded {@link Future} with the {@link MessageReader},
66+
* otherwise a failed {@link Future} if something went wrong while reading the body or while creating the {@link MessageReader}
6267
*/
6368
public static Future<MessageReader> createReader(HttpServerRequest request) {
64-
Promise<MessageReader> prom = Promise.promise();
65-
66-
request.exceptionHandler(prom::tryFail);
67-
request.bodyHandler(b -> {
68-
try {
69-
prom.complete(createReader(request.headers(), b));
70-
} catch (final Exception e) {
71-
prom.fail(e);
72-
}
73-
});
74-
return prom.future();
69+
return request
70+
.body()
71+
.map(b -> createReader(request.headers(), b));
7572
}
7673

7774
/**
78-
* @param request
79-
* @param handler
8075
* @see #createReader(HttpServerRequest)
8176
*/
8277
public static void createReader(HttpServerRequest request, Handler<AsyncResult<MessageReader>> handler) {
8378
createReader(request).onComplete(handler);
8479
}
8580

8681
/**
87-
* Build a {@link MessageReader} starting from an {@link io.vertx.ext.web.client.HttpResponse}
82+
* Build a {@link MessageReader} starting from an {@link HttpResponse}.
8883
*
89-
* @param response
90-
* @return
84+
* @param response the input web client response
85+
* @return a {@link MessageReader} implementation
86+
* @throws CloudEventRWException if the encoding is unknown or something went wrong while parsing the headers
9187
*/
92-
public static MessageReader createReader(HttpResponse<Buffer> response) {
88+
public static MessageReader createReader(HttpResponse<Buffer> response) throws CloudEventRWException {
9389
return createReader(response.headers(), response.body());
9490
}
9591

pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@
160160
<detectLinks/>
161161
<links>
162162
<link>https://docs.spring.io/spring-framework/docs/current/javadoc-api/</link>
163+
<link>https://vertx.io/docs/apidocs/</link>
164+
<link>https://jakarta.ee/specifications/platform/8/apidocs/</link>
163165
</links>
164166
</configuration>
165167
<executions>

0 commit comments

Comments
 (0)