diff --git a/scripts/registerFunction.sh b/scripts/registerFunction.sh
index 7fcb02239..34ce2f921 100755
--- a/scripts/registerFunction.sh
+++ b/scripts/registerFunction.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-while getopts ":n:f:" opt; do
+while getopts ":n:f:i:o:" opt; do
case $opt in
n)
NAME=$OPTARG
@@ -8,7 +8,14 @@ while getopts ":n:f:" opt; do
f)
FUNC=$OPTARG
;;
+ i)
+ INTYPE=$OPTARG
+ ;;
+ o)
+ OUTTYPE=$OPTARG
+ ;;
esac
done
-curl -X POST -H "Content-Type: text/plain" -d $FUNC :8080/function/$NAME
+curl -X POST -H "Content-Type: text/plain" -d $FUNC ":8080/function/$NAME?inputType=$INTYPE&outputType=$OUTTYPE"
+
diff --git a/scripts/registerSupplier.sh b/scripts/registerSupplier.sh
index 84291c5b0..107368990 100755
--- a/scripts/registerSupplier.sh
+++ b/scripts/registerSupplier.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-while getopts ":n:f:" opt; do
+while getopts ":n:f:t:" opt; do
case $opt in
n)
NAME=$OPTARG
@@ -8,7 +8,10 @@ while getopts ":n:f:" opt; do
f)
FUNC=$OPTARG
;;
+ t)
+ TYPE=$OPTARG
+ ;;
esac
done
-curl -X POST -H "Content-Type: text/plain" -d $FUNC :8080/supplier/$NAME
+curl -X POST -H "Content-Type: text/plain" -d $FUNC :8080/supplier/$NAME?type=$TYPE
diff --git a/spring-cloud-function-compiler/pom.xml b/spring-cloud-function-compiler/pom.xml
index 9327d62f1..5979bd875 100644
--- a/spring-cloud-function-compiler/pom.xml
+++ b/spring-cloud-function-compiler/pom.xml
@@ -41,6 +41,11 @@
org.springframework
spring-context
+
+ org.springframework.cloud
+ spring-cloud-function-core
+ ${project.version}
+
org.springframework.boot
spring-boot-starter-web
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/AbstractFunctionCompiler.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/AbstractFunctionCompiler.java
index ad563a5fe..5044b5341 100644
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/AbstractFunctionCompiler.java
+++ b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/AbstractFunctionCompiler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2016-2017 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.
@@ -26,6 +26,8 @@ import org.springframework.cloud.function.compiler.java.CompilationFailedExcepti
import org.springframework.cloud.function.compiler.java.CompilationMessage;
import org.springframework.cloud.function.compiler.java.CompilationResult;
import org.springframework.cloud.function.compiler.java.RuntimeJavaCompiler;
+import org.springframework.util.ObjectUtils;
+import org.springframework.util.StringUtils;
/**
* @author Andy Clement
@@ -59,13 +61,13 @@ public abstract class AbstractFunctionCompiler {
private final ResultType resultType;
- private final String parameterizedTypes;
+ private final String[] defaultResultTypeParameterizations;
private final RuntimeJavaCompiler compiler = new RuntimeJavaCompiler();
- AbstractFunctionCompiler(ResultType type, String parameterizedTypes) {
+ AbstractFunctionCompiler(ResultType type, String... defaultResultTypeParameterizations) {
this.resultType = type;
- this.parameterizedTypes = parameterizedTypes;
+ this.defaultResultTypeParameterizations = defaultResultTypeParameterizations;
}
/**
@@ -80,23 +82,25 @@ public abstract class AbstractFunctionCompiler {
*
* @return a factory instance
*/
- public CompiledFunctionFactory compile(String name, String code) {
+ public CompiledFunctionFactory compile(String name, String code, String... resultTypeParameterizations) {
if (name == null || name.length() == 0) {
throw new IllegalArgumentException("name must not be empty");
}
logger.info("Initial code property value :'{}'", code);
+ String parameterizations = StringUtils.arrayToCommaDelimitedString(
+ (!ObjectUtils.isEmpty(resultTypeParameterizations)) ? resultTypeParameterizations : this.defaultResultTypeParameterizations);
code = decode(code);
if (code.startsWith("\"") && code.endsWith("\"")) {
code = code.substring(1,code.length()-1);
}
if (!code.startsWith("return ") && !code.endsWith(";")) {
- code = String.format("return (%s<%s> & java.io.Serializable) %s;", resultType, this.parameterizedTypes, code);
+ code = String.format("return (%s<%s> & java.io.Serializable) %s;", resultType, parameterizations, code);
}
logger.info("Processed code property value :\n{}\n", code);
String firstLetter = name.substring(0, 1).toUpperCase();
name = (name.length() > 1) ? firstLetter + name.substring(1) : firstLetter;
String className = String.format("%s.%s%sFactory", this.getClass().getPackage().getName(), name, resultType);
- CompilationResult compilationResult = buildAndCompileSourceCode(className, code);
+ CompilationResult compilationResult = buildAndCompileSourceCode(className, code, parameterizations);
if (compilationResult.wasSuccessful()) {
return new CompiledFunctionFactory(className, compilationResult);
}
@@ -107,17 +111,18 @@ public abstract class AbstractFunctionCompiler {
/**
* Create the source for and then compile and load a class that embodies
* the supplied methodBody. The methodBody is inserted into a class template that
- * returns a Function<Flux<Object>,Flux<Object>>.
+ * returns the specified parameterized type.
* This method can return more than one class if the method body includes local class
* declarations. An example methodBody would be return input -> input.buffer(5).map(list->list.get(0));.
*
* @param className the name of the class
- * @param methodBody the source code for a method that should return a
- * Function<Flux<Object>,Flux<Object>>
+ * @param methodBody the source code for a method
+ * @param parameterTypeString the String representation for the parameterized return type, e.g.:
+ * <Flux<Object>,Flux<Object>
* @return the list of Classes produced by compiling and then loading the snippet of code
*/
- private CompilationResult buildAndCompileSourceCode(String className, String methodBody) {
- String sourceCode = makeSourceClassDefinition(className, methodBody);
+ private CompilationResult buildAndCompileSourceCode(String className, String methodBody, String parameterTypeString) {
+ String sourceCode = makeSourceClassDefinition(className, methodBody, parameterTypeString);
return compiler.compile(className, sourceCode);
}
@@ -133,9 +138,9 @@ public abstract class AbstractFunctionCompiler {
* @param methodBody the code to insert into the Reactive source class template
* @return a complete Java Class definition
*/
- private String makeSourceClassDefinition(String className, String methodBody) {
+ private String makeSourceClassDefinition(String className, String methodBody, String types) {
String shortClassName = className.substring(className.lastIndexOf('.') + 1);
- String s = String.format(SOURCE_CODE_TEMPLATE, shortClassName, resultType, resultType, this.parameterizedTypes, methodBody);
+ String s = String.format(SOURCE_CODE_TEMPLATE, shortClassName, resultType, resultType, types, methodBody);
System.out.println(s);
return s;
}
diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionCompiler.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionCompiler.java
index a896e90b2..1cc58113a 100644
--- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionCompiler.java
+++ b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/FunctionCompiler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2016-2017 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.
@@ -24,6 +24,14 @@ import java.util.function.Function;
public class FunctionCompiler extends AbstractFunctionCompiler> {
public FunctionCompiler() {
- super(ResultType.Function, "Flux