Skip to content

Commit 8d71f15

Browse files
Javadocs
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
1 parent f5d9b47 commit 8d71f15

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

amqp/src/main/java/io/cloudevents/amqp/ProtonAmqpMessageFactory.java

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@
1717

1818
package io.cloudevents.amqp;
1919

20-
20+
import io.cloudevents.SpecVersion;
2121
import io.cloudevents.amqp.impl.AmqpConstants;
2222
import io.cloudevents.amqp.impl.ProtonAmqpBinaryMessageReader;
2323
import io.cloudevents.amqp.impl.ProtonAmqpMessageWriter;
2424
import io.cloudevents.core.message.MessageReader;
2525
import io.cloudevents.core.message.MessageWriter;
2626
import io.cloudevents.core.message.impl.GenericStructuredMessageReader;
2727
import io.cloudevents.core.message.impl.MessageUtils;
28+
import io.cloudevents.lang.Nullable;
29+
import io.cloudevents.rw.CloudEventRWException;
2830
import io.cloudevents.rw.CloudEventWriter;
2931
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
3032
import org.apache.qpid.proton.message.Message;
3133

3234
import javax.annotation.ParametersAreNonnullByDefault;
35+
3336
/**
34-
* A factory class providing convenience methods for creating MessageReader and MessageWriter instances based on Qpid Proton.
37+
* A factory class providing convenience methods for creating {@link MessageReader} and {@link MessageWriter} instances based on Qpid Proton {@link Message}.
3538
*/
3639
@ParametersAreNonnullByDefault
3740
public final class ProtonAmqpMessageFactory {
@@ -41,62 +44,63 @@ private ProtonAmqpMessageFactory() {
4144
}
4245

4346
/**
44-
* Creates a MessageReader to read a proton-based {@link Message}.
47+
* Creates a {@link MessageReader} to read a proton-based {@link Message}.
48+
* This reader is able to read both binary and structured encoded {@link io.cloudevents.CloudEvent}.
4549
* <p>
4650
* This implementation simply calls {@link #createReader(String, ApplicationProperties, byte[])}.
4751
*
48-
* @param message The proton message to read from.
49-
*
50-
* @return A message reader that can read the given proton message to a cloud event representation.
52+
* @param message The proton {@link Message} to read from.
53+
* @return A {@link MessageReader} that can read the given proton {@link Message} to a {@link io.cloudevents.CloudEvent} representation.
54+
* @throws CloudEventRWException if something goes wrong while resolving the {@link SpecVersion} or if the message has unknown encoding
55+
* @see #createReader(String, ApplicationProperties, byte[])
5156
*/
52-
public static MessageReader createReader(final Message message) {
53-
57+
public static MessageReader createReader(final Message message) throws CloudEventRWException {
5458
final byte[] payload = AmqpConstants.getPayloadAsByteArray(message.getBody());
5559
return createReader(message.getContentType(), message.getApplicationProperties(), payload);
5660
}
5761

5862
/**
59-
* Creates a MessageReader using the content-type property and payload of a proton-based message.
60-
* <p>
61-
* This method simply calls {@link #createReader(String, ApplicationProperties, byte[])}.
63+
* Creates a {@link MessageReader} using the {@code content-type} property and payload of a proton-based {@link Message}.
64+
* This reader is able to read both binary and structured encoded {@link io.cloudevents.CloudEvent}.
6265
*
63-
* @param contentType The content-type of the message payload.
66+
* @param contentType The {@code content-type} of the message payload.
6467
* @param payload The message payload in bytes.
65-
* @return A message reader capable of representing a CloudEvent from
66-
* a message <em>content-type</em> property and <em>application-data</em>.
68+
* @return A {@link MessageReader} capable of representing a CloudEvent from
69+
* a message {@code content-type} property and {@code application-data}.
70+
* @see #createReader(String, ApplicationProperties, byte[])
6771
*/
6872
public static MessageReader createReader(final String contentType, final byte[] payload) {
6973
return createReader(contentType, null, payload);
7074
}
7175

7276
/**
73-
* Creates a MessageWriter capable of translating both a structured and binary CloudEvent
74-
* to a proton-based AMQP 1.0 representation.
77+
* Creates a MessageReader to read using the {@code content-type} property, {@code application-properties} and data payload
78+
* of a proton-based {@link Message}. This reader is able to read both binary and structured encoded {@link io.cloudevents.CloudEvent}.
7579
*
76-
* @return A message writer to read structured and binary cloud event from a proton-based message.
80+
* @param contentType The {@code content-type} of the message payload.
81+
* @param props The {@code application-properties} section of the proton-message containing cloud event metadata (attributes and/or extensions).
82+
* @param payload The message payload in bytes or {@code null} if the message does not contain any payload.
83+
* @return A {@link MessageReader} capable of representing a {@link io.cloudevents.CloudEvent} from the {@code application-properties},
84+
* {@code content-type} and payload of a proton message.
85+
* @throws CloudEventRWException if something goes wrong while resolving the {@link SpecVersion} or if the message has unknown encoding
7786
*/
78-
public static MessageWriter<CloudEventWriter<Message>, Message> createWriter() {
79-
return new ProtonAmqpMessageWriter<>();
87+
public static MessageReader createReader(final String contentType, final ApplicationProperties props, @Nullable final byte[] payload) throws CloudEventRWException {
88+
return MessageUtils.parseStructuredOrBinaryMessage(
89+
() -> contentType,
90+
format -> new GenericStructuredMessageReader(format, payload),
91+
() -> AmqpConstants.getApplicationProperty(props, AmqpConstants.APP_PROPERTY_SPEC_VERSION, String.class),
92+
sv -> new ProtonAmqpBinaryMessageReader(sv, props, contentType, payload)
93+
);
8094
}
8195

8296
/**
83-
* Creates a MessageReader to read using the content-type property, application-propeties and data payload
84-
* of a proton-based message.
97+
* Creates a {@link MessageWriter} capable of translating both a structured and binary CloudEvent
98+
* to a proton-based AMQP 1.0 {@link Message}.
8599
*
86-
* @param contentType The content-type of the message payload.
87-
* @param props The application-properties section of the proton-message containing cloud event metadata (attributes and/or extensions).
88-
* @param payload The message payload in bytes or {@code null} if the message does not contain any payload.
89-
* @return A message reader capable of representing a CloudEvent from the application-properties,
90-
* content-type and payload of a proton message.
100+
* @return A {@link MessageWriter} to write a {@link io.cloudevents.CloudEvent} to Proton {@link Message} using structured or binary encoding.
91101
*/
92-
public static MessageReader createReader(final String contentType, final ApplicationProperties props, final byte[] payload) {
93-
94-
return MessageUtils.parseStructuredOrBinaryMessage(
95-
() -> contentType,
96-
format -> new GenericStructuredMessageReader(format, payload),
97-
() -> AmqpConstants.getApplicationProperty(props, AmqpConstants.APP_PROPERTY_SPEC_VERSION, String.class),
98-
sv -> new ProtonAmqpBinaryMessageReader(sv, props, contentType, payload));
99-
102+
public static MessageWriter<CloudEventWriter<Message>, Message> createWriter() {
103+
return new ProtonAmqpMessageWriter<>();
100104
}
101105

102106
}

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@
158158
<version>3.2.0</version>
159159
<configuration>
160160
<detectLinks/>
161+
<links>
162+
<link>https://qpid.apache.org/releases/qpid-proton-j-0.33.7/api/</link>
163+
</links>
161164
</configuration>
162165
<executions>
163166
<execution>

0 commit comments

Comments
 (0)