mirror of https://github.com/knative/func.git
fix: sprint-boot template
Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
parent
6d2d8c63b0
commit
38fd673fdb
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
|
@ -12,7 +11,7 @@ import java.util.logging.Level;
|
|||
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;
|
||||
|
@ -29,42 +28,37 @@ public class SpringCloudEventsApplication {
|
|||
}
|
||||
|
||||
@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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
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;
|
||||
|
@ -27,7 +26,7 @@ import org.springframework.http.ResponseEntity;
|
|||
@SpringBootTest(classes = SpringCloudEventsApplication.class,
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class SpringCloudEventsApplicationTests {
|
||||
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
|
@ -42,12 +41,12 @@ public class SpringCloudEventsApplicationTests {
|
|||
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"))
|
||||
|
|
Loading…
Reference in New Issue