Javadocs to http mods (#320)
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
This commit is contained in:
parent
711277eacb
commit
a7f87cf6cb
|
|
@ -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<CloudEvent>, 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<CloudEvent>, Messa
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isCloudEventEntity(Object obj) {
|
||||
return obj != null && CloudEvent.class.isAssignableFrom(obj.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<MessageReader> createReader(HttpServerRequest request) {
|
||||
Promise<MessageReader> 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<AsyncResult<MessageReader>> 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<Buffer> response) {
|
||||
public static MessageReader createReader(HttpResponse<Buffer> response) throws CloudEventRWException {
|
||||
return createReader(response.headers(), response.body());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue