Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: spring-boot template #265

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkged.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion templates/springboot/events/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<properties>
<java.version>11</java.version>
<spring-cloud-function.version>3.1.0-SNAPSHOT</spring-cloud-function.version>
<spring-cloud-function.version>3.1.1</spring-cloud-function.version>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package functions;

import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.HTTP_ATTR_PREFIX;
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.ID;
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.SOURCE;
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.SPECVERSION;
Expand All @@ -12,7 +11,7 @@
import java.util.logging.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.function.cloudevent.CloudEventAttributesProvider;
import org.springframework.cloud.function.cloudevent.CloudEventHeaderEnricher;
import org.springframework.cloud.function.web.util.HeaderUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
Expand All @@ -29,42 +28,37 @@ public static void main(String[] args) {
}

@Bean
public Function<Message<Input>, Output> uppercase(
CloudEventAttributesProvider provider) {
public Function<Message<Input>, Output> uppercase(CloudEventHeaderEnricher enricher) {
return m -> {
HttpHeaders httpHeaders = HeaderUtils.fromMessage(m.getHeaders());

;

LOGGER.log(Level.INFO, "Input CE Id:{0}", httpHeaders.getFirst(
HTTP_ATTR_PREFIX + ID));
ID));
LOGGER.log(Level.INFO, "Input CE Spec Version:{0}",
httpHeaders.getFirst(HTTP_ATTR_PREFIX + SPECVERSION));
httpHeaders.getFirst(SPECVERSION));
LOGGER.log(Level.INFO, "Input CE Source:{0}",
httpHeaders.getFirst(HTTP_ATTR_PREFIX + SOURCE));
httpHeaders.getFirst(SOURCE));
LOGGER.log(Level.INFO, "Input CE Subject:{0}",
httpHeaders.getFirst(HTTP_ATTR_PREFIX + SUBJECT));
httpHeaders.getFirst(SUBJECT));

Input input = m.getPayload();
LOGGER.log(Level.INFO, "Input {0} ", input);
Output output = new Output();
output.input = input.input;
output.operation = httpHeaders.getFirst(HTTP_ATTR_PREFIX + SUBJECT);
output.output =
input.input != null ? input.input.toUpperCase() : "NO DATA";
output.operation = httpHeaders.getFirst(SUBJECT);
output.output = input.input != null ? input.input.toUpperCase() : "NO DATA";
return output;
};
}

@Bean
public CloudEventAttributesProvider attributesProvider() {
return attributes -> {
attributes
.setSpecversion("1.0")
.setId(UUID.randomUUID()
.toString())
.setSource("http://example.com/uppercase")
.setType("com.redhat.faas.springboot.events");
};
public CloudEventHeaderEnricher attributesProvider() {
return attributes -> attributes
.setSpecVersion("1.0")
.setId(UUID.randomUUID()
.toString())
.setSource("http://example.com/uppercase")
.setType("com.redhat.faas.springboot.events");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.HTTP_ATTR_PREFIX;
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.ID;
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.SOURCE;
import static org.springframework.cloud.function.cloudevent.CloudEventMessageUtils.SPECVERSION;
Expand All @@ -27,7 +26,7 @@
@SpringBootTest(classes = SpringCloudEventsApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT)
public class SpringCloudEventsApplicationTests {

@Autowired
private TestRestTemplate rest;

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

HttpHeaders ceHeaders = new HttpHeaders();
ceHeaders.add(HTTP_ATTR_PREFIX + SPECVERSION, "1.0");
ceHeaders.add(HTTP_ATTR_PREFIX + ID, UUID.randomUUID()
ceHeaders.add(SPECVERSION, "1.0");
ceHeaders.add(ID, UUID.randomUUID()
.toString());
ceHeaders.add(HTTP_ATTR_PREFIX + TYPE, "com.redhat.faas.springboot.test");
ceHeaders.add(HTTP_ATTR_PREFIX + SOURCE, "http://localhost:8080/uppercase");
ceHeaders.add(HTTP_ATTR_PREFIX + SUBJECT, "Convert to UpperCase");
ceHeaders.add(TYPE, "com.redhat.faas.springboot.test");
ceHeaders.add(SOURCE, "http://localhost:8080/uppercase");
ceHeaders.add(SUBJECT, "Convert to UpperCase");

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