quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.53k stars 2.61k forks source link

Missing cloudevents artifacts definitions on Quarkus BOM #29281

Open pjgg opened 1 year ago

pjgg commented 1 year ago

Describe the bug

I have an HTTP endpoint that directly consume CloudEvents

For example

@Path("/events")
public class EventResource {

    @Inject
    ObjectMapper mapper;

@POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("/pureCE")
    public EventDTO pureCloudEventPayload(@Valid CloudEvent event) {
        if (event == null || event.getData() == null) {
            throw new BadRequestException("Invalid data received. Null or empty event");
        }

        return EventDTO.fromCloudEvent(mapper, event);
    }

EventDTO

@RegisterForReflection
public class EventDTO implements Serializable {

    private static final long serialVersionUID = 1305278483346223763L;

    public static EventDTO fromCloudEvent(ObjectMapper mapper, CloudEvent cloudEvent) {
        return PojoCloudEventDataMapper
                .from(mapper, EventDTO.class)
                .map(cloudEvent.getData())
                .getValue();
    }

   @NotNull(message = "Call UUID value should be not null")
    @NotBlank(message = "Call UUID may not be blank")
    private String callUUID;

    @NotNull(message = "Timestamp value should be not null")
    @NotBlank(message = "Timestamp may not be blank")
    private String timestamp;

    @NotNull(message = "Service UUID value should be not null")
    @NotBlank(message = "Service UUID may not be blank")
    private String serviceUUID;

    @NotNull(message = "IP Address value should be not null")
    @NotBlank(message = "IP Address may not be blank")
    private String ipAddress;

    private String message;  
    .
    . // getters & setters
    .
    .

   public CloudEventData toCloudEventData(ObjectMapper mapper) {
        return PojoCloudEventData.wrap(this, mapper::writeValueAsBytes);
    }

Request example through rest assurance

@Test
    public void verifyPureCloudEvents() {
        EventDTO event = defaultEventDto();
        makeCloudEventPost(event, "/events/pureCE")
                .then()
                .statusCode(HttpStatus.SC_OK)
                .body("message", is(EXPECTED_MSG));
    }

     private EventDTO defaultEventDto() {
        EventDTO event = new EventDTO();
        event.setCallUUID(UUID.randomUUID().toString());
        event.setMessage(EXPECTED_MSG);
        event.setIpAddress("192.168.2.1");
        event.setServiceUUID(UUID.randomUUID().toString());
        event.setTimestamp((new Timestamp(System.currentTimeMillis())).toString());
        return event;
    }

    private Response makeCloudEventPost(EventDTO event, String path) {
        return given().body(event)
                .contentType(ContentType.JSON)
                .header("Ce-Specversion", "1.0")
                .header("Ce-Type", "EventDTO")
                .header("Ce-Source", "io.quarkus.ts.http.cloudevents/eventDTO")
                .header("Ce-Id", UUID.randomUUID().toString())
                .header("Ce-Subject", "SUBJ-0001")
                .post(path);
    }

And What I see is that Quarkus are missing the following artifacts on Quarkus BOM

       <dependency>
            <groupId>io.cloudevents</groupId>
            <artifactId>cloudevents-api</artifactId>
        </dependency>
        <dependency>
            <groupId>io.cloudevents</groupId>
            <artifactId>cloudevents-http-restful-ws</artifactId>
        </dependency>
        <dependency>
            <groupId>io.cloudevents</groupId>
            <artifactId>cloudevents-json-jackson</artifactId>
        </dependency>

Also the Hibernate-validation annotations doesn't look that are working with HTTP CloudEvents.

I saw that other extensions as Funqy or Kafka has a clear integration with CloudEvents. But has Quarkus-resteasy (classic or reactive) an integration with cloudEvents?

How to Reproduce?

git clone -b GH-29208 https://github.com/pjgg/quarkus-test-suite.git cd quarkus-test-suite/http/http-cloud-events mvn clean verify

quarkus-bot[bot] commented 1 year ago

/cc @matejvasek, @patriot1burke