Skip to content

Commit 7a1a197

Browse files
Removed deprecated restful-ws modules
1 parent 6232cb6 commit 7a1a197

49 files changed

Lines changed: 301 additions & 2493 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/restful-ws-spring-boot/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<dependencies>
3333
<dependency>
3434
<groupId>org.springframework.boot</groupId>
35-
<artifactId>spring-boot-starter-jersey</artifactId>
35+
<artifactId>spring-boot-starter-web</artifactId>
3636
<version>${spring-boot.version}</version>
3737
</dependency>
3838
<dependency>
@@ -51,6 +51,12 @@
5151
<artifactId>cloudevents-http-restful-ws</artifactId>
5252
<version>${project.version}</version>
5353
</dependency>
54+
<dependency>
55+
<groupId>io.cloudevents</groupId>
56+
<artifactId>cloudevents-spring</artifactId>
57+
<version>4.1.0-SNAPSHOT</version>
58+
<scope>compile</scope>
59+
</dependency>
5460
</dependencies>
5561

5662
<build>

examples/restful-ws-spring-boot/src/main/java/io/cloudevents/examples/springboot/MainResource.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,45 @@
1717

1818
package io.cloudevents.examples.springboot;
1919

20-
import com.fasterxml.jackson.databind.ObjectMapper;
2120
import io.cloudevents.CloudEvent;
2221
import io.cloudevents.core.builder.CloudEventBuilder;
2322
import io.cloudevents.core.data.PojoCloudEventData;
2423
import io.cloudevents.jackson.PojoCloudEventDataMapper;
2524
import org.springframework.beans.factory.annotation.Autowired;
26-
27-
import javax.ws.rs.POST;
28-
import javax.ws.rs.Path;
29-
import javax.ws.rs.core.MediaType;
30-
import javax.ws.rs.core.Response;
25+
import org.springframework.http.MediaType;
26+
import org.springframework.http.ResponseEntity;
27+
import org.springframework.web.bind.annotation.PostMapping;
28+
import org.springframework.web.bind.annotation.RequestBody;
29+
import org.springframework.web.bind.annotation.RestController;
30+
import tools.jackson.databind.ObjectMapper;
3131

3232
import static io.cloudevents.core.CloudEventUtils.mapData;
3333

34-
@Path("/")
34+
@RestController
3535
public class MainResource {
36-
3736
public static final String HAPPY_BIRTHDAY_EVENT_TYPE = "happybirthday.myapplication";
38-
3937
@Autowired
40-
ObjectMapper objectMapper;
38+
private ObjectMapper objectMapper;
4139

42-
@POST
43-
@Path("happy_birthday")
44-
public Response handleHappyBirthdayEvent(CloudEvent inputEvent) {
40+
@PostMapping("/happy_birthday")
41+
public ResponseEntity handleHappyBirthdayEvent(@RequestBody CloudEvent inputEvent) {
4542
if (!inputEvent.getType().equals(HAPPY_BIRTHDAY_EVENT_TYPE)) {
46-
return Response.status(Response.Status.BAD_REQUEST)
47-
.type(MediaType.TEXT_PLAIN)
48-
.entity("Event type should be \"" + HAPPY_BIRTHDAY_EVENT_TYPE + "\" but is \"" + inputEvent.getType() + "\"")
49-
.build();
43+
return ResponseEntity.badRequest()
44+
.contentType(MediaType.TEXT_PLAIN)
45+
.body("Event type should be \"" + HAPPY_BIRTHDAY_EVENT_TYPE + "\" but is \"" + inputEvent.getType() + "\"");
5046
}
5147

5248
PojoCloudEventData<User> cloudEventData = mapData(inputEvent, PojoCloudEventDataMapper.from(objectMapper, User.class));
5349

5450
if (cloudEventData == null) {
55-
return Response.status(Response.Status.BAD_REQUEST)
56-
.type(MediaType.TEXT_PLAIN)
57-
.entity("Event should contain the user")
58-
.build();
51+
return ResponseEntity.badRequest().contentType(MediaType.TEXT_PLAIN).body("Event should contain the user");
5952
}
6053

6154
User user = cloudEventData.getValue();
6255
user.setAge(user.getAge() + 1);
6356

64-
CloudEvent outputEvent = CloudEventBuilder.from(inputEvent)
65-
.withData(PojoCloudEventData.wrap(user, objectMapper::writeValueAsBytes))
66-
.build();
57+
CloudEvent outputEvent = CloudEventBuilder.from(inputEvent).withData(PojoCloudEventData.wrap(user, objectMapper::writeValueAsBytes)).build();
6758

68-
return Response.ok(outputEvent).build();
59+
return ResponseEntity.ok(outputEvent);
6960
}
7061
}

examples/restful-ws-spring-boot/src/main/java/io/cloudevents/examples/springboot/JerseyConfiguration.java renamed to examples/restful-ws-spring-boot/src/main/java/io/cloudevents/examples/springboot/WebConfig.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@
1717

1818
package io.cloudevents.examples.springboot;
1919

20-
import io.cloudevents.http.restful.ws.CloudEventsProvider;
21-
import org.glassfish.jersey.server.ResourceConfig;
20+
import io.cloudevents.spring.mvc.CloudEventHttpMessageConverter;
21+
import org.springframework.context.annotation.Bean;
2222
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.http.converter.HttpMessageConverters;
24+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
25+
import tools.jackson.databind.ObjectMapper;
2326

2427
@Configuration
25-
public class JerseyConfiguration extends ResourceConfig {
26-
27-
public JerseyConfiguration() {
28-
// Configure Jersey to load the CloudEventsProvider (which serializes/deserializes CloudEvents)
29-
// and our resource
30-
registerClasses(CloudEventsProvider.class, MainResource.class);
28+
public class WebConfig implements WebMvcConfigurer {
29+
@Override
30+
public void configureMessageConverters(HttpMessageConverters.ServerBuilder builder) {
31+
builder.addCustomConverter(new CloudEventHttpMessageConverter());
3132
}
3233

34+
@Bean
35+
public ObjectMapper objectMapper(){
36+
return new ObjectMapper();
37+
}
3338
}

http/restful-ws-integration-tests/restful-ws-spring/pom.xml renamed to http/integration-tests/pom.xml

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@
2020
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2121
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2222
<parent>
23-
<artifactId>cloudevents-http-restful-ws-integration-tests</artifactId>
23+
<artifactId>cloudevents-parent</artifactId>
2424
<groupId>io.cloudevents</groupId>
2525
<version>4.1.0-SNAPSHOT</version>
26-
<relativePath>../pom.xml</relativePath>
26+
<relativePath>../../pom.xml</relativePath>
2727
</parent>
2828
<modelVersion>4.0.0</modelVersion>
2929

30-
<artifactId>cloudevents-http-restful-ws-integration-tests-spring</artifactId>
31-
<name>CloudEvents - JAX-RS Integration Tests - Spring</name>
30+
<artifactId>cloudevents-integration-tests</artifactId>
31+
<name>CloudEvents - Spring Http Integration Tests</name>
3232
<packaging>jar</packaging>
3333

3434
<properties>
35-
<module-name>io.cloudevents.jaxrs.integration.tests.spring</module-name>
35+
<!-- No need to generate javadocs for these IT tests -->
36+
<maven.javadoc.skip>true</maven.javadoc.skip>
3637
<spring-boot.version>4.0.0</spring-boot.version>
3738
<spring.version>7.0.2</spring.version>
3839
</properties>
@@ -50,32 +51,44 @@
5051
</dependencyManagement>
5152

5253
<dependencies>
53-
5454
<dependency>
5555
<groupId>io.cloudevents</groupId>
56-
<artifactId>cloudevents-http-restful-ws-integration-tests-common</artifactId>
56+
<artifactId>cloudevents-core</artifactId>
57+
<classifier>tests</classifier>
58+
<type>test-jar</type>
59+
<version>${project.version}</version>
60+
<scope>test</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>io.cloudevents</groupId>
64+
<artifactId>cloudevents-http-basic</artifactId>
65+
<version>${project.version}</version>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>io.cloudevents</groupId>
70+
<artifactId>cloudevents-spring</artifactId>
71+
<version>${project.version}</version>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>io.cloudevents</groupId>
76+
<artifactId>cloudevents-json-jackson</artifactId>
5777
<version>${project.version}</version>
5878
<scope>test</scope>
5979
</dependency>
60-
6180
<dependency>
6281
<groupId>org.springframework.boot</groupId>
63-
<artifactId>spring-boot-starter-jersey</artifactId>
82+
<artifactId>spring-boot-starter-test</artifactId>
6483
<version>${spring-boot.version}</version>
6584
<scope>test</scope>
6685
</dependency>
6786
<dependency>
6887
<groupId>org.springframework.boot</groupId>
69-
<artifactId>spring-boot-starter-test</artifactId>
88+
<artifactId>spring-boot-starter-web</artifactId>
7089
<version>${spring-boot.version}</version>
7190
<scope>test</scope>
72-
<exclusions>
73-
<exclusion>
74-
<groupId>org.junit.vintage</groupId>
75-
<artifactId>junit-vintage-engine</artifactId>
76-
</exclusion>
77-
</exclusions>
7891
</dependency>
79-
8092
</dependencies>
93+
8194
</project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2018-Present The CloudEvents Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package io.cloudevents.http.restful.ws.spring;
19+
20+
import io.cloudevents.CloudEvent;
21+
import io.cloudevents.core.test.Data;
22+
import io.cloudevents.spring.mvc.CloudEventHttpMessageConverter;
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
25+
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.http.HttpStatus;
27+
import org.springframework.http.converter.HttpMessageConverters;
28+
import org.springframework.web.bind.annotation.GetMapping;
29+
import org.springframework.web.bind.annotation.PostMapping;
30+
import org.springframework.web.bind.annotation.RequestBody;
31+
import org.springframework.web.bind.annotation.RestController;
32+
import org.springframework.web.server.ResponseStatusException;
33+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
34+
35+
@SpringBootApplication(scanBasePackages = {"io.cloudevents.http.restful.ws"})
36+
public class TestApplication extends SpringBootServletInitializer {
37+
@Configuration
38+
public static class WebConfig implements WebMvcConfigurer {
39+
@Override
40+
public void configureMessageConverters(HttpMessageConverters.ServerBuilder builder) {
41+
builder.addCustomConverter(new CloudEventHttpMessageConverter());
42+
}
43+
}
44+
45+
@RestController
46+
public static class TestResource {
47+
@GetMapping("/getMinEvent")
48+
public CloudEvent getMinEvent() {
49+
return Data.V1_MIN;
50+
}
51+
52+
@GetMapping(path = "/getStructuredEventCsv", produces = "application/cloudevents+csv")
53+
public CloudEvent getStructuredEventCsv() {
54+
return Data.V1_MIN;
55+
}
56+
57+
@GetMapping(path = "/getStructuredEventJson", produces = "application/cloudevents+json")
58+
public CloudEvent getStructuredEventJson() {
59+
return Data.V1_MIN;
60+
}
61+
62+
@GetMapping(value = "/getEvent")
63+
public CloudEvent getEvent() {
64+
return Data.V1_WITH_JSON_DATA_WITH_EXT_STRING;
65+
}
66+
67+
@PostMapping("/postEventWithoutBody")
68+
public void postEventWithoutBody(@RequestBody CloudEvent inputEvent) {
69+
if (!inputEvent.equals(Data.V1_MIN)) {
70+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR);
71+
}
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)