Skip to content

Commit 38fd673

Browse files
authored
fix: sprint-boot template
Signed-off-by: Matej Vasek <mvasek@redhat.com>
1 parent 6d2d8c6 commit 38fd673

File tree

4 files changed

+24
-31
lines changed

4 files changed

+24
-31
lines changed

pkged.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/springboot/events/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<properties>
1919
<java.version>11</java.version>
20-
<spring-cloud-function.version>3.1.0-SNAPSHOT</spring-cloud-function.version>
20+
<spring-cloud-function.version>3.1.1</spring-cloud-function.version>
2121
<compiler-plugin.version>3.8.1</compiler-plugin.version>
2222
<maven.compiler.parameters>true</maven.compiler.parameters>
2323
<maven.compiler.source>11</maven.compiler.source>

templates/springboot/events/src/main/java/functions/SpringCloudEventsApplication.java

+16-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package functions;
22

3-
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.HTTP_ATTR_PREFIX;
43
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.ID;
54
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.SOURCE;
65
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.SPECVERSION;
@@ -12,7 +11,7 @@
1211
import java.util.logging.Logger;
1312
import org.springframework.boot.SpringApplication;
1413
import org.springframework.boot.autoconfigure.SpringBootApplication;
15-
import org.springframework.cloud.function.cloudevent.CloudEventAttributesProvider;
14+
import org.springframework.cloud.function.cloudevent.CloudEventHeaderEnricher;
1615
import org.springframework.cloud.function.web.util.HeaderUtils;
1716
import org.springframework.context.annotation.Bean;
1817
import org.springframework.http.HttpHeaders;
@@ -29,42 +28,37 @@ public static void main(String[] args) {
2928
}
3029

3130
@Bean
32-
public Function<Message<Input>, Output> uppercase(
33-
CloudEventAttributesProvider provider) {
31+
public Function<Message<Input>, Output> uppercase(CloudEventHeaderEnricher enricher) {
3432
return m -> {
3533
HttpHeaders httpHeaders = HeaderUtils.fromMessage(m.getHeaders());
36-
37-
;
34+
3835
LOGGER.log(Level.INFO, "Input CE Id:{0}", httpHeaders.getFirst(
39-
HTTP_ATTR_PREFIX + ID));
36+
ID));
4037
LOGGER.log(Level.INFO, "Input CE Spec Version:{0}",
41-
httpHeaders.getFirst(HTTP_ATTR_PREFIX + SPECVERSION));
38+
httpHeaders.getFirst(SPECVERSION));
4239
LOGGER.log(Level.INFO, "Input CE Source:{0}",
43-
httpHeaders.getFirst(HTTP_ATTR_PREFIX + SOURCE));
40+
httpHeaders.getFirst(SOURCE));
4441
LOGGER.log(Level.INFO, "Input CE Subject:{0}",
45-
httpHeaders.getFirst(HTTP_ATTR_PREFIX + SUBJECT));
42+
httpHeaders.getFirst(SUBJECT));
4643

4744
Input input = m.getPayload();
4845
LOGGER.log(Level.INFO, "Input {0} ", input);
4946
Output output = new Output();
5047
output.input = input.input;
51-
output.operation = httpHeaders.getFirst(HTTP_ATTR_PREFIX + SUBJECT);
52-
output.output =
53-
input.input != null ? input.input.toUpperCase() : "NO DATA";
48+
output.operation = httpHeaders.getFirst(SUBJECT);
49+
output.output = input.input != null ? input.input.toUpperCase() : "NO DATA";
5450
return output;
5551
};
5652
}
5753

5854
@Bean
59-
public CloudEventAttributesProvider attributesProvider() {
60-
return attributes -> {
61-
attributes
62-
.setSpecversion("1.0")
63-
.setId(UUID.randomUUID()
64-
.toString())
65-
.setSource("http://example.com/uppercase")
66-
.setType("com.redhat.faas.springboot.events");
67-
};
55+
public CloudEventHeaderEnricher attributesProvider() {
56+
return attributes -> attributes
57+
.setSpecVersion("1.0")
58+
.setId(UUID.randomUUID()
59+
.toString())
60+
.setSource("http://example.com/uppercase")
61+
.setType("com.redhat.faas.springboot.events");
6862
}
6963

7064
/**

templates/springboot/events/src/test/java/functions/SpringCloudEventsApplicationTests.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.hamcrest.Matchers.equalTo;
55
import static org.hamcrest.Matchers.notNullValue;
66
import static org.hamcrest.Matchers.nullValue;
7-
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.HTTP_ATTR_PREFIX;
87
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.ID;
98
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.SOURCE;
109
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.SPECVERSION;
@@ -27,7 +26,7 @@
2726
@SpringBootTest(classes = SpringCloudEventsApplication.class,
2827
webEnvironment = WebEnvironment.RANDOM_PORT)
2928
public class SpringCloudEventsApplicationTests {
30-
29+
3130
@Autowired
3231
private TestRestTemplate rest;
3332

@@ -42,12 +41,12 @@ public void testUpperCaseJsonInput() throws Exception {
4241
input.input = "hello";
4342

4443
HttpHeaders ceHeaders = new HttpHeaders();
45-
ceHeaders.add(HTTP_ATTR_PREFIX + SPECVERSION, "1.0");
46-
ceHeaders.add(HTTP_ATTR_PREFIX + ID, UUID.randomUUID()
44+
ceHeaders.add(SPECVERSION, "1.0");
45+
ceHeaders.add(ID, UUID.randomUUID()
4746
.toString());
48-
ceHeaders.add(HTTP_ATTR_PREFIX + TYPE, "com.redhat.faas.springboot.test");
49-
ceHeaders.add(HTTP_ATTR_PREFIX + SOURCE, "http://localhost:8080/uppercase");
50-
ceHeaders.add(HTTP_ATTR_PREFIX + SUBJECT, "Convert to UpperCase");
47+
ceHeaders.add(TYPE, "com.redhat.faas.springboot.test");
48+
ceHeaders.add(SOURCE, "http://localhost:8080/uppercase");
49+
ceHeaders.add(SUBJECT, "Convert to UpperCase");
5150

5251
ResponseEntity<String> response = this.rest.exchange(
5352
RequestEntity.post(new URI("/uppercase"))

0 commit comments

Comments
 (0)