diff --git a/.github/workflows/branch.yaml b/.github/workflows/branch.yaml index 3a93cbb55..c167f0c66 100644 --- a/.github/workflows/branch.yaml +++ b/.github/workflows/branch.yaml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ 8, 11, 17 ] + java: [ 17, 21, 25 ] steps: - uses: actions/checkout@v2 - name: Setup java @@ -33,7 +33,7 @@ jobs: - name: Setup java uses: actions/setup-java@v1 with: - java-version: 8 + java-version: 17 server-id: central # Value of the distributionManagement/repository/id field of the pom.xml server-username: MAVEN_USERNAME # env variable for username in deploy server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy @@ -45,4 +45,3 @@ jobs: MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }} MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} - diff --git a/.github/workflows/bump.yaml b/.github/workflows/bump.yaml index b0e288f78..479643902 100644 --- a/.github/workflows/bump.yaml +++ b/.github/workflows/bump.yaml @@ -25,7 +25,7 @@ jobs: - name: Setup java uses: actions/setup-java@v1 with: - java-version: 8 + java-version: 17 - name: Bump version using Maven if: ${{ inputs.maven-modules == 'true' }} run: './mvnw versions:set -DnewVersion=$NEW_VERSION -DgenerateBackupPoms=false -B' @@ -44,4 +44,3 @@ jobs: This PR performs the bump of the SDK to ${{ github.event.inputs.version }}. This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request). - diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index d20d884c1..fd5290cd6 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ 8, 11, 17 ] + java: [ 17, 21, 25 ] name: Java ${{ matrix.java }} Test steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index eac746de7..d7878e73d 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,6 @@ Supported features of the specification: | AVRO Event Format | :x: | :x: | | HTTP Protocol Binding | :heavy_check_mark: | :heavy_check_mark: | | - [Vert.x](http/vertx) | :heavy_check_mark: | :heavy_check_mark: | -| - [Jakarta EE 8 Restful WS](http/restful-ws) | :heavy_check_mark: | :heavy_check_mark: | | - [Jakarta EE 9+ Restful WS](http/restful-ws-jakarta) | :heavy_check_mark: | :heavy_check_mark: | | - [Basic](http/basic) | :heavy_check_mark: | :heavy_check_mark: | | - [Spring](spring) | :heavy_check_mark: | :heavy_check_mark: | @@ -69,7 +68,6 @@ Javadocs are available on [javadoc.io](https://www.javadoc.io): - [cloudevents-protobuf](https://www.javadoc.io/doc/io.cloudevents/cloudevents-protobuf) - [cloudevents-xml](https://www.javadoc.io/doc/io.cloudevents/cloudevents-xml) - [cloudevents-http-basic](https://www.javadoc.io/doc/io.cloudevents/cloudevents-http-basic) -- [cloudevents-http-restful-ws](https://www.javadoc.io/doc/io.cloudevents/cloudevents-http-restful-ws) - [cloudevents-http-restful-ws-jakarta](https://www.javadoc.io/doc/io.cloudevents/cloudevents-http-restful-ws-jakarta) - [cloudevents-http-vertx](https://www.javadoc.io/doc/io.cloudevents/cloudevents-http-vertx) - [cloudevents-kafka](https://www.javadoc.io/doc/io.cloudevents/cloudevents-kafka) diff --git a/amqp/src/main/java/io/cloudevents/amqp/impl/AmqpConstants.java b/amqp/src/main/java/io/cloudevents/amqp/impl/AmqpConstants.java index dc61ce71f..c865ba08f 100644 --- a/amqp/src/main/java/io/cloudevents/amqp/impl/AmqpConstants.java +++ b/amqp/src/main/java/io/cloudevents/amqp/impl/AmqpConstants.java @@ -110,11 +110,9 @@ public static byte[] getPayloadAsByteArray(final Section payload) { return null; } - if (payload instanceof Data) { - final Data body = (Data) payload; + if (payload instanceof Data body) { return body.getValue().getArray(); - } else if (payload instanceof AmqpValue) { - final AmqpValue body = (AmqpValue) payload; + } else if (payload instanceof AmqpValue body) { if (body.getValue() instanceof byte[]) { return (byte[]) body.getValue(); } else if (body.getValue() instanceof String && diff --git a/amqp/src/test/java/io/cloudevents/amqp/ProtonAmqpMessageFactoryTest.java b/amqp/src/test/java/io/cloudevents/amqp/ProtonAmqpMessageFactoryTest.java index d76aef477..390b0f854 100644 --- a/amqp/src/test/java/io/cloudevents/amqp/ProtonAmqpMessageFactoryTest.java +++ b/amqp/src/test/java/io/cloudevents/amqp/ProtonAmqpMessageFactoryTest.java @@ -228,7 +228,7 @@ private static Stream binaryTestArguments() { private static final SimpleEntry property(final String name, final Object value) { return name.equalsIgnoreCase("ignored") ? new SimpleEntry<>(name, value) : - new SimpleEntry<>(String.format(PREFIX_TEMPLATE, name), value); + new SimpleEntry<>(PREFIX_TEMPLATE.formatted(name), value); } @SafeVarargs diff --git a/amqp/src/test/java/io/cloudevents/amqp/ProtonAmqpMessageWriterTest.java b/amqp/src/test/java/io/cloudevents/amqp/ProtonAmqpMessageWriterTest.java index a5a55c2ee..73ae18419 100644 --- a/amqp/src/test/java/io/cloudevents/amqp/ProtonAmqpMessageWriterTest.java +++ b/amqp/src/test/java/io/cloudevents/amqp/ProtonAmqpMessageWriterTest.java @@ -116,7 +116,7 @@ private Message translateStructured(final CloudEvent event, final EventFormat fo } private void addProperty(final Map map, final String name, final String value, final boolean prefix) { if (prefix) { - map.put(String.format("cloudEvents:%s", name), value); + map.put("cloudEvents:%s".formatted(name), value); } else { map.put(name, value); } diff --git a/api/src/main/java/io/cloudevents/rw/CloudEventContextWriter.java b/api/src/main/java/io/cloudevents/rw/CloudEventContextWriter.java index e0b6101d8..0ee331fb1 100644 --- a/api/src/main/java/io/cloudevents/rw/CloudEventContextWriter.java +++ b/api/src/main/java/io/cloudevents/rw/CloudEventContextWriter.java @@ -85,8 +85,9 @@ default CloudEventContextWriter withContextAttribute(String name, OffsetDateTime * @throws IllegalArgumentException if you're trying to set the specversion attribute. * * @deprecated CloudEvent specification only permits {@link Integer} type as a - * numeric value. + * numeric value. Use {@link #withContextAttribute(String, Integer)} instead. */ + @Deprecated default CloudEventContextWriter withContextAttribute(String name, Number value) throws CloudEventRWException { return withContextAttribute(name, value.toString()); } @@ -122,7 +123,7 @@ default CloudEventContextWriter withContextAttribute(String name, Boolean value) } /** - * Set attribute with a binary type. + * Set the attribute with a binary type. * This setter should not be invoked for specversion, because the writer should * already know the specversion or because it doesn't need it to correctly write the value. * diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index aee054145..80f4ac1ae 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -31,7 +31,6 @@ UTF-8 1.23 - 1.8 benchmarks true @@ -80,16 +79,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.15.0 - - ${javac.target} - ${javac.target} - ${javac.target} - - org.apache.maven.plugins maven-shade-plugin @@ -135,6 +124,10 @@ maven-clean-plugin 3.5.0 + + maven-compiler-plugin + 3.15.0 + maven-deploy-plugin 3.1.4 diff --git a/benchmarks/src/main/java/io/cloudevents/bench/kafka/KafkaConsumerMessageToCloudEventBenchmark.java b/benchmarks/src/main/java/io/cloudevents/bench/kafka/KafkaConsumerMessageToCloudEventBenchmark.java index 8c9fd7a69..e31a8dde4 100644 --- a/benchmarks/src/main/java/io/cloudevents/bench/kafka/KafkaConsumerMessageToCloudEventBenchmark.java +++ b/benchmarks/src/main/java/io/cloudevents/bench/kafka/KafkaConsumerMessageToCloudEventBenchmark.java @@ -25,6 +25,8 @@ import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; +import java.util.Optional; + import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT; public class KafkaConsumerMessageToCloudEventBenchmark { @@ -45,12 +47,12 @@ public BinaryMessage() { 0, 0, TimestampType.NO_TIMESTAMP_TYPE, - -1L, ConsumerRecord.NULL_SIZE, ConsumerRecord.NULL_SIZE, "aaa", inRecord.value(), - inRecord.headers() + inRecord.headers(), + Optional.empty() ); } } @@ -81,12 +83,12 @@ public StructuredJsonMessage() { 0, 0, TimestampType.NO_TIMESTAMP_TYPE, - -1L, ConsumerRecord.NULL_SIZE, ConsumerRecord.NULL_SIZE, "aaa", inRecord.value(), - inRecord.headers() + inRecord.headers(), + Optional.empty() ); } } diff --git a/bom/pom.xml b/bom/pom.xml index 8acec8291..a86d29047 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -66,11 +66,6 @@ cloudevents-http-vertx ${project.version} - - io.cloudevents - cloudevents-http-restful-ws - ${project.version} - io.cloudevents cloudevents-kafka diff --git a/core/src/main/java/io/cloudevents/core/CloudEventUtils.java b/core/src/main/java/io/cloudevents/core/CloudEventUtils.java index 92de5591c..8b3ac6a5c 100644 --- a/core/src/main/java/io/cloudevents/core/CloudEventUtils.java +++ b/core/src/main/java/io/cloudevents/core/CloudEventUtils.java @@ -46,8 +46,8 @@ private CloudEventUtils() {} * @return the reader implementation */ public static CloudEventReader toReader(CloudEvent event) { - if (event instanceof CloudEventReader) { - return (CloudEventReader) event; + if (event instanceof CloudEventReader reader) { + return reader; } else { return new CloudEventReaderAdapter(event); } @@ -63,8 +63,8 @@ public static CloudEventReader toReader(CloudEvent event) { * @return the context reader implementation */ public static CloudEventContextReader toContextReader(CloudEventContext event) { - if (event instanceof CloudEventContextReader) { - return (CloudEventContextReader) event; + if (event instanceof CloudEventContextReader reader) { + return reader; } else { return new CloudEventContextReaderAdapter(event); } diff --git a/core/src/main/java/io/cloudevents/core/data/BytesCloudEventData.java b/core/src/main/java/io/cloudevents/core/data/BytesCloudEventData.java index c6df2974b..b67eb2730 100644 --- a/core/src/main/java/io/cloudevents/core/data/BytesCloudEventData.java +++ b/core/src/main/java/io/cloudevents/core/data/BytesCloudEventData.java @@ -16,6 +16,7 @@ public class BytesCloudEventData implements CloudEventData { * @param value the bytes to wrap * @deprecated use {@link BytesCloudEventData#wrap(byte[])} */ + @Deprecated public BytesCloudEventData(byte[] value) { Objects.requireNonNull(value); this.value = value; diff --git a/core/src/main/java/io/cloudevents/core/impl/CloudEventContextReaderAdapter.java b/core/src/main/java/io/cloudevents/core/impl/CloudEventContextReaderAdapter.java index 5d537a1e3..b2dd6cbcf 100644 --- a/core/src/main/java/io/cloudevents/core/impl/CloudEventContextReaderAdapter.java +++ b/core/src/main/java/io/cloudevents/core/impl/CloudEventContextReaderAdapter.java @@ -52,21 +52,21 @@ public void readAttributes(CloudEventContextWriter writer) throws RuntimeExcepti } public void readExtensions(CloudEventContextWriter writer) throws RuntimeException { - for (String key : event.getExtensionNames()) { - Object value = event.getExtension(key); - if (value instanceof String) { - writer.withContextAttribute(key, (String) value); - } else if (value instanceof Number) { - writer.withContextAttribute(key, (Number) value); - } else if (value instanceof Boolean) { - writer.withContextAttribute(key, (Boolean) value); - } else if (value instanceof URI) { - writer.withContextAttribute(key, (URI) value); - } else if (value instanceof OffsetDateTime) { - writer.withContextAttribute(key, (OffsetDateTime) value); + for (String extensionName : event.getExtensionNames()) { + Object value = event.getExtension(extensionName); + if (value instanceof String string) { + writer.withContextAttribute(extensionName, string); + } else if (value instanceof Number number) { + writer.withContextAttribute(extensionName, number); + } else if (value instanceof Boolean bool) { + writer.withContextAttribute(extensionName, bool); + } else if (value instanceof URI uri) { + writer.withContextAttribute(extensionName, uri); + } else if (value instanceof OffsetDateTime time) { + writer.withContextAttribute(extensionName, time); } else { // This should never happen because we build that map only through our builders - throw new IllegalStateException("Illegal value inside extensions map: " + key + " " + value); + throw new IllegalStateException("Illegal value inside extensions map: " + extensionName + " " + value); } } } diff --git a/core/src/test/java/io/cloudevents/core/test/Data.java b/core/src/test/java/io/cloudevents/core/test/Data.java index 268726151..1acab4d44 100644 --- a/core/src/test/java/io/cloudevents/core/test/Data.java +++ b/core/src/test/java/io/cloudevents/core/test/Data.java @@ -125,7 +125,7 @@ public class Data { .withExtension("integer", 42) .withExtension("decimal", new BigDecimal("42.42")) .withExtension("float", 4.2f) - .withExtension("long", new Long(4200)) + .withExtension("long", Long.valueOf(4200)) .build(); public static final CloudEvent V03_MIN = CloudEventBuilder.v03(V1_MIN).build(); diff --git a/docs/http-basic.md b/docs/http-basic.md index a971eea6e..20a3a9c1a 100644 --- a/docs/http-basic.md +++ b/docs/http-basic.md @@ -12,7 +12,6 @@ This module is designed to be usable with various HTTP APIs. There are also more specialized HTTP bindings: - [`cloudevents-http-vertx`](http-vertx.md) -- [`cloudevents-http-restful-ws`](http-jakarta-restful-ws.md) (deprecated, please use `cloudevents-http-restful-ws-jakarta`) - [`cloudevents-http-restful-ws-jakarta`](http-jakarta-restful-ws-jakarta.md) - [`cloudevents-spring`](spring.md) diff --git a/docs/http-jakarta-restful-ws.md b/docs/http-jakarta-restful-ws.md deleted file mode 100644 index 9800365bd..000000000 --- a/docs/http-jakarta-restful-ws.md +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: CloudEvents HTTP Jakarta RESTful Web Services -nav_order: 5 ---- - -# HTTP Protocol Binding for Jakarta EE 8 - RESTful Web Services - -This module is deprecated and will be removed in version 5.0. -Please migrate to Jakarta EE 9+ and use the `cloudevents-http-restful-ws-jakarta` module instead. - -[![Javadocs](http://www.javadoc.io/badge/io.cloudevents/cloudevents-http-restful-ws.svg?color=green)](http://www.javadoc.io/doc/io.cloudevents/cloudevents-http-restful-ws) - -For Maven-based projects, use the following to configure the CloudEvents Jakarta -RESTful Web Services Binding for Jakarta EE 8: - -```xml - - io.cloudevents - cloudevents-http-restful-ws - 4.1.1 - -``` - -This integration is tested with Jersey, RestEasy & Spring Boot Jersey. - -## Receiving CloudEvents - -You need to configure the `CloudEventsProvider` to enable -marshalling/unmarshalling of CloudEvents. - -Below is a sample on how to read and write CloudEvents: - -```java -import io.cloudevents.CloudEvent; -import io.cloudevents.core.builder.CloudEventBuilder; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.core.Response; - -@Path("/") -public class EventReceiverResource { - - @GET - @Path("getMinEvent") - public CloudEvent getMinEvent() { - return CloudEventBuilder.v1() - .withId("hello") - .withType("example.vertx") - .withSource(URI.create("http://localhost")) - .build(); - } - - // Return the CloudEvent using the HTTP binding structured encoding - @GET - @Path("getStructuredEvent") - @StructuredEncoding("application/cloudevents+csv") - public CloudEvent getStructuredEvent() { - return CloudEventBuilder.v1() - .withId("hello") - .withType("example.vertx") - .withSource(URI.create("http://localhost")) - .build(); - } - - @POST - @Path("postEventWithoutBody") - public Response postEvent(CloudEvent inputEvent) { - // Handle the event - return Response.ok().build(); - } -} -``` - -## Sending CloudEvents - -You need to configure the `CloudEventsProvider` to enable -marshalling/unmarshalling of CloudEvents. - -Below is a sample on how to use the client to send a CloudEvent: - -```java -import io.cloudevents.CloudEvent; -import io.cloudevents.http.restful.ws.CloudEventsProvider; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; - -public class CloudEventSender { - - public Response sendEvent(WebTarget target, CloudEvent event) { - return target - .path("postEvent") - .request() - .buildPost(Entity.entity(event, CloudEventsProvider.CLOUDEVENT_TYPE)) - .invoke(); - } - - public Response sendEventAsStructured(WebTarget target, CloudEvent event) { - return target - .path("postEvent") - .request() - .buildPost(Entity.entity(event, "application/cloudevents+json")) - .invoke(); - } - - public CloudEvent getEvent(WebTarget target) { - Response response = target - .path("getEvent") - .request() - .buildGet() - .invoke(); - - return response.readEntity(CloudEvent.class); - } -} -``` - -## Examples - -- [Quarkus and Resteasy](https://github.com/cloudevents/sdk-java/tree/main/examples/restful-ws-quarkus) -- [Jersey and Spring Boot](https://github.com/cloudevents/sdk-java/tree/main/examples/restful-ws-spring-boot) diff --git a/docs/index.md b/docs/index.md index c6f93f384..34eaf6ef5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -34,7 +34,6 @@ Using the Java SDK you can: | AVRO Event Format | :x: | :x: | | HTTP Protocol Binding | :heavy_check_mark: | :heavy_check_mark: | | - [Vert.x](http-vertx.md) | :heavy_check_mark: | :heavy_check_mark: | -| - [Jakarta EE 8 Restful WS](http-jakarta-restful-ws.md) | :heavy_check_mark: | :heavy_check_mark: | | - [Jakarta EE 9+ Restful WS](http-jakarta-restful-ws-jakarta.md) | :heavy_check_mark: | :heavy_check_mark: | | - [Basic](http-basic.md) | :heavy_check_mark: | :heavy_check_mark: | | - [Spring](spring.md) | :heavy_check_mark: | :heavy_check_mark: | @@ -65,7 +64,6 @@ receive CloudEvents, check out the dedicated pages: - [AMQP using Proton](amqp-proton.md) - [HTTP using Vert.x](http-vertx.md) -- [HTTP using Jakarta EE 8 - Jakarta Restful WS](http-jakarta-restful-ws.md) - [HTTP using Jakarta EE 9+ - Jakarta Restful WS](http-jakarta-restful-ws-jakarta.md) - [HTTP using Spring](spring.md) - [HTTP using Jackson](json-jackson.md) @@ -102,8 +100,6 @@ a different feature from the different sub specs of - [`cloudevents-xml`] Implementation of the XML Event Format. - [`cloudevents-http-vertx`] Implementation of [HTTP Protocol Binding] with [Vert.x Core](https://vertx.io/) -- [`cloudevents-http-restful-ws`] Implementation of [HTTP Protocol Binding] - for [Jakarta EE 8 Restful WS](https://jakarta.ee/specifications/restful-ws/2.1/) (deprecated, please use `cloudevents-http-restful-ws-jakarta`) - [`cloudevents-http-restful-ws-jakarta`] Implementation of [HTTP Protocol Binding] for [Jakarta EE 9+ Restful WS](https://jakarta.ee/specifications/restful-ws/) - [`cloudevents-http-basic`] Generic implementation of [HTTP Protocol @@ -130,7 +126,6 @@ You can look at the latest published artifacts on [`cloudevents-xml`]: https://github.com/cloudevents/sdk-java/tree/main/formats/xml [`cloudevents-http-vertx`]: https://github.com/cloudevents/sdk-java/tree/main/http/vertx [`cloudevents-http-basic`]: https://github.com/cloudevents/sdk-java/tree/main/http/basic -[`cloudevents-http-restful-ws`]: https://github.com/cloudevents/sdk-java/tree/main/http/restful-ws [`cloudevents-http-restful-ws-jakarta`]: https://github.com/cloudevents/sdk-java/tree/main/http/restful-ws-jakarta [`cloudevents-kafka`]: https://github.com/cloudevents/sdk-java/tree/main/kafka [`cloudevents-amqp-proton`]: https://github.com/cloudevents/sdk-java/tree/main/amqp diff --git a/examples/README.md b/examples/README.md index bee7031cd..7953e48d4 100644 --- a/examples/README.md +++ b/examples/README.md @@ -7,10 +7,10 @@ This directory includes some examples on how to use CloudEvents sdk-java: - [kafka](kafka) shows how to use the module `cloudevents-kafka` to produce and consume CloudEvents on Kafka topics. - [restful-ws-quarkus](restful-ws-quarkus) shows how to use the module - `cloudevents-http-restful-ws` with Quarkus to receive and send CloudEvents + `cloudevents-http-restful-ws-jakarta` with Quarkus to receive and send CloudEvents through HTTP. - [restful-ws-spring-boot](restful-ws-spring-boot) shows how to use the module - `cloudevents-http-restful-ws` with Spring Boot and Jersey to receive and + `cloudevents-http-restful-ws-jakarta` with Spring Boot and Jersey to receive and send CloudEvents through HTTP. - [spring-reactive](spring-reactive) shows how to use the module `cloudevents-spring` with Spring Boot and Webflux to receive and diff --git a/examples/amqp-proton/pom.xml b/examples/amqp-proton/pom.xml index b71f606c9..85b9efbcf 100644 --- a/examples/amqp-proton/pom.xml +++ b/examples/amqp-proton/pom.xml @@ -13,7 +13,7 @@ cloudevents.example.amqp.proton - 4.5.27 + 4.5.28 diff --git a/examples/amqp-proton/src/main/java/io/cloudevents/examples/amqp/vertx/AmqpClient.java b/examples/amqp-proton/src/main/java/io/cloudevents/examples/amqp/vertx/AmqpClient.java index 5b35b3e60..7f6dc928f 100644 --- a/examples/amqp-proton/src/main/java/io/cloudevents/examples/amqp/vertx/AmqpClient.java +++ b/examples/amqp-proton/src/main/java/io/cloudevents/examples/amqp/vertx/AmqpClient.java @@ -18,7 +18,7 @@ import java.nio.charset.StandardCharsets; /** - * A example vertx-based AMQP client that interacts with a remote AMQP server to send and receive CloudEvent messages. + * An example vertx-based AMQP client that interacts with a remote AMQP server to send and receive CloudEvent messages. */ public class AmqpClient { diff --git a/examples/basic-http/pom.xml b/examples/basic-http/pom.xml index 0261d504d..bbfa233a7 100644 --- a/examples/basic-http/pom.xml +++ b/examples/basic-http/pom.xml @@ -46,7 +46,7 @@ org.eclipse.jetty jetty-server - 9.4.58.v20250814 + 12.1.10 diff --git a/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/BasicHttpServer.java b/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/BasicHttpServer.java index 0bcd84d69..f59d47315 100644 --- a/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/BasicHttpServer.java +++ b/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/BasicHttpServer.java @@ -64,7 +64,7 @@ private static void echoHandler(HttpExchange exchange) throws IOException { private static MessageReader createMessageReader(HttpExchange httpExchange) throws IOException { Headers headers = httpExchange.getRequestHeaders(); - byte[] body = IOUtils.toByteArray(httpExchange.getRequestBody()); + byte[] body = httpExchange.getRequestBody().readAllBytes(); return HttpMessageFactory.createReaderFromMultimap(headers, body); } diff --git a/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/HttpURLConnectionClient.java b/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/HttpURLConnectionClient.java index 08a22c1a5..c9e48a504 100644 --- a/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/HttpURLConnectionClient.java +++ b/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/HttpURLConnectionClient.java @@ -64,7 +64,7 @@ public static void main(String[] args) throws IOException { private static MessageReader createMessageReader(HttpURLConnection httpUrlConnection) throws IOException { Map> headers = httpUrlConnection.getHeaderFields(); - byte[] body = IOUtils.toByteArray(httpUrlConnection.getInputStream()); + byte[] body = httpUrlConnection.getInputStream().readAllBytes(); return HttpMessageFactory.createReaderFromMultimap(headers, body); } diff --git a/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/IOUtils.java b/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/IOUtils.java deleted file mode 100644 index 25725064a..000000000 --- a/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/IOUtils.java +++ /dev/null @@ -1,43 +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.examples.http.basic; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -// based on apache's commons-io -// which is licensed under the Apache License, Version 2.0 -// https://commons.apache.org/proper/commons-io/ -// https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/IOUtils.java - -public final class IOUtils { - - private IOUtils() {} - - // since Java 9+ you may call InputStream.readAllBytes() instead of this method - public static byte[] toByteArray(InputStream body) throws IOException { - try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { - byte[] buff = new byte[(1<<10) * 8]; - int read; - while ((read = body.read(buff)) != -1) { - byteArrayOutputStream.write(buff, 0, read); - } - return byteArrayOutputStream.toByteArray(); - } - } -} diff --git a/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/JettyServer.java b/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/JettyServer.java index 946704471..09f96490f 100644 --- a/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/JettyServer.java +++ b/examples/basic-http/src/main/java/io/cloudevents/examples/http/basic/JettyServer.java @@ -16,14 +16,9 @@ package io.cloudevents.examples.http.basic; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.ServletException; import java.io.IOException; -import java.io.UncheckedIOException; import java.net.InetSocketAddress; -import java.util.Enumeration; +import java.nio.ByteBuffer; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -33,70 +28,58 @@ import io.cloudevents.http.HttpMessageFactory; import org.eclipse.jetty.http.HttpStatus; -import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; +import org.eclipse.jetty.server.Response; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.Callback; public class JettyServer { - private static class Handler extends AbstractHandler { + private static class CloudeventsHandler extends Handler.Abstract { @Override - public void handle(String uri, - Request request, - HttpServletRequest httpServletRequest, - HttpServletResponse httpServletResponse) throws IOException, ServletException { - if (!"/echo".equalsIgnoreCase(uri)) { - httpServletResponse.setStatus(HttpStatus.NOT_FOUND_404); - return; + public boolean handle(Request request, Response response, Callback callback) throws IOException { + if (!"/echo".equalsIgnoreCase(request.getHttpURI().getPath())) { + return false; } if (!"POST".equalsIgnoreCase(request.getMethod())) { - httpServletResponse.setStatus(HttpStatus.METHOD_NOT_ALLOWED_405); - return; + response.setStatus(HttpStatus.METHOD_NOT_ALLOWED_405); + callback.succeeded(); + return true; } - CloudEvent receivedEvent = createMessageReader(httpServletRequest).toEvent(); + CloudEvent receivedEvent = createMessageReader(request).toEvent(); System.out.println("Handling event: " + receivedEvent); - createMessageWriter(httpServletResponse).writeBinary(receivedEvent); + createMessageWriter(response, callback).writeBinary(receivedEvent); + return true; } } - private static MessageReader createMessageReader(HttpServletRequest httpServletRequest) throws IOException { - Consumer> forEachHeader = processHeader -> { - Enumeration headerNames = httpServletRequest.getHeaderNames(); - while (headerNames.hasMoreElements()) { - String name = headerNames.nextElement(); - processHeader.accept(name, httpServletRequest.getHeader(name)); - - } - }; - byte[] body = IOUtils.toByteArray(httpServletRequest.getInputStream()); + private static MessageReader createMessageReader(Request request) { + Consumer> forEachHeader = processHeader -> + request.getHeaders() + .forEach(header -> processHeader.accept(header.getName(), header.getValue())); + byte[] body = request.read().takeByteArray(); return HttpMessageFactory.createReader(forEachHeader, body); } - private static MessageWriter createMessageWriter(HttpServletResponse httpServletResponse) throws IOException { + private static MessageWriter createMessageWriter(Response response, Callback callback) { return HttpMessageFactory.createWriter( - httpServletResponse::addHeader, + response.getHeaders()::add, body -> { - try { - try (ServletOutputStream outputStream = httpServletResponse.getOutputStream()) { - if (body != null) { - httpServletResponse.setContentLength(body.length); - httpServletResponse.setStatus(HttpStatus.OK_200); - outputStream.write(body); - } else { - httpServletResponse.setStatus(HttpStatus.NO_CONTENT_204); - } - } - } catch (IOException e) { - throw new UncheckedIOException(e); + if (body != null) { + response.setStatus(HttpStatus.OK_200); + response.write(true, ByteBuffer.wrap(body), callback); + } else { + response.setStatus(HttpStatus.NO_CONTENT_204); } }); } public static void main(String[] args) throws Exception { Server server = new Server(new InetSocketAddress("localhost", 8080)); - server.setHandler(new Handler()); + server.setHandler(new CloudeventsHandler()); server.start(); server.join(); } diff --git a/examples/restful-ws-microprofile-liberty/pom.xml b/examples/restful-ws-microprofile-liberty/pom.xml index e7d9e2f13..0950e05a6 100644 --- a/examples/restful-ws-microprofile-liberty/pom.xml +++ b/examples/restful-ws-microprofile-liberty/pom.xml @@ -4,7 +4,6 @@ cloudevents-examples io.cloudevents 5.0.0-SNAPSHOT - ../ 4.0.0 cloudevents-restful-ws-microprofile-liberty-example diff --git a/examples/restful-ws-quarkus/pom.xml b/examples/restful-ws-quarkus/pom.xml index 90837160e..1d18eb21c 100644 --- a/examples/restful-ws-quarkus/pom.xml +++ b/examples/restful-ws-quarkus/pom.xml @@ -12,7 +12,7 @@ Cloudevents - JAX-RS Quarkus example cloudevents.example.restful.ws.quarkus - 1.13.7.Final + 3.36.1 @@ -28,7 +28,7 @@ io.quarkus - quarkus-resteasy-jackson + quarkus-rest-jackson io.quarkus @@ -45,7 +45,7 @@ io.cloudevents - cloudevents-http-restful-ws + cloudevents-http-restful-ws-jakarta ${project.version} @@ -55,7 +55,7 @@ io.quarkus - quarkus-junit5 + quarkus-junit test @@ -73,8 +73,6 @@ - prepare - prepare-tests build generate-code generate-code-tests diff --git a/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/client/UserClient.java b/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/client/UserClient.java index cd2f025e6..3a0acf7de 100644 --- a/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/client/UserClient.java +++ b/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/client/UserClient.java @@ -1,8 +1,8 @@ package io.cloudevents.examples.quarkus.client; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; import io.cloudevents.CloudEvent; import io.cloudevents.jackson.JsonFormat; diff --git a/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/client/UserEventsGenerator.java b/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/client/UserEventsGenerator.java index 6b79d6b9c..b5f6a60b7 100644 --- a/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/client/UserEventsGenerator.java +++ b/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/client/UserEventsGenerator.java @@ -3,9 +3,9 @@ import java.net.URI; import java.util.UUID; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.ws.rs.core.MediaType; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.core.MediaType; import com.fasterxml.jackson.databind.ObjectMapper; @@ -31,7 +31,7 @@ public class UserEventsGenerator { @Inject @RestClient UserClient userClient; - + long userCount=0; @Scheduled(every="2s") diff --git a/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/resources/UserResource.java b/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/resources/UserResource.java index 39c0dec46..df206ac7b 100644 --- a/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/resources/UserResource.java +++ b/examples/restful-ws-quarkus/src/main/java/io/cloudevents/examples/quarkus/resources/UserResource.java @@ -8,12 +8,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; +import jakarta.inject.Inject; +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.UriInfo; import java.util.HashMap; import java.util.Map; diff --git a/examples/restful-ws-quarkus/src/main/resources/application.properties b/examples/restful-ws-quarkus/src/main/resources/application.properties index e41cca74d..dd9332a70 100644 --- a/examples/restful-ws-quarkus/src/main/resources/application.properties +++ b/examples/restful-ws-quarkus/src/main/resources/application.properties @@ -4,4 +4,4 @@ ## The Rest client will send events to the local UserResource io.cloudevents.examples.quarkus.client.UserClient/mp-rest/url=http://localhost:8080 %test.io.cloudevents.examples.quarkus.client.UserClient/mp-rest/url=http://localhost:8081 -io.cloudevents.examples.quarkus.client.UserClient/mp-rest/scope=javax.inject.Singleton +io.cloudevents.examples.quarkus.client.UserClient/mp-rest/scope=jakarta.inject.Singleton diff --git a/examples/restful-ws-quarkus/src/test/java/io/cloudevents/examples/quarkus/NativeUserResourceTestIT.java b/examples/restful-ws-quarkus/src/test/java/io/cloudevents/examples/quarkus/NativeUserResourceTestIT.java index b1cca4df6..a8d6f2b96 100644 --- a/examples/restful-ws-quarkus/src/test/java/io/cloudevents/examples/quarkus/NativeUserResourceTestIT.java +++ b/examples/restful-ws-quarkus/src/test/java/io/cloudevents/examples/quarkus/NativeUserResourceTestIT.java @@ -1,8 +1,8 @@ package io.cloudevents.examples.quarkus; -import io.quarkus.test.junit.NativeImageTest; +import io.quarkus.test.junit.QuarkusIntegrationTest; -@NativeImageTest +@QuarkusIntegrationTest public class NativeUserResourceTestIT extends UserResourceTest { // Execute the same tests but in native mode. diff --git a/examples/restful-ws-spring-boot/pom.xml b/examples/restful-ws-spring-boot/pom.xml index 81b51694c..3e4bc448a 100644 --- a/examples/restful-ws-spring-boot/pom.xml +++ b/examples/restful-ws-spring-boot/pom.xml @@ -14,7 +14,7 @@ cloudevents.example.spring.boot - 2.7.18 + 3.5.14 @@ -47,7 +47,7 @@ io.cloudevents - cloudevents-http-restful-ws + cloudevents-http-restful-ws-jakarta ${project.version} diff --git a/examples/restful-ws-spring-boot/src/main/java/io/cloudevents/examples/springboot/MainResource.java b/examples/restful-ws-spring-boot/src/main/java/io/cloudevents/examples/springboot/MainResource.java index d82f033ea..49b00eaa1 100644 --- a/examples/restful-ws-spring-boot/src/main/java/io/cloudevents/examples/springboot/MainResource.java +++ b/examples/restful-ws-spring-boot/src/main/java/io/cloudevents/examples/springboot/MainResource.java @@ -22,40 +22,40 @@ import io.cloudevents.core.builder.CloudEventBuilder; import io.cloudevents.core.data.PojoCloudEventData; import io.cloudevents.jackson.PojoCloudEventDataMapper; -import org.springframework.beans.factory.annotation.Autowired; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; import static io.cloudevents.core.CloudEventUtils.mapData; -@Path("/") +@RestController public class MainResource { public static final String HAPPY_BIRTHDAY_EVENT_TYPE = "happybirthday.myapplication"; - @Autowired - ObjectMapper objectMapper; + private final ObjectMapper objectMapper; - @POST - @Path("happy_birthday") - public Response handleHappyBirthdayEvent(CloudEvent inputEvent) { + public MainResource(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @PostMapping("/happy_birthday") + public ResponseEntity handleHappyBirthdayEvent(@RequestBody CloudEvent inputEvent) { if (!inputEvent.getType().equals(HAPPY_BIRTHDAY_EVENT_TYPE)) { - return Response.status(Response.Status.BAD_REQUEST) - .type(MediaType.TEXT_PLAIN) - .entity("Event type should be \"" + HAPPY_BIRTHDAY_EVENT_TYPE + "\" but is \"" + inputEvent.getType() + "\"") - .build(); + return ResponseEntity.badRequest() + .contentType(MediaType.TEXT_PLAIN) + .body("Event type should be \"" + HAPPY_BIRTHDAY_EVENT_TYPE + "\" but is \"" + inputEvent.getType() + "\""); } PojoCloudEventData cloudEventData = mapData(inputEvent, PojoCloudEventDataMapper.from(objectMapper, User.class)); if (cloudEventData == null) { - return Response.status(Response.Status.BAD_REQUEST) - .type(MediaType.TEXT_PLAIN) - .entity("Event should contain the user") - .build(); + return ResponseEntity.badRequest() + .contentType(MediaType.TEXT_PLAIN) + .body("Event should contain the user"); } User user = cloudEventData.getValue(); @@ -65,6 +65,6 @@ public Response handleHappyBirthdayEvent(CloudEvent inputEvent) { .withData(PojoCloudEventData.wrap(user, objectMapper::writeValueAsBytes)) .build(); - return Response.ok(outputEvent).build(); + return ResponseEntity.ok(outputEvent); } } diff --git a/examples/spring-reactive/pom.xml b/examples/spring-reactive/pom.xml index 8a1bf3727..09a5ff0cd 100644 --- a/examples/spring-reactive/pom.xml +++ b/examples/spring-reactive/pom.xml @@ -14,7 +14,7 @@ cloudevents.example.spring.reactive - 2.7.18 + 3.5.14 diff --git a/examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/DemoApplicationTests.java b/examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/DemoApplicationTests.java index b98c7c3c0..fee0321f8 100644 --- a/examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/DemoApplicationTests.java +++ b/examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/DemoApplicationTests.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.http.MediaType; @@ -14,6 +15,7 @@ import io.cloudevents.core.builder.CloudEventBuilder; import static org.assertj.core.api.Assertions.assertThat; +@AutoConfigureWebTestClient @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class DemoApplicationTests { @@ -49,12 +51,13 @@ void structuredRequestResponseEvents() { rest.post().uri("/event") // .contentType(new MediaType("application", "cloudevents+json")) // - .bodyValue("{" // - + "\"id\":\"12345\"," // - + "\"specversion\":\"1.0\"," // - + "\"type\":\"io.spring.event\"," // - + "\"source\":\"https://spring.io/events\"," // - + "\"data\":{\"value\":\"Dave\"}}") // + .bodyValue(""" + { + "id":"12345", + "specversion":"1.0", + "type":"io.spring.event", + "source":"https://spring.io/events", + "data":{"value":"Dave"}}""") // .exchange() // .expectStatus().isOk() // .expectHeader().exists("ce-id") // diff --git a/examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/WebClientTests.java b/examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/WebClientTests.java index 139b30c8a..88b51aea1 100644 --- a/examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/WebClientTests.java +++ b/examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/WebClientTests.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.server.LocalServerPort; @@ -22,6 +23,7 @@ * content of the request and response are asserted separately in * {@link DemoApplicationTests}. */ +@AutoConfigureWebTestClient @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class WebClientTests { diff --git a/examples/spring-rsocket/pom.xml b/examples/spring-rsocket/pom.xml index 6e32b519d..b52dfb0ab 100644 --- a/examples/spring-rsocket/pom.xml +++ b/examples/spring-rsocket/pom.xml @@ -14,7 +14,7 @@ cloudevents.example.spring.rsocket - 2.7.18 + 3.5.14 diff --git a/formats/avro-compact/src/main/java/io/cloudevents/avro/compact/AvroCompactFormat.java b/formats/avro-compact/src/main/java/io/cloudevents/avro/compact/AvroCompactFormat.java index 066776414..3c7d5f402 100644 --- a/formats/avro-compact/src/main/java/io/cloudevents/avro/compact/AvroCompactFormat.java +++ b/formats/avro-compact/src/main/java/io/cloudevents/avro/compact/AvroCompactFormat.java @@ -52,10 +52,10 @@ public byte[] serialize(CloudEvent from) throws EventSerializationException { Map extensions = new HashMap<>(); for (String name : from.getExtensionNames()) { Object value = from.getExtension(name); - if (value instanceof byte[]) - value = ByteBuffer.wrap((byte[]) value); - else if (value instanceof OffsetDateTime) - value = ((OffsetDateTime) value).toInstant(); + if (value instanceof byte[] bytes) + value = ByteBuffer.wrap(bytes); + else if (value instanceof OffsetDateTime time) + value = time.toInstant(); extensions.put(name, value); } @@ -101,19 +101,19 @@ public CloudEvent deserialize(byte[] bytes, CloudEventDataMapper, V> V read(CloudEventWriterFactory w // Only 'Int' values are supported by the specification - if (numericValue instanceof Integer){ - writer.withContextAttribute(extensionName, (Integer) numericValue); + if (numericValue instanceof Integer integer){ + writer.withContextAttribute(extensionName, integer); } else{ throw CloudEventRWException.newInvalidAttributeType(extensionName,numericValue); } diff --git a/formats/json-jackson/src/main/java/io/cloudevents/jackson/CloudEventSerializer.java b/formats/json-jackson/src/main/java/io/cloudevents/jackson/CloudEventSerializer.java index 50f0931d8..e7aeb3329 100644 --- a/formats/json-jackson/src/main/java/io/cloudevents/jackson/CloudEventSerializer.java +++ b/formats/json-jackson/src/main/java/io/cloudevents/jackson/CloudEventSerializer.java @@ -68,8 +68,8 @@ public CloudEventContextWriter withContextAttribute(String name, String value) t public CloudEventContextWriter withContextAttribute(String name, Number value) throws CloudEventRWException { // Only Integer types are supported by the specification - if (value instanceof Integer) { - this.withContextAttribute(name, (Integer) value); + if (value instanceof Integer integer) { + this.withContextAttribute(name, integer); } else { // Default to string representation for other numeric values this.withContextAttribute(name, value.toString()); @@ -116,8 +116,8 @@ public void serialize(CloudEvent value, JsonGenerator gen, SerializerProvider pr // Serialize data if (value.getData() != null) { CloudEventData data = value.getData(); - if (data instanceof JsonCloudEventData) { - gen.writeObjectField("data", ((JsonCloudEventData) data).getNode()); + if (data instanceof JsonCloudEventData eventData) { + gen.writeObjectField("data", eventData.getNode()); } else { byte[] dataBytes = data.toBytes(); String contentType = value.getDataContentType(); diff --git a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonCloudEventData.java b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonCloudEventData.java index 6e9c19b72..b8da09178 100644 --- a/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonCloudEventData.java +++ b/formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonCloudEventData.java @@ -34,6 +34,7 @@ public class JsonCloudEventData implements CloudEventData { * @param node the json node to wrap * @deprecated You should use {@link #wrap(JsonNode)} */ + @Deprecated public JsonCloudEventData(JsonNode node) { Objects.requireNonNull(node); this.node = node; diff --git a/formats/json-jackson/src/main/java/io/cloudevents/jackson/PojoCloudEventDataMapper.java b/formats/json-jackson/src/main/java/io/cloudevents/jackson/PojoCloudEventDataMapper.java index 95c3e0cdc..f8c04dd13 100644 --- a/formats/json-jackson/src/main/java/io/cloudevents/jackson/PojoCloudEventDataMapper.java +++ b/formats/json-jackson/src/main/java/io/cloudevents/jackson/PojoCloudEventDataMapper.java @@ -29,8 +29,8 @@ private PojoCloudEventDataMapper(ObjectMapper mapper, JavaType target) { @Override public PojoCloudEventData map(CloudEventData data) throws CloudEventRWException { // Best case, event is already from json - if (data instanceof JsonCloudEventData) { - JsonNode node = ((JsonCloudEventData) data).getNode(); + if (data instanceof JsonCloudEventData eventData) { + JsonNode node = eventData.getNode(); T value; try { value = this.mapper.convertValue(node, target); diff --git a/formats/json-jackson/src/test/java/io/cloudevents/jackson/CloudEventDeserializerTest.java b/formats/json-jackson/src/test/java/io/cloudevents/jackson/CloudEventDeserializerTest.java index be8f5f418..f9acc716c 100644 --- a/formats/json-jackson/src/test/java/io/cloudevents/jackson/CloudEventDeserializerTest.java +++ b/formats/json-jackson/src/test/java/io/cloudevents/jackson/CloudEventDeserializerTest.java @@ -13,25 +13,29 @@ public class CloudEventDeserializerTest { - private static final String nonBinaryPayload = "{\n" + - " \"specversion\" : \"1.0\",\n" + - " \"type\" : \"com.example.someevent\",\n" + - " \"source\" : \"/mycontext\",\n" + - " \"subject\": null,\n" + - " \"id\" : \"D234-1234-1234\",\n" + - " \"time\" : \"2018-04-05T17:31:00Z\",\n" + - " \"comexampleextension1\" : \"value\",\n" + - " \"comexampleothervalue\" : 5,\n" + - " \"data\" : \"I'm just a string\"\n" + - "}"; + private static final String nonBinaryPayload = """ + { + "specversion" : "1.0", + "type" : "com.example.someevent", + "source" : "/mycontext", + "subject": null, + "id" : "D234-1234-1234", + "time" : "2018-04-05T17:31:00Z", + "comexampleextension1" : "value", + "comexampleothervalue" : 5, + "data" : "I'm just a string" + }\ + """; - private static final String binaryPayload = "{\n" + - " \"specversion\" : \"1.0\",\n" + - " \"type\" : \"com.example.someevent\",\n" + - " \"source\" : \"/mycontext\",\n" + - " \"id\" : \"D234-1234-1234\",\n" + - " \"data_base64\" : \"eyAieHl6IjogMTIzIH0=\"\n" + - "}"; + private static final String binaryPayload = """ + { + "specversion" : "1.0", + "type" : "com.example.someevent", + "source" : "/mycontext", + "id" : "D234-1234-1234", + "data_base64" : "eyAieHl6IjogMTIzIH0=" + }\ + """; @Test void impliedDataContentTypeNonBinaryData() throws IOException { 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 59c2d70c0..0da0ebad5 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 @@ -37,7 +37,7 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Objects; import java.util.stream.Stream; @@ -319,7 +319,7 @@ private static byte[] loadFile(String input) { try { return String.join( "", - Files.readAllLines(Paths.get(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource(input)).toURI()), StandardCharsets.UTF_8) + Files.readAllLines(Path.of(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource(input)).toURI()), StandardCharsets.UTF_8) ).getBytes(StandardCharsets.UTF_8); } catch (IOException | URISyntaxException e) { throw new RuntimeException(e); diff --git a/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtoDataWrapper.java b/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtoDataWrapper.java index ec0abf0c2..8edaac6f2 100644 --- a/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtoDataWrapper.java +++ b/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtoDataWrapper.java @@ -29,8 +29,8 @@ class ProtoDataWrapper implements ProtoCloudEventData { Objects.requireNonNull(protoMessage); - if (protoMessage instanceof Any) { - protoAny = (Any) protoMessage; + if (protoMessage instanceof Any any) { + protoAny = any; } else { protoAny = Any.pack(protoMessage); } diff --git a/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtoSerializer.java b/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtoSerializer.java index 46fb295c4..70d069b9f 100644 --- a/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtoSerializer.java +++ b/formats/protobuf/src/main/java/io/cloudevents/protobuf/ProtoSerializer.java @@ -189,8 +189,8 @@ public CloudEventContextWriter withContextAttribute(String name, Number value) throws CloudEventRWException { // TODO - Future Cleanup - if (value instanceof Integer) { - return withContextAttribute(name, (Integer) value); + if (value instanceof Integer integer) { + return withContextAttribute(name, integer); } else { return withContextAttribute(name, value.toString()); } @@ -245,9 +245,7 @@ public CloudEvent end(CloudEventData data) throws CloudEventRWException { } // If it's a proto message we can handle that directly. - if (data instanceof ProtoCloudEventData) { - - final ProtoCloudEventData protoData = (ProtoCloudEventData) data; + if (data instanceof ProtoCloudEventData protoData) { final Any anAny = protoData.getAny(); // Even though our local implementation cannot be instantiated diff --git a/formats/xml/pom.xml b/formats/xml/pom.xml index ddd27e3a6..65566449c 100644 --- a/formats/xml/pom.xml +++ b/formats/xml/pom.xml @@ -34,7 +34,6 @@ io.cloudevents.formats.xml 2.10.0 - 2.3.1 @@ -46,9 +45,8 @@ - javax.xml.bind - jaxb-api - ${javax.xml.version} + jakarta.xml.bind + jakarta.xml.bind-api diff --git a/formats/xml/src/main/java/io/cloudevents/xml/OccurrenceTracker.java b/formats/xml/src/main/java/io/cloudevents/xml/OccurrenceTracker.java index bd94de4be..6154bd99f 100644 --- a/formats/xml/src/main/java/io/cloudevents/xml/OccurrenceTracker.java +++ b/formats/xml/src/main/java/io/cloudevents/xml/OccurrenceTracker.java @@ -37,8 +37,8 @@ class OccurrenceTracker { } /** - * Record an occurrence of attribute name. - * @param name The name to track. + * Record an occurrence of an attribute name. + * @param name The name to track. * @return boolean true => accepted, false => duplicate name. */ boolean trackOccurrence(String name) { 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 d0e4c0bc7..996f07cf3 100644 --- a/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java +++ b/formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java @@ -19,7 +19,6 @@ 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; diff --git a/formats/xml/src/main/java/io/cloudevents/xml/XMLSerializer.java b/formats/xml/src/main/java/io/cloudevents/xml/XMLSerializer.java index ff5882282..4a23e961a 100644 --- a/formats/xml/src/main/java/io/cloudevents/xml/XMLSerializer.java +++ b/formats/xml/src/main/java/io/cloudevents/xml/XMLSerializer.java @@ -169,8 +169,8 @@ public CloudEventContextWriter withContextAttribute(String name, OffsetDateTime @Override public CloudEventContextWriter withContextAttribute(String name, Number value) throws CloudEventRWException { - if (value instanceof Integer) { - return withContextAttribute(name, (Integer) value); + if (value instanceof Integer integer) { + return withContextAttribute(name, integer); } else { return withContextAttribute(name, String.valueOf(value)); } @@ -200,8 +200,8 @@ public CloudEventContextWriter withContextAttribute(String name, byte[] value) t @Override public Document end(CloudEventData data) throws CloudEventRWException { - if (data instanceof XMLCloudEventData) { - writeXmlData(((XMLCloudEventData) data).getDocument()); + if (data instanceof XMLCloudEventData eventData) { + writeXmlData(eventData.getDocument()); } else if (XMLUtils.isXmlContent(dataContentType)) { writeXmlData(data.toBytes()); } else if (XMLUtils.isTextContent(dataContentType)) { diff --git a/formats/xml/src/test/java/io/cloudevents/xml/XMLFormatTest.java b/formats/xml/src/test/java/io/cloudevents/xml/XMLFormatTest.java index 0c3303573..7188ee715 100644 --- a/formats/xml/src/test/java/io/cloudevents/xml/XMLFormatTest.java +++ b/formats/xml/src/test/java/io/cloudevents/xml/XMLFormatTest.java @@ -56,7 +56,7 @@ public void verifyExtensions() throws IOException { CloudEvent ce = format.deserialize(raw); assertThat(ce).isNotNull(); - assertExtension(ce, "myinteger", new Integer(42)); + assertExtension(ce, "myinteger", Integer.valueOf(42)); assertExtension(ce, "mystring", "Greetings"); assertExtension(ce, "myboolean", Boolean.FALSE); } diff --git a/formats/xml/src/test/java/io/cloudevents/xml/XMLUtilsTest.java b/formats/xml/src/test/java/io/cloudevents/xml/XMLUtilsTest.java index 3052820e1..d6a6e7c81 100644 --- a/formats/xml/src/test/java/io/cloudevents/xml/XMLUtilsTest.java +++ b/formats/xml/src/test/java/io/cloudevents/xml/XMLUtilsTest.java @@ -50,7 +50,7 @@ public void testChildCount() throws ParserConfigurationException { assertThat(XMLUtils.countOfChildElements(root)).isEqualTo(1); - // Add a another child + // Add another child Element c2 = doc.createElement("ChildTwo"); root.appendChild(c2); diff --git a/http/restful-ws-integration-tests/pom.xml b/http/restful-ws-integration-tests/pom.xml deleted file mode 100644 index c974c078d..000000000 --- a/http/restful-ws-integration-tests/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - cloudevents-parent - io.cloudevents - 5.0.0-SNAPSHOT - ../../pom.xml - - 4.0.0 - - cloudevents-http-restful-ws-integration-tests - CloudEvents - JAX-RS Web Http Binding Integration Tests - pom - - - - true - - - - restful-ws-common - restful-ws-spring - restful-ws-jersey - restful-ws-resteasy - - - diff --git a/http/restful-ws-integration-tests/restful-ws-common/pom.xml b/http/restful-ws-integration-tests/restful-ws-common/pom.xml deleted file mode 100644 index 0925f0087..000000000 --- a/http/restful-ws-integration-tests/restful-ws-common/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - cloudevents-http-restful-ws-integration-tests - io.cloudevents - 5.0.0-SNAPSHOT - ../ - - 4.0.0 - - cloudevents-http-restful-ws-integration-tests-common - CloudEvents - JAX-RS Integration Tests - Common - jar - - io.cloudevents.jaxrs.integration.tests.common - - - - - io.cloudevents - cloudevents-http-restful-ws - ${project.version} - - - io.cloudevents - cloudevents-core - tests - test-jar - ${project.version} - - - - org.assertj - assertj-core - ${assertj-core.version} - - - org.junit.jupiter - junit-jupiter - ${junit-jupiter.version} - - - - diff --git a/http/restful-ws-integration-tests/restful-ws-common/src/main/java/io/cloudevents/http/restful/ws/BaseTest.java b/http/restful-ws-integration-tests/restful-ws-common/src/main/java/io/cloudevents/http/restful/ws/BaseTest.java deleted file mode 100644 index 2dd181ae8..000000000 --- a/http/restful-ws-integration-tests/restful-ws-common/src/main/java/io/cloudevents/http/restful/ws/BaseTest.java +++ /dev/null @@ -1,103 +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; - -import io.cloudevents.CloudEvent; -import io.cloudevents.core.mock.CSVFormat; -import io.cloudevents.core.test.Data; -import org.junit.jupiter.api.Test; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; - -import static org.assertj.core.api.Assertions.assertThat; - -public abstract class BaseTest { - - protected abstract WebTarget getWebTarget(); - - @Test - void getMinEvent() { - Response res = getWebTarget().path("getMinEvent").request().buildGet().invoke(); - - assertThat(res.getHeaderString("ce-specversion")) - .isEqualTo("1.0"); - - CloudEvent outEvent = res.readEntity(CloudEvent.class); - assertThat(outEvent) - .isEqualTo(Data.V1_MIN); - } - - @Test - void getStructuredEvent() { - Response res = getWebTarget().path("getStructuredEvent").request().buildGet().invoke(); - - CloudEvent outEvent = res.readEntity(CloudEvent.class); - assertThat(outEvent) - .isEqualTo(Data.V1_MIN); - assertThat(res.getHeaderString(HttpHeaders.CONTENT_TYPE)) - .isEqualTo(CSVFormat.INSTANCE.serializedContentType()); - } - - @Test - void getEvent() { - Response res = getWebTarget().path("getEvent").request().buildGet().invoke(); - - CloudEvent outEvent = res.readEntity(CloudEvent.class); - assertThat(outEvent) - .isEqualTo(Data.V1_WITH_JSON_DATA_WITH_EXT_STRING); - } - - @Test - void postEventWithoutBody() { - Response res = getWebTarget() - .path("postEventWithoutBody") - .request() - .buildPost(Entity.entity(Data.V1_MIN, CloudEventsProvider.CLOUDEVENT_TYPE)) - .invoke(); - - assertThat(res.getStatus()) - .isEqualTo(200); - } - - @Test - void postEventStructured() { - Response res = getWebTarget() - .path("postEventWithoutBody") - .request() - .buildPost(Entity.entity(Data.V1_MIN, "application/cloudevents+csv")) - .invoke(); - - assertThat(res.getStatus()) - .isEqualTo(200); - } - - @Test - void postEvent() { - Response res = getWebTarget() - .path("postEvent") - .request() - .buildPost(Entity.entity(Data.V1_WITH_JSON_DATA_WITH_EXT_STRING, CloudEventsProvider.CLOUDEVENT_TYPE)) - .invoke(); - - assertThat(res.getStatus()) - .isEqualTo(200); - } -} diff --git a/http/restful-ws-integration-tests/restful-ws-common/src/main/java/io/cloudevents/http/restful/ws/TestResource.java b/http/restful-ws-integration-tests/restful-ws-common/src/main/java/io/cloudevents/http/restful/ws/TestResource.java deleted file mode 100644 index 212b5b581..000000000 --- a/http/restful-ws-integration-tests/restful-ws-common/src/main/java/io/cloudevents/http/restful/ws/TestResource.java +++ /dev/null @@ -1,67 +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; - -import io.cloudevents.CloudEvent; -import io.cloudevents.core.test.Data; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.core.Response; - -@Path("/") -public class TestResource { - - @GET - @Path("getMinEvent") - public CloudEvent getMinEvent() { - return Data.V1_MIN; - } - - @GET - @Path("getStructuredEvent") - @StructuredEncoding("application/cloudevents+csv") - public CloudEvent getStructuredEvent() { - return Data.V1_MIN; - } - - @GET - @Path("getEvent") - public CloudEvent getEvent() { - return Data.V1_WITH_JSON_DATA_WITH_EXT_STRING; - } - - @POST - @Path("postEventWithoutBody") - public Response postEventWithoutBody(CloudEvent inputEvent) { - if (inputEvent.equals(Data.V1_MIN)) { - return Response.ok().build(); - } - return Response.serverError().build(); - } - - @POST - @Path("postEvent") - public Response postEvent(CloudEvent inputEvent) { - if (inputEvent.equals(Data.V1_WITH_JSON_DATA_WITH_EXT_STRING)) { - return Response.ok().build(); - } - return Response.serverError().build(); - } -} diff --git a/http/restful-ws-integration-tests/restful-ws-jersey/pom.xml b/http/restful-ws-integration-tests/restful-ws-jersey/pom.xml deleted file mode 100644 index 004951700..000000000 --- a/http/restful-ws-integration-tests/restful-ws-jersey/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - cloudevents-http-restful-ws-integration-tests - io.cloudevents - 5.0.0-SNAPSHOT - ../ - - 4.0.0 - - cloudevents-http-restful-ws-integration-tests-jersey - CloudEvents - JAX-RS Integration Tests - Jersey - jar - - - 2.48 - io.cloudevents.jaxrs.integration.tests.jersey - - - - - - io.cloudevents - cloudevents-http-restful-ws-integration-tests-common - ${project.version} - test - - - - org.glassfish.jersey.test-framework.providers - jersey-test-framework-provider-jetty - ${jersey.version} - test - - - junit - junit - - - - - org.glassfish.jersey.inject - jersey-hk2 - ${jersey.version} - test - - - com.github.hanleyt - jersey-junit - 2.2.0 - test - - - - diff --git a/http/restful-ws-integration-tests/restful-ws-jersey/src/test/java/io/cloudevents/http/restful/ws/jersey/TestJersey.java b/http/restful-ws-integration-tests/restful-ws-jersey/src/test/java/io/cloudevents/http/restful/ws/jersey/TestJersey.java deleted file mode 100644 index 6c17e0505..000000000 --- a/http/restful-ws-integration-tests/restful-ws-jersey/src/test/java/io/cloudevents/http/restful/ws/jersey/TestJersey.java +++ /dev/null @@ -1,68 +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.jersey; - -import com.github.hanleyt.JerseyExtension; -import io.cloudevents.core.mock.CSVFormat; -import io.cloudevents.core.provider.EventFormatProvider; -import io.cloudevents.http.restful.ws.BaseTest; -import io.cloudevents.http.restful.ws.CloudEventsProvider; -import io.cloudevents.http.restful.ws.TestResource; -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.server.ResourceConfig; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.RegisterExtension; - -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Application; - -public class TestJersey extends BaseTest { - - private WebTarget target; - - @Override - protected WebTarget getWebTarget() { - return target; - } - - @BeforeAll - public static void beforeAll() { - EventFormatProvider.getInstance().registerFormat(CSVFormat.INSTANCE); - } - - @BeforeEach - void beforeEach(WebTarget target) { - this.target = target; - } - - @RegisterExtension - JerseyExtension jerseyExtension = new JerseyExtension(this::configureJersey, this::configureJerseyClient); - - private Application configureJersey() { - return new ResourceConfig(TestResource.class) - .register(CloudEventsProvider.class); - } - - private ClientConfig configureJerseyClient(ExtensionContext extensionContext, ClientConfig clientConfig) { - return clientConfig - .register(CloudEventsProvider.class); - } - -} diff --git a/http/restful-ws-integration-tests/restful-ws-resteasy/pom.xml b/http/restful-ws-integration-tests/restful-ws-resteasy/pom.xml deleted file mode 100644 index d3951054c..000000000 --- a/http/restful-ws-integration-tests/restful-ws-resteasy/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - cloudevents-http-restful-ws-integration-tests - io.cloudevents - 5.0.0-SNAPSHOT - ../ - - 4.0.0 - - cloudevents-http-restful-ws-integration-tests-resteasy - CloudEvents - JAX-RS Integration Tests - RESTEasy - jar - - - io.cloudevents.jaxrs.integration.tests.resteasy - 3.9.16 - 4.5.12.Final - - - - - - io.cloudevents - cloudevents-http-restful-ws-integration-tests-common - ${project.version} - test - - - - io.vertx - vertx-core - ${vertx.version} - test - - - org.jboss.resteasy - resteasy-vertx - ${resteasy.version} - test - - - - diff --git a/http/restful-ws-integration-tests/restful-ws-resteasy/src/test/java/io/cloudevents/http/restful/ws/resteasy/TestResteasy.java b/http/restful-ws-integration-tests/restful-ws-resteasy/src/test/java/io/cloudevents/http/restful/ws/resteasy/TestResteasy.java deleted file mode 100644 index cba075146..000000000 --- a/http/restful-ws-integration-tests/restful-ws-resteasy/src/test/java/io/cloudevents/http/restful/ws/resteasy/TestResteasy.java +++ /dev/null @@ -1,62 +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.resteasy; - -import io.cloudevents.core.mock.CSVFormat; -import io.cloudevents.core.provider.EventFormatProvider; -import io.cloudevents.http.restful.ws.BaseTest; -import io.cloudevents.http.restful.ws.CloudEventsProvider; -import io.cloudevents.http.restful.ws.TestResource; -import org.jboss.resteasy.plugins.server.vertx.VertxContainer; -import org.jboss.resteasy.plugins.server.vertx.VertxResteasyDeployment; -import org.jboss.resteasy.test.TestPortProvider; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; - -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.WebTarget; - -public class TestResteasy extends BaseTest { - - private static VertxResteasyDeployment resteasyDeployment; - private static WebTarget target; - - @Override - protected WebTarget getWebTarget() { - return target; - } - - @BeforeAll - public static void beforeClass() throws Exception { - EventFormatProvider.getInstance().registerFormat(CSVFormat.INSTANCE); - - String base = TestPortProvider.generateBaseUrl(); - TestResteasy.resteasyDeployment = VertxContainer.start(base); - TestResteasy.resteasyDeployment.getProviderFactory().register(CloudEventsProvider.class); - TestResteasy.resteasyDeployment.getRegistry().addPerRequestResource(TestResource.class); - - TestResteasy.target = ClientBuilder.newClient().register(CloudEventsProvider.class).target(base); - } - - @AfterAll - public static void after() throws Exception { - TestResteasy.resteasyDeployment.stop(); - } - -} diff --git a/http/restful-ws-jakarta-integration-tests/pom.xml b/http/restful-ws-jakarta-integration-tests/pom.xml index e993c53d6..57e098225 100644 --- a/http/restful-ws-jakarta-integration-tests/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/pom.xml @@ -22,9 +22,9 @@ restful-ws-jakarta-common restful-ws-resteasy - - + restful-ws-jersey restful-ws-liberty + restful-ws-spring diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-jakarta-common/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-jakarta-common/pom.xml index 7f68abed3..fa253ce52 100644 --- a/http/restful-ws-jakarta-integration-tests/restful-ws-jakarta-common/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-jakarta-common/pom.xml @@ -4,7 +4,6 @@ cloudevents-http-restful-ws-jakarta-integration-tests io.cloudevents 5.0.0-SNAPSHOT - ../ 4.0.0 cloudevents-http-restful-ws-jakarta-integration-tests-common diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/pom.xml index 0c355b000..21d65f5d1 100644 --- a/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/pom.xml @@ -22,8 +22,7 @@ cloudevents-http-restful-ws-jakarta-integration-tests io.cloudevents - 2.5.0-SNAPSHOT - ../ + 5.0.0-SNAPSHOT 4.0.0 @@ -33,8 +32,7 @@ cloudevents.http.restful.ws.jakarta.integration.tests.jersey - 3.0.8 - 3.0.0 + 3.1.11 @@ -48,7 +46,6 @@ jakarta.ws.rs jakarta.ws.rs-api - ${jakarta-ee.version} test diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/pom.xml index 6b62f738a..8bc8ea3c7 100644 --- a/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/pom.xml @@ -6,7 +6,6 @@ cloudevents-http-restful-ws-jakarta-integration-tests io.cloudevents 5.0.0-SNAPSHOT - ../ 4.0.0 @@ -17,7 +16,7 @@ cloudevents.http.restful.ws.jakarta.integration.tests.microprofile - 6.0.3.Final + 6.2.16.Final 9080 @@ -43,13 +42,13 @@ jakarta.platform jakarta.jakartaee-api - 9.1.0 + ${jakartaee.version} provided org.eclipse.microprofile microprofile - 5.0 + 6.0 pom provided @@ -85,14 +84,12 @@ - javax.xml.bind - jaxb-api - 2.3.1 + jakarta.xml.bind + jakarta.xml.bind-api - javax.activation - activation - 1.1.1 + jakarta.activation + jakarta.activation-api io.openliberty.arquillian diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-resteasy/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-resteasy/pom.xml index a06829bff..4fe0a1891 100644 --- a/http/restful-ws-jakarta-integration-tests/restful-ws-resteasy/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-resteasy/pom.xml @@ -1,10 +1,27 @@ + + + cloudevents-http-restful-ws-jakarta-integration-tests io.cloudevents 5.0.0-SNAPSHOT - ../ 4.0.0 @@ -12,11 +29,11 @@ CloudEvents - JAX-RS Jakarta EE 9+ Integration Tests - RESTEasy jar - cloudevents.http.restful.ws.jakarta.integration.tests.resteasy - 4.5.27 - 6.0.3.Final + 4.5.28 + 6.2.16.Final + 1.0.1.Final @@ -35,9 +52,14 @@ test - org.jboss.resteasy - resteasy-vertx - ${resteasy.version} + dev.resteasy.vertx + resteasy-vertx-client + ${resteasy-vertx.version} + + + dev.resteasy.vertx + resteasy-vertx-embedded-server + ${resteasy-vertx.version} test diff --git a/http/restful-ws-integration-tests/restful-ws-spring/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-spring/pom.xml similarity index 84% rename from http/restful-ws-integration-tests/restful-ws-spring/pom.xml rename to http/restful-ws-jakarta-integration-tests/restful-ws-spring/pom.xml index a5de0609a..309ba82ab 100644 --- a/http/restful-ws-integration-tests/restful-ws-spring/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-spring/pom.xml @@ -20,20 +20,19 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - cloudevents-http-restful-ws-integration-tests + cloudevents-http-restful-ws-jakarta-integration-tests io.cloudevents 5.0.0-SNAPSHOT - ../ 4.0.0 - cloudevents-http-restful-ws-integration-tests-spring - CloudEvents - JAX-RS Integration Tests - Spring + cloudevents-http-restful-ws-jakarta-integration-tests-spring + CloudEvents - JAX-RS Jakarta EE 9+ Integration Tests - Spring jar io.cloudevents.jaxrs.integration.tests.spring - 2.7.18 + 3.5.14 @@ -52,7 +51,7 @@ io.cloudevents - cloudevents-http-restful-ws-integration-tests-common + cloudevents-http-restful-ws-jakarta-integration-tests-common ${project.version} test diff --git a/http/restful-ws-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/spring/JerseyConfig.java b/http/restful-ws-jakarta-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/jakarta/spring/JerseyConfig.java similarity index 94% rename from http/restful-ws-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/spring/JerseyConfig.java rename to http/restful-ws-jakarta-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/jakarta/spring/JerseyConfig.java index 92cd0c968..2d9405f54 100644 --- a/http/restful-ws-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/spring/JerseyConfig.java +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/jakarta/spring/JerseyConfig.java @@ -15,7 +15,7 @@ * */ -package io.cloudevents.http.restful.ws.spring; +package io.cloudevents.http.restful.ws.jakarta.spring; import io.cloudevents.http.restful.ws.CloudEventsProvider; import io.cloudevents.http.restful.ws.TestResource; diff --git a/http/restful-ws-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/spring/TestApplication.java b/http/restful-ws-jakarta-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/jakarta/spring/TestApplication.java similarity index 91% rename from http/restful-ws-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/spring/TestApplication.java rename to http/restful-ws-jakarta-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/jakarta/spring/TestApplication.java index 920a3528d..8bf1b3906 100644 --- a/http/restful-ws-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/spring/TestApplication.java +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/jakarta/spring/TestApplication.java @@ -15,11 +15,11 @@ * */ -package io.cloudevents.http.restful.ws.spring; +package io.cloudevents.http.restful.ws.jakarta.spring; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -@SpringBootApplication(scanBasePackages = {"io.cloudevents.http.restful.ws.spring"}) +@SpringBootApplication(scanBasePackages = {"io.cloudevents.http.restful.ws.jakarta.spring"}) public class TestApplication extends SpringBootServletInitializer { } diff --git a/http/restful-ws-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/spring/TestSpringBootWithJersey.java b/http/restful-ws-jakarta-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/jakarta/spring/TestSpringBootWithJersey.java similarity index 92% rename from http/restful-ws-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/spring/TestSpringBootWithJersey.java rename to http/restful-ws-jakarta-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/jakarta/spring/TestSpringBootWithJersey.java index 494d0bc81..bf5d8a4b8 100644 --- a/http/restful-ws-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/spring/TestSpringBootWithJersey.java +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-spring/src/test/java/io/cloudevents/http/restful/ws/jakarta/spring/TestSpringBootWithJersey.java @@ -15,7 +15,7 @@ * */ -package io.cloudevents.http.restful.ws.spring; +package io.cloudevents.http.restful.ws.jakarta.spring; import io.cloudevents.core.mock.CSVFormat; import io.cloudevents.core.provider.EventFormatProvider; @@ -27,8 +27,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.WebTarget; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; import java.net.URI; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) diff --git a/http/restful-ws-jakarta/pom.xml b/http/restful-ws-jakarta/pom.xml index 4f621d54a..2a37880dc 100644 --- a/http/restful-ws-jakarta/pom.xml +++ b/http/restful-ws-jakarta/pom.xml @@ -41,10 +41,6 @@ - 3.0.0 - 3.0.8 - 4.5.27 - 6.0.3.Final io.cloudevents.http.restfulws @@ -57,7 +53,6 @@ jakarta.ws.rs jakarta.ws.rs-api - ${jakarta-ee.version} diff --git a/http/restful-ws/README.md b/http/restful-ws/README.md deleted file mode 100644 index 34ccf9ed3..000000000 --- a/http/restful-ws/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# HTTP Protocol Binding for Jakarta RESTful Web Services - -This module is deprecated and will be removed in version 5.0. -Please migrate to Jakarta EE 9+ and use the `cloudevents-http-restful-ws-jakarta` module instead. - -Javadocs: [![Javadocs](http://www.javadoc.io/badge/io.cloudevents/cloudevents-http-restful-ws.svg?color=green)](http://www.javadoc.io/doc/io.cloudevents/cloudevents-http-restful-ws) - -Documentation: https://cloudevents.github.io/sdk-java/http-jakarta-restful-ws diff --git a/http/restful-ws/pom.xml b/http/restful-ws/pom.xml deleted file mode 100644 index 35bc610e7..000000000 --- a/http/restful-ws/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - 4.0.0 - - io.cloudevents - cloudevents-parent - 5.0.0-SNAPSHOT - ../../pom.xml - - - cloudevents-http-restful-ws - CloudEvents - Jakarta RESTful Web Services Http Binding - jar - - - 2.1.6 - 2.48 - 3.9.16 - 4.5.12.Final - io.cloudevents.http.restfulws - - - - - io.cloudevents - cloudevents-core - ${project.version} - - - jakarta.ws.rs - jakarta.ws.rs-api - ${jakarta-ee.version} - - - - diff --git a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/BinaryEncoding.java b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/BinaryEncoding.java deleted file mode 100644 index 265316372..000000000 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/BinaryEncoding.java +++ /dev/null @@ -1,33 +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; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotate a method with this annotation to specify that you want to write the returned event - * in binary mode. - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@Deprecated // to be removed in version 5.0, use cloudevents-http-restful-ws-jakarta module instead -public @interface BinaryEncoding { -} 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 deleted file mode 100644 index 39e9d1760..000000000 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/CloudEventsProvider.java +++ /dev/null @@ -1,158 +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; - -import io.cloudevents.CloudEvent; -import io.cloudevents.core.format.EventFormat; -import io.cloudevents.core.message.MessageWriter; -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.rw.CloudEventWriter; - -import javax.ws.rs.Consumes; -import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.client.ClientRequestContext; -import javax.ws.rs.client.ClientRequestFilter; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.MessageBodyReader; -import javax.ws.rs.ext.MessageBodyWriter; -import javax.ws.rs.ext.Provider; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import java.util.Arrays; -import java.util.Optional; - -/** - * This provider implements {@link CloudEvent} encoding and decoding for Jax-Rs Resources and with {@link javax.ws.rs.client.Client}. - */ -@Provider -@Consumes(MediaType.WILDCARD) -@Produces(MediaType.WILDCARD) -@Deprecated // to be removed in version 5.0, use cloudevents-http-restful-ws-jakarta module instead -public class CloudEventsProvider implements MessageBodyReader, MessageBodyWriter, ClientRequestFilter { - - /** - * The content type to use when sending {@link CloudEvent} with {@link javax.ws.rs.client.Client} - */ - public static MediaType CLOUDEVENT_TYPE = MediaType.valueOf("application/cloudevents"); - - @Override - public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { - return CloudEvent.class.isAssignableFrom(type); - } - - @Override - public CloudEvent readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { - return RestfulWSMessageFactory.create(mediaType, httpHeaders, bufferBodyInput(entityStream)).toEvent(); - } - - private byte[] bufferBodyInput(InputStream inputStream) throws IOException { - if (inputStream == null) { - return null; - } - - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - - int nRead; - byte[] data = new byte[1024]; - while ((nRead = inputStream.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, nRead); - } - - buffer.flush(); - return buffer.toByteArray(); - } - - @Override - public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { - return CloudEvent.class.isAssignableFrom(type); - } - - @Override - public void writeTo(CloudEvent event, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - Optional structuredEncodingFormat = Arrays - .stream(annotations) - .filter(a -> a.annotationType().equals(StructuredEncoding.class)) - .map(a -> ((StructuredEncoding) a).value()) - .findFirst(); - - if (structuredEncodingFormat.isPresent()) { - writeStructured( - event, - structuredEncodingFormat.get(), - new RestfulWSMessageWriter(httpHeaders, entityStream) - ); - } else { - writeBinary( - event, - new RestfulWSMessageWriter(httpHeaders, entityStream) - ); - } - } - - private & CloudEventWriter> void writeBinary(CloudEvent input, V visitor) { - visitor.writeBinary(input); - } - - private & CloudEventWriter> void writeStructured(CloudEvent input, EventFormat format, V visitor) { - visitor.writeStructured(input, format); - } - - private & CloudEventWriter> void writeStructured(CloudEvent input, String formatString, V visitor) { - EventFormat format = EventFormatProvider.getInstance().resolveFormat(formatString); - - if (format == null) { - throw new IllegalArgumentException("Cannot resolve format " + formatString); - } - - writeStructured(input, format, visitor); - } - - @Override - public void filter(ClientRequestContext requestContext) throws IOException { - if (isCloudEventEntity(requestContext.getEntity())) { - EventFormat format = EventFormatProvider.getInstance().resolveFormat(requestContext.getMediaType().toString()); - - if (format != null) { - writeStructured( - (CloudEvent) requestContext.getEntity(), - format, - new RestfulWSClientMessageWriter(requestContext) - ); - } else { - writeBinary( - (CloudEvent) requestContext.getEntity(), - new RestfulWSClientMessageWriter(requestContext) - ); - } - } - } - - 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 deleted file mode 100644 index 4fd9d52a8..000000000 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/StructuredEncoding.java +++ /dev/null @@ -1,39 +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; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotate a method with this annotation to specify that you want to write the returned event - * in structured mode. - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@Deprecated // to be removed in version 5.0, use cloudevents-http-restful-ws-jakarta module instead -public @interface StructuredEncoding { - /** - * 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/BinaryRestfulWSMessageReaderImpl.java b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/BinaryRestfulWSMessageReaderImpl.java deleted file mode 100644 index 4ebb7c13b..000000000 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/BinaryRestfulWSMessageReaderImpl.java +++ /dev/null @@ -1,68 +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.SpecVersion; -import io.cloudevents.core.data.BytesCloudEventData; -import io.cloudevents.core.impl.StringUtils; -import io.cloudevents.core.message.impl.BaseGenericBinaryMessageReaderImpl; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MultivaluedMap; -import java.util.Objects; -import java.util.function.BiConsumer; - -import static io.cloudevents.http.restful.ws.impl.CloudEventsHeaders.CE_PREFIX; - -@Deprecated // to be removed in version 5.0, use cloudevents-http-restful-ws-jakarta module instead -public final class BinaryRestfulWSMessageReaderImpl extends BaseGenericBinaryMessageReaderImpl { - - private final MultivaluedMap headers; - - public BinaryRestfulWSMessageReaderImpl(SpecVersion version, MultivaluedMap headers, byte[] body) { - super(version, body != null && body.length > 0 ? BytesCloudEventData.wrap(body) : null); - - Objects.requireNonNull(headers); - this.headers = headers; - } - - @Override - protected boolean isContentTypeHeader(String key) { - return key.equalsIgnoreCase(HttpHeaders.CONTENT_TYPE); - } - - @Override - protected boolean isCloudEventsHeader(String key) { - return key.length() > CE_PREFIX.length() && StringUtils.startsWithIgnoreCase(key, CE_PREFIX); - } - - @Override - protected String toCloudEventsKey(String key) { - return key.substring(CE_PREFIX.length()).toLowerCase(); - } - - @Override - protected void forEachHeader(BiConsumer fn) { - this.headers.forEach((k, v) -> fn.accept(k, v.get(0))); - } - - @Override - protected String toCloudEventsValue(String value) { - return value; - } -} diff --git a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/CloudEventsHeaders.java b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/CloudEventsHeaders.java deleted file mode 100644 index 09128567f..000000000 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/CloudEventsHeaders.java +++ /dev/null @@ -1,38 +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.core.message.impl.MessageUtils; - -import javax.ws.rs.core.HttpHeaders; -import java.util.Map; - -class CloudEventsHeaders { - - static final String CE_PREFIX = "ce-"; - - static final Map ATTRIBUTES_TO_HEADERS = MessageUtils.generateAttributesToHeadersMapping(v -> { - if (v.equals("datacontenttype")) { - return HttpHeaders.CONTENT_TYPE; - } - return CE_PREFIX + v; - }); - - static final String SPEC_VERSION = ATTRIBUTES_TO_HEADERS.get("specversion"); - -} diff --git a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/RestfulWSClientMessageWriter.java b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/RestfulWSClientMessageWriter.java deleted file mode 100644 index 125a8e187..000000000 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/RestfulWSClientMessageWriter.java +++ /dev/null @@ -1,76 +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.CloudEventData; -import io.cloudevents.SpecVersion; -import io.cloudevents.core.format.EventFormat; -import io.cloudevents.core.message.MessageWriter; -import io.cloudevents.rw.CloudEventRWException; -import io.cloudevents.rw.CloudEventWriter; - -import javax.ws.rs.client.ClientRequestContext; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; - -@Deprecated // to be removed in version 5.0, use cloudevents-http-restful-ws-jakarta module instead -public final class RestfulWSClientMessageWriter implements CloudEventWriter, MessageWriter { - - private final ClientRequestContext context; - - public RestfulWSClientMessageWriter(ClientRequestContext context) { - this.context = context; - - // http headers could contain a content type, so let's remove it - this.context.getHeaders().remove(HttpHeaders.CONTENT_TYPE); - this.context.setEntity(null); - } - - @Override - public RestfulWSClientMessageWriter create(SpecVersion version) { - this.context.getHeaders().add(CloudEventsHeaders.SPEC_VERSION, version.toString()); - return this; - } - - @Override - public RestfulWSClientMessageWriter withContextAttribute(String name, String value) throws CloudEventRWException { - String headerName = CloudEventsHeaders.ATTRIBUTES_TO_HEADERS.get(name); - if (headerName == null) { - headerName = CloudEventsHeaders.CE_PREFIX + name; - } - this.context.getHeaders().add(headerName, value); - return this; - } - - @Override - public Void end(CloudEventData value) throws CloudEventRWException { - this.context.setEntity(value.toBytes()); - return null; - } - - @Override - public Void end() { - return null; - } - - @Override - public Void setEvent(EventFormat format, byte[] value) throws CloudEventRWException { - this.context.setEntity(value, null, MediaType.valueOf(format.serializedContentType())); - return null; - } -} diff --git a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/RestfulWSMessageFactory.java b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/RestfulWSMessageFactory.java deleted file mode 100644 index 9f5c9f74d..000000000 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/RestfulWSMessageFactory.java +++ /dev/null @@ -1,43 +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.core.message.MessageReader; -import io.cloudevents.core.message.impl.GenericStructuredMessageReader; -import io.cloudevents.core.message.impl.MessageUtils; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; - -@Deprecated // to be removed in version 5.0, use cloudevents-http-restful-ws-jakarta module instead -public final class RestfulWSMessageFactory { - - private RestfulWSMessageFactory() { - } - - public static MessageReader create(MediaType mediaType, MultivaluedMap headers, byte[] payload) throws IllegalArgumentException { - return MessageUtils.parseStructuredOrBinaryMessage( - () -> headers.getFirst(HttpHeaders.CONTENT_TYPE), - format -> new GenericStructuredMessageReader(format, payload), - () -> headers.getFirst(CloudEventsHeaders.SPEC_VERSION), - sv -> new BinaryRestfulWSMessageReaderImpl(sv, headers, payload) - ); - } - -} diff --git a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/RestfulWSMessageWriter.java b/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/RestfulWSMessageWriter.java deleted file mode 100644 index 91abdb797..000000000 --- a/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/RestfulWSMessageWriter.java +++ /dev/null @@ -1,92 +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.CloudEventData; -import io.cloudevents.SpecVersion; -import io.cloudevents.core.format.EventFormat; -import io.cloudevents.core.message.MessageWriter; -import io.cloudevents.rw.CloudEventRWException; -import io.cloudevents.rw.CloudEventWriter; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MultivaluedMap; -import java.io.IOException; -import java.io.OutputStream; - -@Deprecated // to be removed in version 5.0, use cloudevents-http-restful-ws-jakarta module instead -public final class RestfulWSMessageWriter implements CloudEventWriter, MessageWriter { - - private final MultivaluedMap httpHeaders; - private final OutputStream entityStream; - - public RestfulWSMessageWriter(MultivaluedMap httpHeaders, OutputStream entityStream) { - this.httpHeaders = httpHeaders; - this.entityStream = entityStream; - - // http headers could contain a content type, so let's remove it - this.httpHeaders.remove(HttpHeaders.CONTENT_TYPE); - } - - @Override - public RestfulWSMessageWriter create(SpecVersion version) { - this.httpHeaders.add(CloudEventsHeaders.SPEC_VERSION, version.toString()); - return this; - } - - @Override - public RestfulWSMessageWriter withContextAttribute(String name, String value) throws CloudEventRWException { - String headerName = CloudEventsHeaders.ATTRIBUTES_TO_HEADERS.get(name); - if (headerName == null) { - headerName = CloudEventsHeaders.CE_PREFIX + name; - } - this.httpHeaders.add(headerName, value); - return this; - } - - @Override - public Void end(CloudEventData value) throws CloudEventRWException { - try { - this.entityStream.write(value.toBytes()); - } catch (IOException e) { - throw CloudEventRWException.newOther(e); - } - return this.end(); - } - - @Override - public Void end() { - try { - this.entityStream.flush(); - } catch (IOException e) { - throw CloudEventRWException.newOther(e); - } - return null; - } - - @Override - public Void setEvent(EventFormat format, byte[] value) throws CloudEventRWException { - this.httpHeaders.add(HttpHeaders.CONTENT_TYPE, format.serializedContentType()); - try { - this.entityStream.write(value); - } catch (IOException e) { - throw CloudEventRWException.newOther(e); - } - return this.end(); - } -} diff --git a/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.client.ClientRequestFilter b/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.client.ClientRequestFilter deleted file mode 100644 index d70b7236c..000000000 --- a/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.client.ClientRequestFilter +++ /dev/null @@ -1,17 +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. -# - -io.cloudevents.http.restful.ws.CloudEventsProvider diff --git a/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyReader b/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyReader deleted file mode 100644 index d70b7236c..000000000 --- a/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyReader +++ /dev/null @@ -1,17 +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. -# - -io.cloudevents.http.restful.ws.CloudEventsProvider diff --git a/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyWriter b/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyWriter deleted file mode 100644 index d70b7236c..000000000 --- a/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyWriter +++ /dev/null @@ -1,17 +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. -# - -io.cloudevents.http.restful.ws.CloudEventsProvider diff --git a/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.ext.Providers b/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.ext.Providers deleted file mode 100644 index 2a284a1eb..000000000 --- a/http/restful-ws/src/main/resources/META-INF/services/javax.ws.rs.ext.Providers +++ /dev/null @@ -1 +0,0 @@ -io.cloudevents.http.restful.ws.CloudEventsProvider diff --git a/http/vertx/pom.xml b/http/vertx/pom.xml index 2d272ccae..f1ca3337b 100644 --- a/http/vertx/pom.xml +++ b/http/vertx/pom.xml @@ -31,7 +31,7 @@ jar - 4.5.27 + 4.5.28 io.cloudevents.http.vertx diff --git a/kafka/pom.xml b/kafka/pom.xml index 03e4f276b..fb3677cf2 100644 --- a/kafka/pom.xml +++ b/kafka/pom.xml @@ -31,7 +31,7 @@ jar - 3.9.2 + 4.3.0 io.cloudevents.kafka diff --git a/kafka/src/main/java/io/cloudevents/kafka/CloudEventSerializer.java b/kafka/src/main/java/io/cloudevents/kafka/CloudEventSerializer.java index 3756516d1..0eba5951b 100644 --- a/kafka/src/main/java/io/cloudevents/kafka/CloudEventSerializer.java +++ b/kafka/src/main/java/io/cloudevents/kafka/CloudEventSerializer.java @@ -56,23 +56,23 @@ public void configure(Map configs, boolean isKey) { throw new IllegalArgumentException("Cannot use CloudEventSerializer as key serializer"); } Object encodingConfig = configs.get(ENCODING_CONFIG); - if (encodingConfig instanceof String) { - this.encoding = Encoding.valueOf((String) encodingConfig); - } else if (encodingConfig instanceof Encoding) { - this.encoding = (Encoding) encodingConfig; + if (encodingConfig instanceof String string) { + this.encoding = Encoding.valueOf(string); + } else if (encodingConfig instanceof Encoding encoding1) { + this.encoding = encoding1; } else if (encodingConfig != null) { throw new IllegalArgumentException(ENCODING_CONFIG + " can be of type String or " + Encoding.class.getCanonicalName()); } if (this.encoding == Encoding.STRUCTURED) { Object eventFormatConfig = configs.get(EVENT_FORMAT_CONFIG); - if (eventFormatConfig instanceof String) { - this.format = EventFormatProvider.getInstance().resolveFormat((String) eventFormatConfig); + if (eventFormatConfig instanceof String string) { + this.format = EventFormatProvider.getInstance().resolveFormat(string); if (this.format == null) { throw new IllegalArgumentException(EVENT_FORMAT_CONFIG + " cannot be resolved with " + eventFormatConfig); } - } else if (eventFormatConfig instanceof EventFormat) { - this.format = (EventFormat) eventFormatConfig; + } else if (eventFormatConfig instanceof EventFormat eventFormat) { + this.format = eventFormat; } else { throw new IllegalArgumentException(EVENT_FORMAT_CONFIG + " cannot be null and can be of type String or " + EventFormat.class.getCanonicalName()); } diff --git a/pom.xml b/pom.xml index e13e660f2..aa3f6b527 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,6 @@ amqp http/basic http/vertx - http/restful-ws http/restful-ws-jakarta kafka spring @@ -85,12 +84,13 @@ - 8 - 8 + 17 + ${java.version} UTF-8 3.27.7 + 10.0.0 5.14.4 3.0.2 @@ -112,6 +112,18 @@ + + + + jakarta.platform + jakarta.jakartaee-bom + ${jakartaee.version} + pom + import + + + + @@ -185,13 +197,13 @@ https://docs.spring.io/spring-framework/docs/current/javadoc-api/ - https://jakarta.ee/specifications/platform/8/apidocs/ - https://kafka.apache.org/39/javadoc/ + https://jakarta.ee/specifications/platform/10/apidocs/ + https://kafka.apache.org/43/javadoc/ https://www.javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/latest/ https://projectreactor.io/docs/core/release/api/ https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/ - 8 + ${java.version} @@ -232,7 +244,6 @@ benchmarks - http/restful-ws-integration-tests http/restful-ws-jakarta-integration-tests examples diff --git a/rocketmq/src/test/java/io/cloudevents/rocketmq/RocketmqMessageFactoryTest.java b/rocketmq/src/test/java/io/cloudevents/rocketmq/RocketmqMessageFactoryTest.java index ea11e2a8f..9d3e75519 100644 --- a/rocketmq/src/test/java/io/cloudevents/rocketmq/RocketmqMessageFactoryTest.java +++ b/rocketmq/src/test/java/io/cloudevents/rocketmq/RocketmqMessageFactoryTest.java @@ -221,7 +221,7 @@ private static Stream binaryTestArguments() { private static AbstractMap.SimpleEntry property(final String name, final String value) { return name.equalsIgnoreCase("ignored") ? new AbstractMap.SimpleEntry<>(name, value) : - new AbstractMap.SimpleEntry<>(String.format(PREFIX_TEMPLATE, name), value); + new AbstractMap.SimpleEntry<>(PREFIX_TEMPLATE.formatted(name), value); } @SafeVarargs diff --git a/spring/pom.xml b/spring/pom.xml index 738091e74..2fb07bf7d 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -32,7 +32,7 @@ io.cloudevents.spring - 2.7.18 + 3.5.14 @@ -115,4 +115,3 @@ - diff --git a/spring/src/main/java/io/cloudevents/spring/http/CloudEventHttpUtils.java b/spring/src/main/java/io/cloudevents/spring/http/CloudEventHttpUtils.java index e8addda99..6c1e603a2 100644 --- a/spring/src/main/java/io/cloudevents/spring/http/CloudEventHttpUtils.java +++ b/spring/src/main/java/io/cloudevents/spring/http/CloudEventHttpUtils.java @@ -27,6 +27,10 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; @@ -52,7 +56,9 @@ private CloudEventHttpUtils() { * @throws CloudEventRWException if something goes wrong while resolving the {@link SpecVersion} or if the message has unknown encoding */ public static MessageReader toReader(HttpHeaders headers, Supplier body) throws CloudEventRWException { - return HttpMessageFactory.createReaderFromMultimap(headers, body.get()); + Map> headersMap = new HashMap<>(); + headers.forEach((key, values) -> headersMap.put(key, new ArrayList<>(values))); + return HttpMessageFactory.createReaderFromMultimap(headersMap, body.get()); } /** diff --git a/spring/src/main/java/io/cloudevents/spring/messaging/CloudEventMessageConverter.java b/spring/src/main/java/io/cloudevents/spring/messaging/CloudEventMessageConverter.java index 2aabc6bb0..325ff738a 100644 --- a/spring/src/main/java/io/cloudevents/spring/messaging/CloudEventMessageConverter.java +++ b/spring/src/main/java/io/cloudevents/spring/messaging/CloudEventMessageConverter.java @@ -49,8 +49,7 @@ public Object fromMessage(Message message, Class targetClass) { @Override public Message toMessage(Object payload, MessageHeaders headers) { - if (payload instanceof CloudEvent) { - CloudEvent event = (CloudEvent) payload; + if (payload instanceof CloudEvent event) { return CloudEventUtils.toReader(event).read(new MessageBuilderMessageWriter(headers)); } return null; @@ -92,11 +91,11 @@ private String contentType(MessageHeaders message) { private byte[] getBinaryData(Message message) { Object payload = message.getPayload(); - if (payload instanceof byte[]) { - return (byte[]) payload; + if (payload instanceof byte[] bytes) { + return bytes; } - else if (payload instanceof String) { - return ((String) payload).getBytes(StandardCharsets.UTF_8); + else if (payload instanceof String string) { + return string.getBytes(StandardCharsets.UTF_8); } return null; } diff --git a/spring/src/main/java/io/cloudevents/spring/mvc/CloudEventHttpMessageConverter.java b/spring/src/main/java/io/cloudevents/spring/mvc/CloudEventHttpMessageConverter.java index bee78967d..a5c17fb56 100644 --- a/spring/src/main/java/io/cloudevents/spring/mvc/CloudEventHttpMessageConverter.java +++ b/spring/src/main/java/io/cloudevents/spring/mvc/CloudEventHttpMessageConverter.java @@ -38,36 +38,35 @@ */ public class CloudEventHttpMessageConverter extends AbstractHttpMessageConverter { - public CloudEventHttpMessageConverter() { - super(MediaType.APPLICATION_OCTET_STREAM, MediaType.ALL); - } + public CloudEventHttpMessageConverter() { + super(MediaType.APPLICATION_OCTET_STREAM, MediaType.ALL); + } - @Override - protected boolean supports(Class clazz) { - return CloudEvent.class.isAssignableFrom(clazz); - } + @Override + protected boolean supports(Class clazz) { + return CloudEvent.class.isAssignableFrom(clazz); + } - @Override - protected CloudEvent readInternal(Class clazz, HttpInputMessage inputMessage) - throws IOException, HttpMessageNotReadableException { - byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody()); - return CloudEventHttpUtils.toReader(inputMessage.getHeaders(), () -> body).toEvent(); - } + @Override + protected CloudEvent readInternal(Class clazz, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody()); + return CloudEventHttpUtils.toReader(inputMessage.getHeaders(), () -> body).toEvent(); + } - @Override - protected void writeInternal(CloudEvent event, HttpOutputMessage outputMessage) - throws IOException, HttpMessageNotWritableException { - CloudEventUtils.toReader(event) - .read(CloudEventHttpUtils.toWriter(outputMessage.getHeaders(), body -> copy(body, outputMessage))); - } + @Override + protected void writeInternal(CloudEvent event, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + CloudEventUtils.toReader(event) + .read(CloudEventHttpUtils.toWriter(outputMessage.getHeaders(), body -> copy(body, outputMessage))); + } - private void copy(byte[] body, HttpOutputMessage outputMessage) { - try { - StreamUtils.copy(body, outputMessage.getBody()); - } - catch (IOException e) { - throw new IllegalStateException(e); - } - } + private void copy(byte[] body, HttpOutputMessage outputMessage) { + try { + StreamUtils.copy(body, outputMessage.getBody()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } } diff --git a/spring/src/test/java/io/cloudevents/spring/mvc/MvcRestControllerTests.java b/spring/src/test/java/io/cloudevents/spring/mvc/MvcRestControllerTests.java index 2e89441a6..5f8dfcf04 100644 --- a/spring/src/test/java/io/cloudevents/spring/mvc/MvcRestControllerTests.java +++ b/spring/src/test/java/io/cloudevents/spring/mvc/MvcRestControllerTests.java @@ -52,156 +52,135 @@ @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) class MvcRestControllerTests { - @Autowired - private TestRestTemplate rest; - - @LocalServerPort - private int port; - - @Test - void echoWithCorrectHeaders() { - - ResponseEntity response = rest.exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/")) // - .header("ce-id", "12345") // - .header("ce-specversion", "1.0") // - .header("ce-type", "io.spring.event") // - .header("ce-source", "https://spring.io/events") // - .contentType(MediaType.APPLICATION_JSON) // - .body("{\"value\":\"Dave\"}"), String.class); - - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); - - HttpHeaders headers = response.getHeaders(); - - assertThat(headers).containsKey("ce-id"); - assertThat(headers).containsKey("ce-source"); - assertThat(headers).containsKey("ce-type"); - - // assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); - assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); - assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); - - } - - @Test - void structuredRequestResponseEvents() { - - ResponseEntity response = rest - .exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/event")) // - .contentType(new MediaType("application", "cloudevents+json")) // - .body("{" // - + "\"id\":\"12345\"," // - + "\"specversion\":\"1.0\"," // - + "\"type\":\"io.spring.event\"," // - + "\"source\":\"https://spring.io/events\"," // - + "\"data\":{\"value\":\"Dave\"}}"), - String.class); - - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); - - HttpHeaders headers = response.getHeaders(); - - assertThat(headers).containsKey("ce-id"); - assertThat(headers).containsKey("ce-source"); - assertThat(headers).containsKey("ce-type"); - - // assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); - assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); - assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); - - } - - @Test - void requestResponseEvents() { - - ResponseEntity response = rest - .exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/event")) // - .header("ce-id", "12345") // - .header("ce-specversion", "1.0") // - .header("ce-type", "io.spring.event") // - .header("ce-source", "https://spring.io/events") // - .contentType(MediaType.APPLICATION_JSON) // - .body("{\"value\":\"Dave\"}"), String.class); - - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); - - HttpHeaders headers = response.getHeaders(); - - assertThat(headers).containsKey("ce-id"); - assertThat(headers).containsKey("ce-source"); - assertThat(headers).containsKey("ce-type"); - - assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); - assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); - assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); - - } - - @SpringBootApplication - @RestController - static class TestApplication { - - @PostMapping("/") - public ResponseEntity echo(@RequestBody Foo foo, @RequestHeader HttpHeaders headers) { - CloudEvent attributes = CloudEventHttpUtils.fromHttp(headers) // - .withId(UUID.randomUUID().toString()) // - .withSource(URI.create("https://spring.io/foos")) // - .withType("io.spring.event.Foo") // - .build(); - HttpHeaders outgoing = CloudEventHttpUtils.toHttp(attributes); - return ResponseEntity.ok().headers(outgoing).body(foo); - } - - @PostMapping("/event") - public CloudEvent ce(@RequestBody CloudEvent event) { - CloudEvent attributes = CloudEventBuilder.from(event) // - .withId(UUID.randomUUID().toString()) // - .withSource(URI.create("https://spring.io/foos")) // - .withType("io.spring.event.Foo") // - .withData(event.getData().toBytes()) // - .build(); - return attributes; - } - - @Configuration - public static class CloudEventHandlerConfiguration implements WebMvcConfigurer { - - @Override - public void configureMessageConverters(List> converters) { - converters.add(0, new CloudEventHttpMessageConverter()); - } - - } - - } + @Autowired + private TestRestTemplate rest; + + @LocalServerPort + private int port; + + @Test + void echoWithCorrectHeaders() { + + ResponseEntity response = rest.exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/")) // + .header("ce-id", "12345") // + .header("ce-specversion", "1.0") // + .header("ce-type", "io.spring.event") // + .header("ce-source", "https://spring.io/events") // + .contentType(MediaType.APPLICATION_JSON) // + .body("{\"value\":\"Dave\"}"), String.class); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); + + HttpHeaders headers = response.getHeaders(); + + assertThat(headers).containsKey("ce-id"); + assertThat(headers).containsKey("ce-source"); + assertThat(headers).containsKey("ce-type"); + + // assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); + assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); + assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); + + } + + @Test + void structuredRequestResponseEvents() { + + ResponseEntity response = rest + .exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/event")) // + .contentType(new MediaType("application", "cloudevents+json")) // + .body(""" + { + "id":"12345", + "specversion":"1.0", + "type":"io.spring.event", + "source":"https://spring.io/events", + "data":{"value":"Dave"}}"""), + String.class); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); + + HttpHeaders headers = response.getHeaders(); + + assertThat(headers).containsKey("ce-id"); + assertThat(headers).containsKey("ce-source"); + assertThat(headers).containsKey("ce-type"); + + // assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); + assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); + assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); + + } + + @Test + void requestResponseEvents() { + + ResponseEntity response = rest + .exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/event")) // + .header("ce-id", "12345") // + .header("ce-specversion", "1.0") // + .header("ce-type", "io.spring.event") // + .header("ce-source", "https://spring.io/events") // + .contentType(MediaType.APPLICATION_JSON) // + .body("{\"value\":\"Dave\"}"), String.class); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); + + HttpHeaders headers = response.getHeaders(); + + assertThat(headers).containsKey("ce-id"); + assertThat(headers).containsKey("ce-source"); + assertThat(headers).containsKey("ce-type"); + + assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); + assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); + assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); + + } + + @SpringBootApplication + @RestController + static class TestApplication { + + @PostMapping("/") + public ResponseEntity echo(@RequestBody Foo foo, @RequestHeader HttpHeaders headers) { + CloudEvent attributes = CloudEventHttpUtils.fromHttp(headers) // + .withId(UUID.randomUUID().toString()) // + .withSource(URI.create("https://spring.io/foos")) // + .withType("io.spring.event.Foo") // + .build(); + HttpHeaders outgoing = CloudEventHttpUtils.toHttp(attributes); + return ResponseEntity.ok().headers(outgoing).body(foo); + } + + @PostMapping("/event") + public CloudEvent ce(@RequestBody CloudEvent event) { + CloudEvent attributes = CloudEventBuilder.from(event) // + .withId(UUID.randomUUID().toString()) // + .withSource(URI.create("https://spring.io/foos")) // + .withType("io.spring.event.Foo") // + .withData(event.getData().toBytes()) // + .build(); + return attributes; + } + + @Configuration + public static class CloudEventHandlerConfiguration implements WebMvcConfigurer { + + @Override + public void configureMessageConverters(List> converters) { + converters.add(0, new CloudEventHttpMessageConverter()); + } + + } + + } } -class Foo { - - private String value; - - public Foo() { - } - - public Foo(String value) { - this.value = value; - } - - public String getValue() { - return this.value; - } - - public void setValue(String value) { - this.value = value; - } - - @Override - public String toString() { - return "Foo [value=" + this.value + "]"; - } - -} +record Foo( + String value +) {} diff --git a/spring/src/test/java/io/cloudevents/spring/webflux/WebFluxRestControllerTests.java b/spring/src/test/java/io/cloudevents/spring/webflux/WebFluxRestControllerTests.java index c98f03943..0fdf6734b 100644 --- a/spring/src/test/java/io/cloudevents/spring/webflux/WebFluxRestControllerTests.java +++ b/spring/src/test/java/io/cloudevents/spring/webflux/WebFluxRestControllerTests.java @@ -52,150 +52,129 @@ @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=REACTIVE") class WebFluxRestControllerTests { - @Autowired - private TestRestTemplate rest; + @Autowired + private TestRestTemplate rest; - @LocalServerPort - private int port; - - @Test - void echoWithCorrectHeaders() { - - ResponseEntity response = rest.exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/")) // - .header("ce-id", "12345") // - .header("ce-specversion", "1.0") // - .header("ce-type", "io.spring.event") // - .header("ce-source", "https://spring.io/events") // - .contentType(MediaType.APPLICATION_JSON) // - .body("{\"value\":\"Dave\"}"), String.class); - - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); + @LocalServerPort + private int port; + + @Test + void echoWithCorrectHeaders() { + + ResponseEntity response = rest.exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/")) // + .header("ce-id", "12345") // + .header("ce-specversion", "1.0") // + .header("ce-type", "io.spring.event") // + .header("ce-source", "https://spring.io/events") // + .contentType(MediaType.APPLICATION_JSON) // + .body("{\"value\":\"Dave\"}"), String.class); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); + + HttpHeaders headers = response.getHeaders(); - HttpHeaders headers = response.getHeaders(); + assertThat(headers).containsKey("ce-id"); + assertThat(headers).containsKey("ce-source"); + assertThat(headers).containsKey("ce-type"); - assertThat(headers).containsKey("ce-id"); - assertThat(headers).containsKey("ce-source"); - assertThat(headers).containsKey("ce-type"); + // assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); + assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); + assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); - // assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); - assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); - assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); + } - } + @Test + void structuredRequestResponseEvents() { - @Test - void structuredRequestResponseEvents() { + ResponseEntity response = rest + .exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/event")) // + .contentType(new MediaType("application", "cloudevents+json")) // + .body(""" + { + "id":"12345", + "specversion":"1.0", + "type":"io.spring.event", + "source":"https://spring.io/events", + "data":{"value":"Dave"}}"""), + String.class); - ResponseEntity response = rest - .exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/event")) // - .contentType(new MediaType("application", "cloudevents+json")) // - .body("{" // - + "\"id\":\"12345\"," // - + "\"specversion\":\"1.0\"," // - + "\"type\":\"io.spring.event\"," // - + "\"source\":\"https://spring.io/events\"," // - + "\"data\":{\"value\":\"Dave\"}}"), - String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); + HttpHeaders headers = response.getHeaders(); - HttpHeaders headers = response.getHeaders(); + assertThat(headers).containsKey("ce-id"); + assertThat(headers).containsKey("ce-source"); + assertThat(headers).containsKey("ce-type"); - assertThat(headers).containsKey("ce-id"); - assertThat(headers).containsKey("ce-source"); - assertThat(headers).containsKey("ce-type"); + assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); + assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); + assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); - assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); - assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); - assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); + } - } + @Test + void requestResponseEvents() { - @Test - void requestResponseEvents() { + ResponseEntity response = rest + .exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/event")) // + .header("ce-id", "12345") // + .header("ce-specversion", "1.0") // + .header("ce-type", "io.spring.event") // + .header("ce-source", "https://spring.io/events") // + .contentType(MediaType.APPLICATION_JSON) // + .body("{\"value\":\"Dave\"}"), String.class); - ResponseEntity response = rest - .exchange(RequestEntity.post(URI.create("http://localhost:" + port + "/event")) // - .header("ce-id", "12345") // - .header("ce-specversion", "1.0") // - .header("ce-type", "io.spring.event") // - .header("ce-source", "https://spring.io/events") // - .contentType(MediaType.APPLICATION_JSON) // - .body("{\"value\":\"Dave\"}"), String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getBody()).isEqualTo("{\"value\":\"Dave\"}"); + HttpHeaders headers = response.getHeaders(); - HttpHeaders headers = response.getHeaders(); + assertThat(headers).containsKey("ce-id"); + assertThat(headers).containsKey("ce-source"); + assertThat(headers).containsKey("ce-type"); - assertThat(headers).containsKey("ce-id"); - assertThat(headers).containsKey("ce-source"); - assertThat(headers).containsKey("ce-type"); + assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); + assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); + assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); - assertThat(headers.getFirst("ce-id")).isNotEqualTo("12345"); - assertThat(headers.getFirst("ce-type")).isEqualTo("io.spring.event.Foo"); - assertThat(headers.getFirst("ce-source")).isEqualTo("https://spring.io/foos"); + } - } + @SpringBootApplication + @RestController + static class TestApplication { - @SpringBootApplication - @RestController - static class TestApplication { + @PostMapping("/") + public ResponseEntity echo(@RequestBody Foo foo, @RequestHeader HttpHeaders headers) { + CloudEvent attributes = CloudEventHttpUtils.fromHttp(headers).withId(UUID.randomUUID().toString()) + .withSource(URI.create("https://spring.io/foos")).withType("io.spring.event.Foo").build(); + HttpHeaders outgoing = CloudEventHttpUtils.toHttp(attributes); + return ResponseEntity.ok().headers(outgoing).body(foo); + } - @PostMapping("/") - public ResponseEntity echo(@RequestBody Foo foo, @RequestHeader HttpHeaders headers) { - CloudEvent attributes = CloudEventHttpUtils.fromHttp(headers).withId(UUID.randomUUID().toString()) - .withSource(URI.create("https://spring.io/foos")).withType("io.spring.event.Foo").build(); - HttpHeaders outgoing = CloudEventHttpUtils.toHttp(attributes); - return ResponseEntity.ok().headers(outgoing).body(foo); - } + @PostMapping("/event") + public Mono event(@RequestBody Mono body) { + return body.map(event -> CloudEventBuilder.from(event).withId(UUID.randomUUID().toString()) + .withSource(URI.create("https://spring.io/foos")).withType("io.spring.event.Foo") + .withData(event.getData().toBytes()).build()); + } - @PostMapping("/event") - public Mono event(@RequestBody Mono body) { - return body.map(event -> CloudEventBuilder.from(event).withId(UUID.randomUUID().toString()) - .withSource(URI.create("https://spring.io/foos")).withType("io.spring.event.Foo") - .withData(event.getData().toBytes()).build()); - } + @Configuration + public static class CloudEventHandlerConfiguration implements CodecCustomizer { - @Configuration - public static class CloudEventHandlerConfiguration implements CodecCustomizer { + @Override + public void customize(CodecConfigurer configurer) { + configurer.customCodecs().register(new CloudEventHttpMessageReader()); + configurer.customCodecs().register(new CloudEventHttpMessageWriter()); + } - @Override - public void customize(CodecConfigurer configurer) { - configurer.customCodecs().register(new CloudEventHttpMessageReader()); - configurer.customCodecs().register(new CloudEventHttpMessageWriter()); - } + } - } - - } + } } -class Foo { - - private String value; - - public Foo() { - } - - public Foo(String value) { - this.value = value; - } - - public String getValue() { - return this.value; - } - - public void setValue(String value) { - this.value = value; - } - - @Override - public String toString() { - return "Foo [value=" + this.value + "]"; - } - -} \ No newline at end of file +record Foo( + String value +) {} diff --git a/sql/src/main/java/io/cloudevents/sql/EvaluationException.java b/sql/src/main/java/io/cloudevents/sql/EvaluationException.java index fff1d627d..6096a27d3 100644 --- a/sql/src/main/java/io/cloudevents/sql/EvaluationException.java +++ b/sql/src/main/java/io/cloudevents/sql/EvaluationException.java @@ -48,7 +48,7 @@ public enum ErrorKind { private final String expression; public EvaluationException(ErrorKind errorKind, Interval interval, String expression, String message, Throwable cause) { - super(String.format("%s at %s `%s`: %s", errorKind.name(), interval.toString(), expression, message), cause); + super("%s at %s `%s`: %s".formatted(errorKind.name(), interval.toString(), expression, message), cause); this.errorKind = errorKind; this.interval = interval; this.expression = expression; diff --git a/sql/src/main/java/io/cloudevents/sql/ParseException.java b/sql/src/main/java/io/cloudevents/sql/ParseException.java index 7fd477f53..e631a696c 100644 --- a/sql/src/main/java/io/cloudevents/sql/ParseException.java +++ b/sql/src/main/java/io/cloudevents/sql/ParseException.java @@ -27,7 +27,7 @@ public enum ErrorKind { private final String expression; public ParseException(ErrorKind errorKind, Interval interval, String expression, String message, Throwable cause) { - super(String.format("[%s at %d:%d `%s`] %s", errorKind.name(), interval.a, interval.b, expression, message), cause); + super("[%s at %d:%d `%s`] %s".formatted(errorKind.name(), interval.a, interval.b, expression, message), cause); this.errorKind = errorKind; this.interval = interval; this.expression = expression; diff --git a/sql/src/main/java/io/cloudevents/sql/impl/expressions/AccessAttributeExpression.java b/sql/src/main/java/io/cloudevents/sql/impl/expressions/AccessAttributeExpression.java index 7fd776bf4..65909ddb5 100644 --- a/sql/src/main/java/io/cloudevents/sql/impl/expressions/AccessAttributeExpression.java +++ b/sql/src/main/java/io/cloudevents/sql/impl/expressions/AccessAttributeExpression.java @@ -49,8 +49,8 @@ private static Object coherceTypes(Object value) { // No casting required return value; } - if (value instanceof byte[]) { - return Base64.getEncoder().encodeToString((byte[]) value); + if (value instanceof byte[] bytes) { + return Base64.getEncoder().encodeToString(bytes); } return Objects.toString(value); } diff --git a/sql/src/main/java/io/cloudevents/sql/impl/runtime/TypeCastingProvider.java b/sql/src/main/java/io/cloudevents/sql/impl/runtime/TypeCastingProvider.java index 418517cee..9517a7328 100644 --- a/sql/src/main/java/io/cloudevents/sql/impl/runtime/TypeCastingProvider.java +++ b/sql/src/main/java/io/cloudevents/sql/impl/runtime/TypeCastingProvider.java @@ -13,9 +13,9 @@ public static boolean canCast(Object value, Type target) { } switch (target) { case INTEGER: - if (value instanceof String) { + if (value instanceof String string) { try { - Integer.parseInt((String) value); + Integer.parseInt(string); return true; } catch (NumberFormatException e) { return false; @@ -23,9 +23,9 @@ public static boolean canCast(Object value, Type target) { } return value instanceof Boolean; case BOOLEAN: - if (value instanceof String) { + if (value instanceof String string) { try { - parseBool((String) value); + parseBool(string); return true; } catch (IllegalArgumentException e) { return false; diff --git a/sql/src/test/java/io/cloudevents/sql/TCKTestSuite.java b/sql/src/test/java/io/cloudevents/sql/TCKTestSuite.java index 3a5a16b89..dee300c4b 100644 --- a/sql/src/test/java/io/cloudevents/sql/TCKTestSuite.java +++ b/sql/src/test/java/io/cloudevents/sql/TCKTestSuite.java @@ -60,12 +60,12 @@ public CloudEvent getTestInputEvent() { if (this.eventOverrides != null) { CloudEventBuilder builder = CloudEventBuilder.from(inputEvent); this.eventOverrides.forEach((k, v) -> { - if (v instanceof String) { - builder.withContextAttribute(k, (String) v); - } else if (v instanceof Boolean) { - builder.withContextAttribute(k, (Boolean) v); - } else if (v instanceof Number) { - builder.withContextAttribute(k, ((Number) v).intValue()); + if (v instanceof String string) { + builder.withContextAttribute(k, string); + } else if (v instanceof Boolean bool) { + builder.withContextAttribute(k, bool); + } else if (v instanceof Number number) { + builder.withContextAttribute(k, number.intValue()); } else { throw new IllegalArgumentException("Unexpected event override attribute '" + k + "' type: " + v.getClass()); }