Allow Azure function apps to pass function name down to handler
This commit is contained in:
@@ -42,14 +42,16 @@ public class AzureSpringBootRequestHandler<I, O> extends AzureSpringFunctionInit
|
|||||||
}
|
}
|
||||||
|
|
||||||
public O handleRequest(I input, ExecutionContext context) {
|
public O handleRequest(I input, ExecutionContext context) {
|
||||||
|
String name = null;
|
||||||
try {
|
try {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
context.getLogger().fine("Handler processed a request.");
|
context.getLogger().fine("Handler processed a request.");
|
||||||
|
name = context.getFunctionName();
|
||||||
}
|
}
|
||||||
initialize(context);
|
initialize(context);
|
||||||
|
|
||||||
Object convertedEvent = convertEvent(input);
|
Object convertedEvent = convertEvent(input);
|
||||||
Publisher<?> output = apply(extract(convertedEvent));
|
Publisher<?> output = apply(name, extract(convertedEvent));
|
||||||
return result(convertedEvent, output);
|
return result(convertedEvent, output);
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
@@ -73,32 +75,8 @@ public class AzureSpringBootRequestHandler<I, O> extends AzureSpringFunctionInit
|
|||||||
|
|
||||||
public void handleOutput(I input, OutputBinding<O> binding,
|
public void handleOutput(I input, OutputBinding<O> binding,
|
||||||
ExecutionContext context) {
|
ExecutionContext context) {
|
||||||
try {
|
O result = handleRequest(input, context);
|
||||||
if (context != null) {
|
binding.setValue(result);
|
||||||
context.getLogger().fine("Handler processing a request.");
|
|
||||||
}
|
|
||||||
initialize(context);
|
|
||||||
|
|
||||||
Object convertedEvent = convertEvent(input);
|
|
||||||
Publisher<?> output = apply(extract(convertedEvent));
|
|
||||||
binding.setValue(result(convertedEvent, output));
|
|
||||||
|
|
||||||
if (context != null) {
|
|
||||||
context.getLogger().fine("Handler processed a request.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Throwable ex) {
|
|
||||||
if (context != null) {
|
|
||||||
context.getLogger().throwing(getClass().getName(), "handle", ex);
|
|
||||||
}
|
|
||||||
if (ex instanceof RuntimeException) {
|
|
||||||
throw (RuntimeException) ex;
|
|
||||||
}
|
|
||||||
if (ex instanceof Error) {
|
|
||||||
throw (Error) ex;
|
|
||||||
}
|
|
||||||
throw new UndeclaredThrowableException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object convertEvent(I input) {
|
protected Object convertEvent(I input) {
|
||||||
|
|||||||
@@ -119,8 +119,12 @@ public class AzureSpringFunctionInitializer implements Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Publisher<?> apply(Publisher<?> input) {
|
protected Publisher<?> apply(String name, Publisher<?> input) {
|
||||||
if (this.function != null) {
|
Function<Publisher<?>, Publisher<?>> function = this.function;
|
||||||
|
if (function == null && name != null) {
|
||||||
|
function = this.catalog.lookup(Function.class, name);
|
||||||
|
}
|
||||||
|
if (function != null) {
|
||||||
return function.apply(input);
|
return function.apply(input);
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("No function defined");
|
throw new IllegalStateException("No function defined");
|
||||||
|
|||||||
Reference in New Issue
Block a user