diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 000000000..0679d88a9
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,14 @@
+# EditorConfig is awesome: http://EditorConfig.org
+
+# top-most EditorConfig file
+root = true
+
+[*]
+indent_style = tab
+indent_size = 4
+end_of_line = lf
+insert_final_newline = true
+
+[*.yml]
+indent_style = space
+indent_size = 2
diff --git a/.mvn/settings.xml b/.mvn/settings.xml
index f8860c9ca..2e2841999 100644
--- a/.mvn/settings.xml
+++ b/.mvn/settings.xml
@@ -1,15 +1,15 @@
-
-
- sonatype-nexus-staging
- ${env.sonatype_username}
- ${env.sonatype_password}
-
-
- repo.spring.io
- ${env.spring_username}
- ${env.spring_password}
-
-
+
+
+ sonatype-nexus-staging
+ ${env.sonatype_username}
+ ${env.sonatype_password}
+
+
+ repo.spring.io
+ ${env.spring_username}
+ ${env.spring_password}
+
+
diff --git a/.springformat b/.springformat
new file mode 100644
index 000000000..e69de29bb
diff --git a/docs/pom.xml b/docs/pom.xml
index 2e9eabf12..f24d88df9 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -1,6 +1,6 @@
-
4.0.0
spring-cloud-function-docs
@@ -66,24 +66,33 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
diff --git a/pipeline.yml b/pipeline.yml
index bd88a461b..fbf8f9e54 100644
--- a/pipeline.yml
+++ b/pipeline.yml
@@ -2,75 +2,75 @@
# fly --target cloud set-pipeline --config pipeline.yml --pipeline spring-cloud-function --load-vars-from credentials.yml
---
jobs:
-- name: build
- plan:
- - get: source
- trigger: true
- - task: maven
- config:
- platform: linux
- image_resource:
- type: docker-image
- source:
- repository: springio/maven-base
- inputs:
- - name: source
- caches:
- - path: source/.m2
- run:
- dir: source
- path: sh
- args:
- - -c
- - |
- rm -rf ~/.m2
- ln -s $(pwd)/.m2 ~/.m2
- ./mvnw deploy -s .mvn/settings.xml -Dgpg.passphrase="${passphrase}"
- params:
- TERM: -dumb
- passphrase: {{passphrase}}
- sonatype_username: {{sonatype-username}}
- sonatype_password: {{sonatype-password}}
- spring_username: {{spring-username}}
- spring_password: {{spring-password}}
- on_failure: *slack-failure
- on_success: *slack-success
+ - name: build
+ plan:
+ - get: source
+ trigger: true
+ - task: maven
+ config:
+ platform: linux
+ image_resource:
+ type: docker-image
+ source:
+ repository: springio/maven-base
+ inputs:
+ - name: source
+ caches:
+ - path: source/.m2
+ run:
+ dir: source
+ path: sh
+ args:
+ - -c
+ - |
+ rm -rf ~/.m2
+ ln -s $(pwd)/.m2 ~/.m2
+ ./mvnw deploy -s .mvn/settings.xml -Dgpg.passphrase="${passphrase}"
+ params:
+ TERM: -dumb
+ passphrase: {{passphrase}}
+ sonatype_username: {{sonatype-username}}
+ sonatype_password: {{sonatype-password}}
+ spring_username: {{spring-username}}
+ spring_password: {{spring-password}}
+ on_failure: *slack-failure
+ on_success: *slack-success
slack-failure: &slack-failure
put: slack
params:
channel: spring-cloud-firehose
attachments:
- - color: danger
- fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME "
- text: "Build has failed"
- title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME"
- title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME
+ - color: danger
+ fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME "
+ text: "Build has failed"
+ title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME"
+ title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME
slack-success: &slack-success
put: slack
params:
channel: spring-cloud-firehose
attachments:
- - color: good
- fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME "
- text: "Build has succeeded"
- title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME"
- title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME
+ - color: good
+ fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME "
+ text: "Build has succeeded"
+ title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME"
+ title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME
resources:
-- name: source
- type: git
- source:
- uri: https://github.com/spring-cloud/spring-cloud-function.git
-- name: slack
- type: slack-notification
- source:
- url: {{slack-url}}
-
-resource_types:
-- name: slack-notification
- type: docker-image
- source:
- repository: nebhale/slack-notification-resource
+ - name: source
+ type: git
+ source:
+ uri: https://github.com/spring-cloud/spring-cloud-function.git
+ - name: slack
+ type: slack-notification
+ source:
+ url: {{slack-url}}
+
+resource_types:
+ - name: slack-notification
+ type: docker-image
+ source:
+ repository: nebhale/slack-notification-resource
diff --git a/pom.xml b/pom.xml
index e2448c746..89b6e2466 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,7 @@
-
+
4.0.0
spring-cloud-function-parent
@@ -13,7 +13,7 @@
org.springframework.cloud
spring-cloud-build
2.1.3.BUILD-SNAPSHOT
-
+
@@ -23,6 +23,9 @@
2.1.0.RELEASE
1.0.15.RELEASE
spring-cloud-function
+ true
+ true
+
@@ -91,6 +94,14 @@
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+
+ io.spring.javaformat
+ spring-javaformat-maven-plugin
+
@@ -99,7 +110,8 @@
false
true
- com.example,functions,example
+ com.example,functions,example
+
@@ -216,6 +228,15 @@
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+
+
+
java11+
diff --git a/spring-cloud-function-adapters/pom.xml b/spring-cloud-function-adapters/pom.xml
index 675972186..0e5ac8788 100644
--- a/spring-cloud-function-adapters/pom.xml
+++ b/spring-cloud-function-adapters/pom.xml
@@ -1,6 +1,7 @@
-
+
4.0.0
spring-cloud-function-adapter-parent
@@ -18,6 +19,6 @@
spring-cloud-function-adapter-aws
spring-cloud-function-adapter-openwhisk
spring-cloud-function-adapter-azure
-
+
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/pom.xml
index f77e48414..d6758afb6 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/pom.xml
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/pom.xml
@@ -1,6 +1,7 @@
-
+
4.0.0
spring-cloud-function-adapter-aws
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootApiGatewayRequestHandler.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootApiGatewayRequestHandler.java
index 78eba99ac..06b3fc96f 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootApiGatewayRequestHandler.java
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootApiGatewayRequestHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,6 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.GenericMessage;
/**
- *
* @author Dave Syer
* @author Oleg Zhurakousky
*
@@ -66,12 +65,12 @@ public class SpringBootApiGatewayRequestHandler extends
}
private boolean functionAcceptsMessage() {
- return inspector.isMessage(function());
+ return this.inspector.isMessage(function());
}
private Object deserializeBody(String json) {
try {
- return mapper.readValue(json, getInputType());
+ return this.mapper.readValue(json, getInputType());
}
catch (Exception e) {
throw new IllegalStateException("Cannot convert event", e);
@@ -91,13 +90,15 @@ public class SpringBootApiGatewayRequestHandler extends
protected APIGatewayProxyResponseEvent convertOutput(Object output) {
if (functionReturnsMessage(output)) {
Message> message = (Message>) output;
- return new APIGatewayProxyResponseEvent().withStatusCode(
- (Integer) message.getHeaders().getOrDefault("statuscode", HttpStatus.OK.value()))
+ return new APIGatewayProxyResponseEvent()
+ .withStatusCode((Integer) message.getHeaders()
+ .getOrDefault("statuscode", HttpStatus.OK.value()))
.withHeaders(toResponseHeaders(message.getHeaders()))
.withBody(serializeBody(message.getPayload()));
}
else {
- return new APIGatewayProxyResponseEvent().withStatusCode(HttpStatus.OK.value())
+ return new APIGatewayProxyResponseEvent()
+ .withStatusCode(HttpStatus.OK.value())
.withBody(serializeBody(output));
}
@@ -116,7 +117,7 @@ public class SpringBootApiGatewayRequestHandler extends
private String serializeBody(Object body) {
try {
- return mapper.writeValueAsString(body);
+ return this.mapper.writeValueAsString(body);
}
catch (JsonProcessingException e) {
throw new IllegalStateException("Cannot convert output", e);
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootKinesisEventHandler.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootKinesisEventHandler.java
index c6771c266..38e04b6fa 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootKinesisEventHandler.java
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootKinesisEventHandler.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2017 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.cloud.function.adapter.aws;
-import static java.util.stream.Collectors.toList;
-
import java.util.List;
import java.util.stream.Collectors;
@@ -32,7 +30,11 @@ import org.springframework.cloud.function.context.catalog.FunctionInspector;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.GenericMessage;
+import static java.util.stream.Collectors.toList;
+
/**
+ * @param payload type
+ * @param response type
* @author Mark Fisher
* @author Halvdan Hoem Grelland
*/
@@ -65,28 +67,26 @@ public class SpringBootKinesisEventHandler
if (functionAcceptsMessage()) {
return wrapInMessages(payloads);
- } else {
+ }
+ else {
return payloads;
}
}
private List> wrapInMessages(List payloads) {
- return payloads.stream()
- .map(GenericMessage::new)
- .collect(Collectors.toList());
+ return payloads.stream().map(GenericMessage::new).collect(Collectors.toList());
}
private List deserializePayloads(List records) {
return RecordDeaggregator.deaggregate(records).stream()
- .map(this::deserializeUserRecord)
- .collect(toList());
+ .map(this::deserializeUserRecord).collect(toList());
}
@SuppressWarnings("unchecked")
private E deserializeUserRecord(UserRecord userRecord) {
try {
byte[] jsonBytes = userRecord.getData().array();
- return (E) mapper.readValue(jsonBytes, getInputType());
+ return (E) this.mapper.readValue(jsonBytes, getInputType());
}
catch (Exception e) {
throw new IllegalStateException("Cannot convert event", e);
@@ -94,6 +94,7 @@ public class SpringBootKinesisEventHandler
}
private boolean functionAcceptsMessage() {
- return inspector.isMessage(function());
+ return this.inspector.isMessage(function());
}
+
}
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootRequestHandler.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootRequestHandler.java
index 1610ace3d..3f795447e 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootRequestHandler.java
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootRequestHandler.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2017 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,12 +22,12 @@ import java.util.List;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
-
import org.reactivestreams.Publisher;
-
import reactor.core.publisher.Flux;
/**
+ * @param event type
+ * @param result types
* @author Mark Fisher
*/
public class SpringBootRequestHandler extends SpringFunctionInitializer
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootStreamHandler.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootStreamHandler.java
index 3230e1e7f..a04cb7a98 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootStreamHandler.java
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringBootStreamHandler.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2017-1018 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,12 +26,11 @@ import java.util.List;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import org.reactivestreams.Publisher;
-import org.springframework.beans.factory.annotation.Autowired;
-
import reactor.core.publisher.Flux;
+import org.springframework.beans.factory.annotation.Autowired;
+
/**
* @author Dave Syer
* @author Oleg Zhurakousky
@@ -39,7 +38,7 @@ import reactor.core.publisher.Flux;
public class SpringBootStreamHandler extends SpringFunctionInitializer
implements RequestStreamHandler {
- @Autowired(required=false)
+ @Autowired(required = false)
private ObjectMapper mapper;
public SpringBootStreamHandler() {
@@ -64,7 +63,7 @@ public class SpringBootStreamHandler extends SpringFunctionInitializer
initialize();
Object value = convertStream(input);
Publisher> flux = apply(extract(value));
- mapper.writeValue(output, result(value, flux));
+ this.mapper.writeValue(output, result(value, flux));
}
private Object result(Object input, Publisher> flux) {
@@ -72,7 +71,7 @@ public class SpringBootStreamHandler extends SpringFunctionInitializer
for (Object value : Flux.from(flux).toIterable()) {
result.add(value);
}
- if (isSingleValue(input) && result.size()==1) {
+ if (isSingleValue(input) && result.size() == 1) {
return result.get(0);
}
return result;
@@ -91,10 +90,11 @@ public class SpringBootStreamHandler extends SpringFunctionInitializer
private Object convertStream(InputStream input) {
try {
- return mapper.readValue(input, getInputType());
+ return this.mapper.readValue(input, getInputType());
}
catch (Exception e) {
throw new IllegalStateException("Cannot convert event", e);
}
}
+
}
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringFunctionInitializer.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringFunctionInitializer.java
index 0ddbd7521..8d86e0877 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringFunctionInitializer.java
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/SpringFunctionInitializer.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2017 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -29,6 +29,7 @@ import java.util.jar.Manifest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.reactivestreams.Publisher;
+import reactor.core.publisher.Flux;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
@@ -38,8 +39,6 @@ import org.springframework.cloud.function.context.catalog.FunctionInspector;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.ClassUtils;
-import reactor.core.publisher.Flux;
-
/**
* @author Dave Syer
*/
@@ -69,71 +68,6 @@ public class SpringFunctionInitializer implements Closeable {
this(getStartClass());
}
- @Override
- public void close() {
- if (this.context != null) {
- this.context.close();
- }
- }
-
- @SuppressWarnings("unchecked")
- protected void initialize() {
- if (!this.initialized.compareAndSet(false, true)) {
- return;
- }
- logger.info("Initializing: " + configurationClass);
- SpringApplication builder = springApplication();
- ConfigurableApplicationContext context = builder.run();
- context.getAutowireCapableBeanFactory().autowireBean(this);
- String name = context.getEnvironment().getProperty("function.name");
- if (name == null) {
- name = "function";
- }
- if (this.catalog == null) {
- if (context.containsBean(name)) {
- this.function = context.getBean(name, Function.class);
- }
- }
- else {
- Set functionNames = this.catalog.getNames(Function.class);
- if (functionNames.size() == 1) {
- this.function = this.catalog.lookup(Function.class,
- functionNames.iterator().next());
- }
- else {
- this.function = this.catalog.lookup(Function.class, name);
- }
- }
- this.context = context;
-
- }
-
- private SpringApplication springApplication() {
- Class> sourceClass = configurationClass;
- SpringApplication application = new org.springframework.cloud.function.context.FunctionalSpringApplication(
- sourceClass);
- application.setWebApplicationType(WebApplicationType.NONE);
- return application;
- }
-
- protected Class> getInputType() {
- if (inspector != null) {
- return inspector.getInputType(function());
- }
- return Object.class;
- }
-
- protected Object function() {
- return this.function;
- }
-
- protected Publisher> apply(Publisher> input) {
- if (this.function != null) {
- return Flux.from(function.apply(input));
- }
- throw new IllegalStateException("No function defined");
- }
-
private static Class> getStartClass() {
ClassLoader classLoader = SpringFunctionInitializer.class.getClassLoader();
if (System.getenv("MAIN_CLASS") != null) {
@@ -180,4 +114,69 @@ public class SpringFunctionInitializer implements Closeable {
return null;
}
+ @Override
+ public void close() {
+ if (this.context != null) {
+ this.context.close();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void initialize() {
+ if (!this.initialized.compareAndSet(false, true)) {
+ return;
+ }
+ logger.info("Initializing: " + this.configurationClass);
+ SpringApplication builder = springApplication();
+ ConfigurableApplicationContext context = builder.run();
+ context.getAutowireCapableBeanFactory().autowireBean(this);
+ String name = context.getEnvironment().getProperty("function.name");
+ if (name == null) {
+ name = "function";
+ }
+ if (this.catalog == null) {
+ if (context.containsBean(name)) {
+ this.function = context.getBean(name, Function.class);
+ }
+ }
+ else {
+ Set functionNames = this.catalog.getNames(Function.class);
+ if (functionNames.size() == 1) {
+ this.function = this.catalog.lookup(Function.class,
+ functionNames.iterator().next());
+ }
+ else {
+ this.function = this.catalog.lookup(Function.class, name);
+ }
+ }
+ this.context = context;
+
+ }
+
+ private SpringApplication springApplication() {
+ Class> sourceClass = this.configurationClass;
+ SpringApplication application = new org.springframework.cloud.function.context.FunctionalSpringApplication(
+ sourceClass);
+ application.setWebApplicationType(WebApplicationType.NONE);
+ return application;
+ }
+
+ protected Class> getInputType() {
+ if (this.inspector != null) {
+ return this.inspector.getInputType(function());
+ }
+ return Object.class;
+ }
+
+ protected Object function() {
+ return this.function;
+ }
+
+ protected Publisher> apply(Publisher> input) {
+ if (this.function != null) {
+ return Flux.from(this.function.apply(input));
+ }
+ throw new IllegalStateException("No function defined");
+ }
+
}
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/SpringBootApiGatewayRequestHandlerTests.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/SpringBootApiGatewayRequestHandlerTests.java
index d89b9a79e..1841a9c90 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/SpringBootApiGatewayRequestHandlerTests.java
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/SpringBootApiGatewayRequestHandlerTests.java
@@ -1,8 +1,13 @@
package org.springframework.cloud.function.adapter.aws;
+import java.util.Collections;
+import java.util.Map;
+import java.util.function.Function;
+
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import org.junit.Test;
+
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
import org.springframework.context.annotation.Bean;
@@ -11,10 +16,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.GenericMessage;
-import java.util.Collections;
-import java.util.Map;
-import java.util.function.Function;
-
import static org.assertj.core.api.Assertions.assertThat;
public class SpringBootApiGatewayRequestHandlerTests {
@@ -23,71 +24,83 @@ public class SpringBootApiGatewayRequestHandlerTests {
@Test
public void functionBean() {
- handler = new SpringBootApiGatewayRequestHandler(FunctionConfig.class);
- handler.initialize();
+ this.handler = new SpringBootApiGatewayRequestHandler(FunctionConfig.class);
+ this.handler.initialize();
APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent();
request.setBody("{\"value\":\"foo\"}");
- Object output = handler.handleRequest(request, null);
+ Object output = this.handler.handleRequest(request, null);
assertThat(output).isInstanceOf(APIGatewayProxyResponseEvent.class);
- assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode()).isEqualTo(200);
- assertThat(((APIGatewayProxyResponseEvent) output).getBody()).isEqualTo("{\"value\":\"FOO\"}");
- }
-
- @Configuration
- @Import({ContextFunctionCatalogAutoConfiguration.class,
- JacksonAutoConfiguration.class})
- protected static class FunctionConfig {
- @Bean
- public Function function() {
- return foo -> new Bar(foo.getValue().toUpperCase());
- }
+ assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode())
+ .isEqualTo(200);
+ assertThat(((APIGatewayProxyResponseEvent) output).getBody())
+ .isEqualTo("{\"value\":\"FOO\"}");
}
@Test
public void functionMessageBean() {
- handler = new SpringBootApiGatewayRequestHandler(FunctionMessageConfig.class);
- handler.initialize();
+ this.handler = new SpringBootApiGatewayRequestHandler(
+ FunctionMessageConfig.class);
+ this.handler.initialize();
APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent();
request.setBody("{\"value\":\"foo\"}");
- Object output = handler.handleRequest(request, null);
+ Object output = this.handler.handleRequest(request, null);
assertThat(output).isInstanceOf(APIGatewayProxyResponseEvent.class);
- assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode()).isEqualTo(200);
- assertThat(((APIGatewayProxyResponseEvent) output).getHeaders().get("spring")).isEqualTo("cloud");
- assertThat(((APIGatewayProxyResponseEvent) output).getBody()).isEqualTo("{\"value\":\"FOO\"}");
+ assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode())
+ .isEqualTo(200);
+ assertThat(((APIGatewayProxyResponseEvent) output).getHeaders().get("spring"))
+ .isEqualTo("cloud");
+ assertThat(((APIGatewayProxyResponseEvent) output).getBody())
+ .isEqualTo("{\"value\":\"FOO\"}");
}
@Configuration
- @Import({ContextFunctionCatalogAutoConfiguration.class,
- JacksonAutoConfiguration.class})
+ @Import({ ContextFunctionCatalogAutoConfiguration.class,
+ JacksonAutoConfiguration.class })
+ protected static class FunctionConfig {
+
+ @Bean
+ public Function function() {
+ return foo -> new Bar(foo.getValue().toUpperCase());
+ }
+
+ }
+
+ @Configuration
+ @Import({ ContextFunctionCatalogAutoConfiguration.class,
+ JacksonAutoConfiguration.class })
protected static class FunctionMessageConfig {
+
@Bean
public Function, Message> function() {
return (foo -> {
Map headers = Collections.singletonMap("spring", "cloud");
return new GenericMessage<>(
- new Bar(foo.getPayload().getValue().toUpperCase()),
- headers);
+ new Bar(foo.getPayload().getValue().toUpperCase()), headers);
});
}
+
}
protected static class Foo {
+
private String value;
public String getValue() {
- return value;
+ return this.value;
}
public void setValue(String value) {
this.value = value;
}
+
}
protected static class Bar {
+
private String value;
public Bar() {
@@ -98,11 +111,13 @@ public class SpringBootApiGatewayRequestHandlerTests {
}
public String getValue() {
- return value;
+ return this.value;
}
public void setValue(String value) {
this.value = value;
}
+
}
+
}
diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/SpringBootKinesisEventHandlerTests.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/SpringBootKinesisEventHandlerTests.java
index 15f8e38f1..9824f5eb7 100644
--- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/SpringBootKinesisEventHandlerTests.java
+++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/SpringBootKinesisEventHandlerTests.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2017 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,11 +16,6 @@
package org.springframework.cloud.function.adapter.aws;
-import static java.util.Arrays.asList;
-import static java.util.Collections.singletonList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -41,6 +36,11 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.messaging.Message;
+import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
/**
* @author Halvdan Hoem Grelland
*/
@@ -50,122 +50,6 @@ public class SpringBootKinesisEventHandlerTests {
private SpringBootKinesisEventHandler handler;
- @Test
- public void functionBeanHandlesKinesisEvent() throws Exception {
- handler = new SpringBootKinesisEventHandler<>(FunctionConfig.class);
- handler.initialize();
-
- KinesisEvent event = asKinesisEvent(singletonList(new Foo("foo")));
-
- List output = handler.handleRequest(event, null);
-
- assertThat(output).containsExactly(new Bar("FOO"));
- }
-
- @Test
- public void functionBeanHandlesAggregatedKinesisEvent() throws Exception {
- handler = new SpringBootKinesisEventHandler<>(FunctionConfig.class);
- handler.initialize();
-
- List events = asList(new Foo("foo"), new Foo("bar"), new Foo("baz"));
- KinesisEvent aggregatedEvent = asAggregatedKinesisEvent(events);
-
- List output = handler.handleRequest(aggregatedEvent, null);
-
- assertThat(output)
- .containsExactly(new Bar("FOO"), new Bar("BAR"), new Bar("BAZ"));
- }
-
- @Test
- public void functionMessageBean() throws Exception {
- handler = new SpringBootKinesisEventHandler<>(FunctionMessageConfig.class);
- handler.initialize();
-
- KinesisEvent event = asKinesisEvent(asList(new Foo("foo"), new Foo("bar")));
-
- List output = handler.handleRequest(event, null);
-
- assertThat(output)
- .containsExactly(new Bar("FOO"), new Bar("BAR"));
- }
-
- @Configuration
- @Import({
- ContextFunctionCatalogAutoConfiguration.class,
- JacksonAutoConfiguration.class
- })
- protected static class FunctionConfig {
- @Bean
- public Function function() {
- return foo -> new Bar(foo.getValue().toUpperCase());
- }
- }
-
- @Configuration
- @Import({
- ContextFunctionCatalogAutoConfiguration.class,
- JacksonAutoConfiguration.class
- })
- protected static class FunctionMessageConfig {
- @Bean
- public Function, Bar> function() {
- return foo -> new Bar(foo.getPayload().getValue().toUpperCase());
- }
- }
-
- protected static class Foo {
-
- private String value;
-
- public Foo() {
- }
-
- public Foo(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
- }
-
- protected static class Bar {
-
- private String value;
-
- public Bar() {
- }
-
- public Bar(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Bar bar = (Bar) o;
- return Objects.equals(value, bar.value);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(value);
- }
- }
-
private static KinesisEvent asKinesisEvent(List