Handler for azure sample calls super in different method

If FooHandler extends AzureSpringBootRequestHandler apparently
Azure cannot extract the generic types Foo and Bar.
This commit is contained in:
Dave Syer
2018-01-24 14:24:13 +00:00
parent 7604de3ca7
commit b0bddd3160
10 changed files with 111 additions and 82 deletions

View File

@@ -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://<azure-function-url-from-the-log>/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://<azure-function-url-from-the-log>/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:
----
{

View File

@@ -29,7 +29,7 @@ import reactor.core.publisher.Flux;
*/
public class AzureSpringBootRequestHandler<I, O> 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<I, O> extends AzureSpringFunctionInit
return Flux.just(input);
}
private Object result(Object input, Flux<?> output) {
private O result(Object input, Flux<?> output) {
List<Object> 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) {

View File

@@ -14,7 +14,7 @@
<name>Spring Cloud Function Dependencies</name>
<description>Spring Cloud Function Dependencies</description>
<properties>
<reactor-bom.version>Bismuth-SR1</reactor-bom.version>
<reactor-bom.version>Bismuth-SR4</reactor-bom.version>
</properties>
<dependencyManagement>
<dependencies>
@@ -65,6 +65,11 @@
<artifactId>spring-cloud-function-adapter-aws</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-azure</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-openwhisk</artifactId>

View File

@@ -1,4 +0,0 @@
#!/bin/sh
cd $(dirname $0)
PATH="$PWD/node/":$PATH
node "node/node_modules/npm/bin/npm-cli.js" "$@"

View File

@@ -23,30 +23,25 @@
<maven.compiler.target>1.8</maven.compiler.target>
<functionAppName>function-sample-azure</functionAppName>
<functionAppRegion>westus</functionAppRegion>
<start-class>example.FooConfig</start-class>
<reactor.version>3.1.2.RELEASE</reactor.version>
<start-class>example.Config</start-class>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-java-core</artifactId>
<version>1.0.0-beta-2</version>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-azure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-web</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-azure</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.1.2.RELEASE</version>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-java-core</artifactId>
<version>1.0.0-beta-2</version>
<scope>provided</scope>
</dependency>
<!-- Test -->
@@ -62,6 +57,18 @@
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-dependencies</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
@@ -78,28 +85,6 @@
</pluginManagement>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<nodeVersion>v8.8.1</nodeVersion>
</configuration>
<executions>
<execution>
<id>install-npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm-install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
@@ -132,9 +117,7 @@
<resource>
<directory>${project.basedir}/src/main/azure</directory>
<includes>
<include>uppercase/**</include>
<include>host.json</include>
<include>local.settings.json</include>
<include>**</include>
</includes>
</resource>
</resources>
@@ -154,6 +137,28 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>azure</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<inherited>false</inherited>
<configuration>
<attach>false</attach>
<descriptor>${basedir}/src/assembly/azure.xml</descriptor>
<outputDirectory>${project.build.directory}/azure-functions</outputDirectory>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${functionAppName}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@@ -0,0 +1,20 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>azure</id>
<formats>
<format>zip</format>
</formats>
<baseDirectory></baseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/azure-functions/${functionAppName}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*-azure.jar</include>
<include>**/*.json</include>
</includes>
</fileSet>
</fileSets>
</assembly>

View File

@@ -1,2 +1,3 @@
{
"functionTimeout": "00:10:00"
}

View File

@@ -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
}

View File

@@ -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<Foo, Bar> 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());
}
}

View File

@@ -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<Foo, Bar> {
@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);
}
}