From b0bddd316067c1e0566b9272a90242fab7c236c0 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 24 Jan 2018 14:24:13 +0000 Subject: [PATCH] Handler for azure sample calls super in different method If FooHandler extends AzureSpringBootRequestHandler apparently Azure cannot extract the generic types Foo and Bar. --- .../README.adoc | 12 ++- .../azure/AzureSpringBootRequestHandler.java | 12 ++- spring-cloud-function-dependencies/pom.xml | 7 +- .../function-sample-azure/npm | 4 - .../function-sample-azure/pom.xml | 81 ++++++++++--------- .../src/assembly/azure.xml | 20 +++++ .../src/main/azure/host.json | 1 + .../src/main/azure/uppercase/function.json | 34 ++++---- .../src/main/java/example/Config.java | 12 +-- .../src/main/java/example/FooHandler.java | 10 +-- 10 files changed, 111 insertions(+), 82 deletions(-) delete mode 100755 spring-cloud-function-samples/function-sample-azure/npm create mode 100644 spring-cloud-function-samples/function-sample-azure/src/assembly/azure.xml diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/README.adoc b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/README.adoc index 1b6e582c4..a62d0a838 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/README.adoc +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/README.adoc @@ -21,10 +21,10 @@ The Azure tooling needs to find some JSON configuration files to tell it how to ``` { "scriptFile" : "../function-sample-azure-1.0.0.BUILD-SNAPSHOT-azure.jar", - "entryPoint" : "example.FooHandler.handleRequest", + "entryPoint" : "example.FooHandler.execute", "bindings" : [ { "type" : "httpTrigger", - "name" : "req", + "name" : "foo", "direction" : "in", "authLevel" : "anonymous", "methods" : [ "get", "post" ] @@ -59,13 +59,11 @@ You will need the `az` CLI app and some node.js fu (see https://docs.microsoft.c ---- $ az login $ mvn azure-functions:deploy - -On another terminal try this: curl https:///api/uppercase -d '{"value": "hello foobar!"}' - -Please ensure that you use the right URL for the function above. ---- -The input type for the function in the Azure sample is a Foo with a single property called "value". So you would need this to test it with something as below. +On another terminal try this: `curl https:///api/uppercase -d '{"value": "hello foobar!"}'`. Please ensure that you use the right URL for the function above. Alternatively you can test the function in the Azure Dashboard UI (click on the function name, go to the right hand side and click "Test" and to the bottom right, "Run"). + +The input type for the function in the Azure sample is a Foo with a single property called "value". So you need this to test it with something like below: ---- { diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/main/java/org/springframework/cloud/function/adapter/azure/AzureSpringBootRequestHandler.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/main/java/org/springframework/cloud/function/adapter/azure/AzureSpringBootRequestHandler.java index 47d70938d..56a94cea4 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/main/java/org/springframework/cloud/function/adapter/azure/AzureSpringBootRequestHandler.java +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/main/java/org/springframework/cloud/function/adapter/azure/AzureSpringBootRequestHandler.java @@ -29,7 +29,7 @@ import reactor.core.publisher.Flux; */ public class AzureSpringBootRequestHandler extends AzureSpringFunctionInitializer { - public Object handleRequest(I foo, ExecutionContext context) { + public O handleRequest(I foo, ExecutionContext context) { context.getLogger().info("Handler Java HTTP trigger processed a request."); initialize(context); @@ -49,15 +49,19 @@ public class AzureSpringBootRequestHandler extends AzureSpringFunctionInit return Flux.just(input); } - private Object result(Object input, Flux output) { + private O result(Object input, Flux output) { List result = new ArrayList<>(); for (Object value : output.toIterable()) { result.add(convertOutput(value)); } if (isSingleValue(input) && result.size() == 1) { - return result.get(0); + @SuppressWarnings("unchecked") + O value = (O) result.get(0); + return value; } - return result; + @SuppressWarnings("unchecked") + O value = (O) result; + return value; } private boolean isSingleValue(Object input) { diff --git a/spring-cloud-function-dependencies/pom.xml b/spring-cloud-function-dependencies/pom.xml index ad6010252..18cbf17ae 100644 --- a/spring-cloud-function-dependencies/pom.xml +++ b/spring-cloud-function-dependencies/pom.xml @@ -14,7 +14,7 @@ Spring Cloud Function Dependencies Spring Cloud Function Dependencies - Bismuth-SR1 + Bismuth-SR4 @@ -65,6 +65,11 @@ spring-cloud-function-adapter-aws ${project.version} + + org.springframework.cloud + spring-cloud-function-adapter-azure + ${project.version} + org.springframework.cloud spring-cloud-function-adapter-openwhisk diff --git a/spring-cloud-function-samples/function-sample-azure/npm b/spring-cloud-function-samples/function-sample-azure/npm deleted file mode 100755 index e5e7ed560..000000000 --- a/spring-cloud-function-samples/function-sample-azure/npm +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -cd $(dirname $0) -PATH="$PWD/node/":$PATH -node "node/node_modules/npm/bin/npm-cli.js" "$@" diff --git a/spring-cloud-function-samples/function-sample-azure/pom.xml b/spring-cloud-function-samples/function-sample-azure/pom.xml index 904b6c9f5..13b8f0984 100644 --- a/spring-cloud-function-samples/function-sample-azure/pom.xml +++ b/spring-cloud-function-samples/function-sample-azure/pom.xml @@ -23,30 +23,25 @@ 1.8 function-sample-azure westus - example.FooConfig + 3.1.2.RELEASE + example.Config - com.microsoft.azure - azure-functions-java-core - 1.0.0-beta-2 + org.springframework.cloud + spring-cloud-function-adapter-azure org.springframework.cloud spring-cloud-function-web - 1.0.0.BUILD-SNAPSHOT provided - org.springframework.cloud - spring-cloud-function-adapter-azure - 1.0.0.BUILD-SNAPSHOT - - - io.projectreactor - reactor-core - 3.1.2.RELEASE + com.microsoft.azure + azure-functions-java-core + 1.0.0-beta-2 + provided @@ -62,6 +57,18 @@ + + + + org.springframework.cloud + spring-cloud-function-dependencies + 1.0.0.BUILD-SNAPSHOT + pom + import + + + + @@ -78,28 +85,6 @@ - - com.github.eirslett - frontend-maven-plugin - 1.6 - - v8.8.1 - - - - install-npm - - install-node-and-npm - - - - npm-install - - npm - - - - com.microsoft.azure azure-functions-maven-plugin @@ -132,9 +117,7 @@ ${project.basedir}/src/main/azure - uppercase/** - host.json - local.settings.json + ** @@ -154,6 +137,28 @@ + + org.apache.maven.plugins + maven-assembly-plugin + + + azure + package + + single + + false + + false + ${basedir}/src/assembly/azure.xml + ${project.build.directory}/azure-functions + false + ${functionAppName} + + + + + diff --git a/spring-cloud-function-samples/function-sample-azure/src/assembly/azure.xml b/spring-cloud-function-samples/function-sample-azure/src/assembly/azure.xml new file mode 100644 index 000000000..85bb6a3a9 --- /dev/null +++ b/spring-cloud-function-samples/function-sample-azure/src/assembly/azure.xml @@ -0,0 +1,20 @@ + + azure + + zip + + + + + ${project.build.directory}/azure-functions/${functionAppName} + + + *-azure.jar + **/*.json + + + + \ No newline at end of file diff --git a/spring-cloud-function-samples/function-sample-azure/src/main/azure/host.json b/spring-cloud-function-samples/function-sample-azure/src/main/azure/host.json index 2c63c0851..4ded8af71 100644 --- a/spring-cloud-function-samples/function-sample-azure/src/main/azure/host.json +++ b/spring-cloud-function-samples/function-sample-azure/src/main/azure/host.json @@ -1,2 +1,3 @@ { + "functionTimeout": "00:10:00" } diff --git a/spring-cloud-function-samples/function-sample-azure/src/main/azure/uppercase/function.json b/spring-cloud-function-samples/function-sample-azure/src/main/azure/uppercase/function.json index bf9a8ab0c..0af9eca0f 100644 --- a/spring-cloud-function-samples/function-sample-azure/src/main/azure/uppercase/function.json +++ b/spring-cloud-function-samples/function-sample-azure/src/main/azure/uppercase/function.json @@ -1,16 +1,22 @@ { - "scriptFile" : "../function-sample-azure-1.0.0.BUILD-SNAPSHOT-azure.jar", - "entryPoint" : "example.FooHandler.handleRequest", - "bindings" : [ { - "type" : "httpTrigger", - "name" : "foo", - "direction" : "in", - "authLevel" : "anonymous", - "methods" : [ "get", "post" ] - }, { - "type" : "http", - "name" : "$return", - "direction" : "out" - } ], - "disabled" : false + "scriptFile": "../function-sample-azure-1.0.0.BUILD-SNAPSHOT-azure.jar", + "entryPoint": "example.FooHandler.execute", + "bindings": [ + { + "type": "httpTrigger", + "name": "foo", + "direction": "in", + "authLevel": "anonymous", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "name": "$return", + "direction": "out" + } + ], + "disabled": false } \ No newline at end of file diff --git a/spring-cloud-function-samples/function-sample-azure/src/main/java/example/Config.java b/spring-cloud-function-samples/function-sample-azure/src/main/java/example/Config.java index beb9f5bb0..7cec312bb 100644 --- a/spring-cloud-function-samples/function-sample-azure/src/main/java/example/Config.java +++ b/spring-cloud-function-samples/function-sample-azure/src/main/java/example/Config.java @@ -23,15 +23,15 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @SpringBootApplication -class FooConfig { +public class Config { + + public static void main(String[] args) throws Exception { + SpringApplication.run(Config.class, args); + } @Bean public Function uppercase() { - return value -> new Bar(value.getValue().toUpperCase()); - } - - public static void main(String[] args) throws Exception { - SpringApplication.run(FooConfig.class, args); + return foo -> new Bar(foo.getValue().toUpperCase()); } } diff --git a/spring-cloud-function-samples/function-sample-azure/src/main/java/example/FooHandler.java b/spring-cloud-function-samples/function-sample-azure/src/main/java/example/FooHandler.java index 0c9bfc06c..f43f8474c 100644 --- a/spring-cloud-function-samples/function-sample-azure/src/main/java/example/FooHandler.java +++ b/spring-cloud-function-samples/function-sample-azure/src/main/java/example/FooHandler.java @@ -17,8 +17,6 @@ package example; import com.microsoft.azure.serverless.functions.ExecutionContext; -import com.microsoft.azure.serverless.functions.annotation.HttpOutput; -import com.microsoft.azure.serverless.functions.annotation.HttpTrigger; import org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHandler; @@ -27,12 +25,8 @@ import org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHa */ public class FooHandler extends AzureSpringBootRequestHandler { - @Override - public @HttpOutput(name = "bar") Bar handleRequest( - @HttpTrigger(name = "foo", methods = { "get", "post" }) Foo foo, - ExecutionContext context) { - context.getLogger().info("Invoking entry point method"); - return (Bar) super.handleRequest(foo, context); + public Bar execute(Foo foo, ExecutionContext context) { + return handleRequest(foo, context); } }