From fa48468e70b693f8dbfcf64ae58ce5824f70b21d Mon Sep 17 00:00:00 2001 From: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> Date: Thu, 23 Mar 2023 13:58:17 +0000 Subject: [PATCH 1/8] 537-refactor-facilitate-decoupling-eventformat-impls-1 Signed-off-by: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> --- .../cloudevents/core/format/ContentType.java | 75 +++++++++++++++++++ .../core/provider/EventFormatProvider.java | 13 ++++ .../provider/EventFormatProviderTest.java | 6 ++ docs/json-jackson.md | 4 +- docs/protobuf.md | 4 +- docs/xml.md | 4 +- .../io/cloudevents/jackson/JsonFormat.java | 6 ++ .../cloudevents/jackson/JsonFormatTest.java | 41 +++++++++- 8 files changed, 145 insertions(+), 8 deletions(-) create mode 100644 core/src/main/java/io/cloudevents/core/format/ContentType.java diff --git a/core/src/main/java/io/cloudevents/core/format/ContentType.java b/core/src/main/java/io/cloudevents/core/format/ContentType.java new file mode 100644 index 000000000..158c70b9a --- /dev/null +++ b/core/src/main/java/io/cloudevents/core/format/ContentType.java @@ -0,0 +1,75 @@ +/* + * 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.core.format; + +import io.cloudevents.CloudEvent; +import io.cloudevents.CloudEventData; +import io.cloudevents.rw.CloudEventDataMapper; + +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.Collections; +import java.util.Set; + +/** + *

A construct that aggregates a two-part identifier of file formats and format contents transmitted on the Internet. + * + *

The two parts of a {@code ContentType} are its type and a subtype; separated by a forward slash ({@code /}). + * + * @see io.cloudevents.core.format.EventFormat + */ +@ParametersAreNonnullByDefault +public enum ContentType { + + /** + * Content type associated with the CSV event format + */ + CSV("application/cloudevents+csv"), + /** + * Content type associated with the JSON event format + */ + JSON("application/cloudevents+json"), + /** + * The content type for transports sending cloudevents in the protocol buffer format. + */ + PROTO("application/cloudevents+protobuf"), + /** + * The content type to set for the "datacontenttype" attribute if the data is stored in protocol buffer format.> + * Note that if this content type is used, the stored data must be wrapped in {@link com.google.protobuf.Any} as specified by the protobuf format spec.> + */ + PROTO_DATA("application/protobuf"), + /** + * The content type for transports sending cloudevents in XML format. + */ + XML("application/cloudevents+xml"); + + private String value; + + private ContentType(String value) { this.value = value; } + + /** + * Return a string consisting of the slash-delimited ({@code /}) two-part identifier for this {@code enum} constant. + */ + public String value() { return value; } + + /** + * Return a string consisting of the slash-delimited ({@code /}) two-part identifier for this {@code enum} constant. + */ + @Override + public String toString() { return value(); } + +} diff --git a/core/src/main/java/io/cloudevents/core/provider/EventFormatProvider.java b/core/src/main/java/io/cloudevents/core/provider/EventFormatProvider.java index 96f3ad678..b27300a15 100644 --- a/core/src/main/java/io/cloudevents/core/provider/EventFormatProvider.java +++ b/core/src/main/java/io/cloudevents/core/provider/EventFormatProvider.java @@ -25,6 +25,7 @@ import javax.annotation.ParametersAreNonnullByDefault; +import io.cloudevents.core.format.ContentType; import io.cloudevents.core.format.EventFormat; import io.cloudevents.lang.Nullable; @@ -98,4 +99,16 @@ public EventFormat resolveFormat(String contentType) { return this.formats.get(contentType); } + /** + * Resolve an event format starting from the content type. + * + * @param contentType the content type to resolve the event format + * @return null if no format was found for the provided content type + */ + @Nullable + public EventFormat resolveFormat(ContentType contentType) { + return this.formats.get(contentType.value()); + } + + } diff --git a/core/src/test/java/io/cloudevents/core/provider/EventFormatProviderTest.java b/core/src/test/java/io/cloudevents/core/provider/EventFormatProviderTest.java index 90dca3bfb..2714baa90 100644 --- a/core/src/test/java/io/cloudevents/core/provider/EventFormatProviderTest.java +++ b/core/src/test/java/io/cloudevents/core/provider/EventFormatProviderTest.java @@ -20,6 +20,7 @@ import io.cloudevents.core.mock.CSVFormat; import org.junit.jupiter.api.Test; +import static io.cloudevents.core.format.ContentType.CSV; import static org.assertj.core.api.Assertions.assertThat; public class EventFormatProviderTest { @@ -41,4 +42,9 @@ void listTypes() { assertThat(EventFormatProvider.getInstance().getContentTypes()).hasSize(1); } + @Test + void resolveCSVUsingEnum() { + assertThat(EventFormatProvider.getInstance().resolveFormat(CSV)) + .isInstanceOf(CSVFormat.class); + } } diff --git a/docs/json-jackson.md b/docs/json-jackson.md index 6bb2a7c6a..823436f02 100644 --- a/docs/json-jackson.md +++ b/docs/json-jackson.md @@ -28,9 +28,9 @@ adding the dependency to your project: ```java import io.cloudevents.CloudEvent; +import io.cloudevents.core.format.ContentType; import io.cloudevents.core.format.EventFormatProvider; import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.jackson.JsonFormat; CloudEvent event = CloudEventBuilder.v1() .withId("hello") @@ -40,7 +40,7 @@ CloudEvent event = CloudEventBuilder.v1() byte[]serialized = EventFormatProvider .getInstance() - .resolveFormat(JsonFormat.CONTENT_TYPE) + .resolveFormat(ContentType.JSON) .serialize(event); ``` diff --git a/docs/protobuf.md b/docs/protobuf.md index d67a0d708..6a49ec86b 100644 --- a/docs/protobuf.md +++ b/docs/protobuf.md @@ -30,9 +30,9 @@ No further configuration is required is use the module. ```java import io.cloudevents.CloudEvent; +import io.cloudevents.core.format.ContentType; import io.cloudevents.core.format.EventFormatProvider; import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.protobuf.ProtobufFormat; CloudEvent event = CloudEventBuilder.v1() .withId("hello") @@ -42,7 +42,7 @@ CloudEvent event = CloudEventBuilder.v1() byte[]serialized = EventFormatProvider .getInstance() - .resolveFormat(ProtobufFormat.CONTENT_TYPE) + .resolveFormat(ContentType.PROTO) .serialize(event); ``` diff --git a/docs/xml.md b/docs/xml.md index 6d0640157..8e365ac1f 100644 --- a/docs/xml.md +++ b/docs/xml.md @@ -29,9 +29,9 @@ adding the dependency to your project: ```java import io.cloudevents.CloudEvent; +import io.cloudevents.core.format.ContentType; import io.cloudevents.core.format.EventFormatProvider; import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.xml.XMLFormat; CloudEvent event = CloudEventBuilder.v1() .withId("hello") @@ -41,7 +41,7 @@ CloudEvent event = CloudEventBuilder.v1() byte[] serialized = EventFormatProvider .getInstance() - .resolveFormat(XMLFormat.CONTENT_TYPE) + .resolveFormat(ContentType.XML) .serialize(event); ``` diff --git a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java index 542405894..02254482c 100644 --- a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java +++ b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java @@ -22,6 +22,7 @@ import io.cloudevents.CloudEvent; import io.cloudevents.CloudEventData; import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.core.format.ContentType; import io.cloudevents.core.format.EventDeserializationException; import io.cloudevents.core.format.EventFormat; import io.cloudevents.core.format.EventSerializationException; @@ -220,4 +221,9 @@ static boolean dataIsJsonContentType(String contentType) { // If content type, spec states that we should assume is json return contentType == null || JSON_CONTENT_TYPE_PATTERN.matcher(contentType).matches(); } + + static boolean dataIsJsonContentType(ContentType contentType) { + // If content type, spec states that we should assume is json + return dataIsJsonContentType(contentType.value()); + } } diff --git a/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java b/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java index f82d25926..9f3e14f42 100644 --- a/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java +++ b/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java @@ -24,6 +24,7 @@ import io.cloudevents.CloudEvent; import io.cloudevents.SpecVersion; import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.core.format.ContentType; import io.cloudevents.core.format.EventDeserializationException; import io.cloudevents.core.provider.EventFormatProvider; import io.cloudevents.rw.CloudEventRWException; @@ -40,6 +41,7 @@ import java.util.Objects; import java.util.stream.Stream; +import static io.cloudevents.core.format.ContentType.*; import static io.cloudevents.core.test.Data.*; import static org.assertj.core.api.Assertions.*; @@ -55,6 +57,14 @@ void isJsonContentType(String contentType) { assertThat(json).isTrue(); } + @ParameterizedTest + @MethodSource("jsonContentTypesEnum") + void isJsonContentType(ContentType contentType) { + boolean json = JsonFormat.dataIsJsonContentType(contentType); + + assertThat(json).isTrue(); + } + @ParameterizedTest @MethodSource("wrongJsonContentTypes") void isNotJsonContentType(String contentType) { @@ -63,6 +73,14 @@ void isNotJsonContentType(String contentType) { assertThat(json).isFalse(); } + @ParameterizedTest + @MethodSource("wrongJsonContentTypesEnums") + void isNotJsonContentType(ContentType contentType) { + boolean json = JsonFormat.dataIsJsonContentType(contentType); + + assertThat(json).isFalse(); + } + @ParameterizedTest @MethodSource("serializeTestArgumentsDefault") void serialize(CloudEvent input, String outputFile) throws IOException { @@ -185,7 +203,16 @@ static Stream jsonContentTypes() { //https://www.rfc-editor.org/rfc/rfc2045#section-5.1 // any us-ascii char can be part of parameters (except CTRLs and tspecials) Arguments.of("text/json; char-set = $!#$%&'*+.^_`|"), - Arguments.of((Object) null) + Arguments.of((Object) null), + Arguments.of(JSON + ""), + Arguments.of(JSON.value()), + Arguments.of(JSON.toString()) + ); + } + + static Stream jsonContentTypesEnum() { + return Stream.of( + Arguments.of(JSON) ); } @@ -200,6 +227,16 @@ static Stream wrongJsonContentTypes() { ); } + static Stream wrongJsonContentTypesEnums() { + return Stream.of( + Arguments.of(CSV), + Arguments.of(PROTO), + Arguments.of(PROTO_DATA), + Arguments.of(XML) + ); + } + + public static Stream serializeTestArgumentsDefault() { return Stream.of( Arguments.of(V03_MIN, "v03/min.json"), @@ -307,7 +344,7 @@ public static Stream badJsonContent() { } private JsonFormat getFormat() { - return (JsonFormat) EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE); + return (JsonFormat) EventFormatProvider.getInstance().resolveFormat(JSON); } private static byte[] loadFile(String input) { From 6172b078e191e7c02e5a14596bb1b481ea087279 Mon Sep 17 00:00:00 2001 From: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> Date: Thu, 23 Mar 2023 17:30:05 +0000 Subject: [PATCH 2/8] 537-refactor-facilitate-decoupling-eventformat-impls-2 Signed-off-by: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> --- .../main/java/io/cloudevents/core/format/ContentType.java | 7 ++----- .../test/java/io/cloudevents/jackson/JsonFormatTest.java | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/io/cloudevents/core/format/ContentType.java b/core/src/main/java/io/cloudevents/core/format/ContentType.java index 158c70b9a..6145ecd4f 100644 --- a/core/src/main/java/io/cloudevents/core/format/ContentType.java +++ b/core/src/main/java/io/cloudevents/core/format/ContentType.java @@ -30,6 +30,8 @@ * *

The two parts of a {@code ContentType} are its type and a subtype; separated by a forward slash ({@code /}). * + *

The constants enumerated by {@code ContentType} correspond only to the specialized formats supported by the Java™ SDK for CloudEvents. + * * @see io.cloudevents.core.format.EventFormat */ @ParametersAreNonnullByDefault @@ -47,11 +49,6 @@ public enum ContentType { * The content type for transports sending cloudevents in the protocol buffer format. */ PROTO("application/cloudevents+protobuf"), - /** - * The content type to set for the "datacontenttype" attribute if the data is stored in protocol buffer format.> - * Note that if this content type is used, the stored data must be wrapped in {@link com.google.protobuf.Any} as specified by the protobuf format spec.> - */ - PROTO_DATA("application/protobuf"), /** * The content type for transports sending cloudevents in XML format. */ diff --git a/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java b/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java index 9f3e14f42..82060f627 100644 --- a/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java +++ b/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java @@ -231,7 +231,6 @@ static Stream wrongJsonContentTypesEnums() { return Stream.of( Arguments.of(CSV), Arguments.of(PROTO), - Arguments.of(PROTO_DATA), Arguments.of(XML) ); } From 8536604894e703ac3fb68873e22a3a69aecb6cb9 Mon Sep 17 00:00:00 2001 From: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> Date: Sat, 1 Apr 2023 18:15:02 +0100 Subject: [PATCH 3/8] 537-refactor-facilitate-decoupling-eventformat-impls-3 Signed-off-by: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> --- .../main/java/io/cloudevents/core/format/ContentType.java | 4 ---- .../cloudevents/core/provider/EventFormatProviderTest.java | 6 ------ .../src/main/java/io/cloudevents/jackson/JsonFormat.java | 2 +- .../main/java/io/cloudevents/protobuf/ProtobufFormat.java | 3 ++- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/io/cloudevents/core/format/ContentType.java b/core/src/main/java/io/cloudevents/core/format/ContentType.java index 6145ecd4f..1d8656393 100644 --- a/core/src/main/java/io/cloudevents/core/format/ContentType.java +++ b/core/src/main/java/io/cloudevents/core/format/ContentType.java @@ -37,10 +37,6 @@ @ParametersAreNonnullByDefault public enum ContentType { - /** - * Content type associated with the CSV event format - */ - CSV("application/cloudevents+csv"), /** * Content type associated with the JSON event format */ diff --git a/core/src/test/java/io/cloudevents/core/provider/EventFormatProviderTest.java b/core/src/test/java/io/cloudevents/core/provider/EventFormatProviderTest.java index 2714baa90..90dca3bfb 100644 --- a/core/src/test/java/io/cloudevents/core/provider/EventFormatProviderTest.java +++ b/core/src/test/java/io/cloudevents/core/provider/EventFormatProviderTest.java @@ -20,7 +20,6 @@ import io.cloudevents.core.mock.CSVFormat; import org.junit.jupiter.api.Test; -import static io.cloudevents.core.format.ContentType.CSV; import static org.assertj.core.api.Assertions.assertThat; public class EventFormatProviderTest { @@ -42,9 +41,4 @@ void listTypes() { assertThat(EventFormatProvider.getInstance().getContentTypes()).hasSize(1); } - @Test - void resolveCSVUsingEnum() { - assertThat(EventFormatProvider.getInstance().resolveFormat(CSV)) - .isInstanceOf(CSVFormat.class); - } } diff --git a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java index 02254482c..c40dffb67 100644 --- a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java +++ b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java @@ -44,7 +44,7 @@ public final class JsonFormat implements EventFormat { /** * Content type associated with the JSON event format */ - public static final String CONTENT_TYPE = "application/cloudevents+json"; + public static final String CONTENT_TYPE = ContentType.JSON.value(); /** * JSON Data Content Type Discriminator */ diff --git a/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtobufFormat.java b/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtobufFormat.java index 0d3b65d4e..74b234d4d 100644 --- a/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtobufFormat.java +++ b/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtobufFormat.java @@ -20,6 +20,7 @@ import io.cloudevents.CloudEvent; import io.cloudevents.CloudEventData; import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.core.format.ContentType; import io.cloudevents.core.format.EventDeserializationException; import io.cloudevents.core.format.EventFormat; import io.cloudevents.core.format.EventSerializationException; @@ -38,7 +39,7 @@ public class ProtobufFormat implements EventFormat { /** * The content type for transports sending cloudevents in the protocol buffer format. */ - public static final String PROTO_CONTENT_TYPE = "application/cloudevents+protobuf"; + public static final String PROTO_CONTENT_TYPE = ContentType.PROTO.value(); /** * The content type to set for the "datacontenttype" attribute if the data is stored in protocol buffer format. * Note that if this content type is used, the stored data must be wrapped in {@link com.google.protobuf.Any} as specified by the protobuf format spec. From e1dbe9c4329c79e940d45993ed22e618b771d367 Mon Sep 17 00:00:00 2001 From: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> Date: Sat, 1 Apr 2023 18:30:01 +0100 Subject: [PATCH 4/8] 537-refactor-facilitate-decoupling-eventformat-impls-3 Signed-off-by: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> --- formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java b/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java index 996f07cf3..2802bda3d 100644 --- a/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java +++ b/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java @@ -19,6 +19,7 @@ import io.cloudevents.CloudEvent; import io.cloudevents.CloudEventData; import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.core.format.ContentType; import io.cloudevents.core.format.EventDeserializationException; import io.cloudevents.core.format.EventFormat; import io.cloudevents.core.format.EventSerializationException; @@ -38,7 +39,7 @@ public class XMLFormat implements EventFormat { /** * The content type for transports sending cloudevents in XML format. */ - public static final String XML_CONTENT_TYPE = "application/cloudevents+xml"; + public static final String XML_CONTENT_TYPE = ContentType.XML.value(); @Override public byte[] serialize(CloudEvent event) throws EventSerializationException { From 4082dd33cec794dec8a36ec74da9b9f35e4031e7 Mon Sep 17 00:00:00 2001 From: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:00:02 +0100 Subject: [PATCH 5/8] 537-refactor-facilitate-decoupling-eventformat-impls-4 Signed-off-by: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> --- .../io/cloudevents/jackson/JsonFormat.java | 5 --- .../cloudevents/jackson/JsonFormatTest.java | 31 ------------------- 2 files changed, 36 deletions(-) diff --git a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java index c40dffb67..4a615c98e 100644 --- a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java +++ b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java @@ -221,9 +221,4 @@ static boolean dataIsJsonContentType(String contentType) { // If content type, spec states that we should assume is json return contentType == null || JSON_CONTENT_TYPE_PATTERN.matcher(contentType).matches(); } - - static boolean dataIsJsonContentType(ContentType contentType) { - // If content type, spec states that we should assume is json - return dataIsJsonContentType(contentType.value()); - } } diff --git a/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java b/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java index 82060f627..59c2d70c0 100644 --- a/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java +++ b/formats/json-jackson/src/test/java/io/cloudevents/jackson/JsonFormatTest.java @@ -57,14 +57,6 @@ void isJsonContentType(String contentType) { assertThat(json).isTrue(); } - @ParameterizedTest - @MethodSource("jsonContentTypesEnum") - void isJsonContentType(ContentType contentType) { - boolean json = JsonFormat.dataIsJsonContentType(contentType); - - assertThat(json).isTrue(); - } - @ParameterizedTest @MethodSource("wrongJsonContentTypes") void isNotJsonContentType(String contentType) { @@ -73,14 +65,6 @@ void isNotJsonContentType(String contentType) { assertThat(json).isFalse(); } - @ParameterizedTest - @MethodSource("wrongJsonContentTypesEnums") - void isNotJsonContentType(ContentType contentType) { - boolean json = JsonFormat.dataIsJsonContentType(contentType); - - assertThat(json).isFalse(); - } - @ParameterizedTest @MethodSource("serializeTestArgumentsDefault") void serialize(CloudEvent input, String outputFile) throws IOException { @@ -210,12 +194,6 @@ static Stream jsonContentTypes() { ); } - static Stream jsonContentTypesEnum() { - return Stream.of( - Arguments.of(JSON) - ); - } - static Stream wrongJsonContentTypes() { return Stream.of( Arguments.of("applications/json"), @@ -227,15 +205,6 @@ static Stream wrongJsonContentTypes() { ); } - static Stream wrongJsonContentTypesEnums() { - return Stream.of( - Arguments.of(CSV), - Arguments.of(PROTO), - Arguments.of(XML) - ); - } - - public static Stream serializeTestArgumentsDefault() { return Stream.of( Arguments.of(V03_MIN, "v03/min.json"), From f1fd00db1e2491c6cd77bdafa041684af21e7619 Mon Sep 17 00:00:00 2001 From: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> Date: Tue, 11 Apr 2023 18:45:31 +0100 Subject: [PATCH 6/8] 537-refactor-facilitate-decoupling-eventformat-impls-5 Signed-off-by: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> --- .../src/main/java/io/cloudevents/jackson/JsonFormat.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java index 4a615c98e..d73edbdf9 100644 --- a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java +++ b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java @@ -44,7 +44,7 @@ public final class JsonFormat implements EventFormat { /** * Content type associated with the JSON event format */ - public static final String CONTENT_TYPE = ContentType.JSON.value(); + public static final String CONTENT_TYPE = "application/cloudevents+json"; /** * JSON Data Content Type Discriminator */ From a46f90be06c6729812e55df505b52946a8fa6522 Mon Sep 17 00:00:00 2001 From: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> Date: Wed, 12 Apr 2023 19:15:08 +0100 Subject: [PATCH 7/8] 537-refactor-facilitate-decoupling-eventformat-impls-6 Signed-off-by: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> --- .../src/main/java/io/cloudevents/protobuf/ProtobufFormat.java | 2 +- formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtobufFormat.java b/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtobufFormat.java index 74b234d4d..170d92f20 100644 --- a/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtobufFormat.java +++ b/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtobufFormat.java @@ -39,7 +39,7 @@ public class ProtobufFormat implements EventFormat { /** * The content type for transports sending cloudevents in the protocol buffer format. */ - public static final String PROTO_CONTENT_TYPE = ContentType.PROTO.value(); + public static final String PROTO_CONTENT_TYPE = "application/cloudevents+protobuf"; /** * The content type to set for the "datacontenttype" attribute if the data is stored in protocol buffer format. * Note that if this content type is used, the stored data must be wrapped in {@link com.google.protobuf.Any} as specified by the protobuf format spec. diff --git a/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java b/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java index 2802bda3d..d0e4c0bc7 100644 --- a/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java +++ b/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java @@ -39,7 +39,7 @@ public class XMLFormat implements EventFormat { /** * The content type for transports sending cloudevents in XML format. */ - public static final String XML_CONTENT_TYPE = ContentType.XML.value(); + public static final String XML_CONTENT_TYPE = "application/cloudevents+xml"; @Override public byte[] serialize(CloudEvent event) throws EventSerializationException { From d431537afb119717e26a63e9bd70a7f6190eb610 Mon Sep 17 00:00:00 2001 From: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> Date: Wed, 12 Apr 2023 19:50:18 +0100 Subject: [PATCH 8/8] 537-refactor-facilitate-decoupling-eventformat-impls-6' Signed-off-by: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com> --- .../java/io/cloudevents/core/provider/EventFormatProvider.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/io/cloudevents/core/provider/EventFormatProvider.java b/core/src/main/java/io/cloudevents/core/provider/EventFormatProvider.java index b27300a15..d961d2f85 100644 --- a/core/src/main/java/io/cloudevents/core/provider/EventFormatProvider.java +++ b/core/src/main/java/io/cloudevents/core/provider/EventFormatProvider.java @@ -109,6 +109,4 @@ public EventFormat resolveFormat(String contentType) { public EventFormat resolveFormat(ContentType contentType) { return this.formats.get(contentType.value()); } - - }