Add ability to extract routing function name using http message headers in aws CustomRuntimeEventLoop
This commit is contained in:
committed by
Oleg Zhurakousky
parent
c5f176b978
commit
d8e20e57af
@@ -130,7 +130,7 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
FunctionInvocationWrapper function = locateFunction(environment, functionCatalog, response.getHeaders().getContentType());
|
FunctionInvocationWrapper function = locateFunction(environment, functionCatalog, response.getHeaders());
|
||||||
Message<byte[]> eventMessage = AWSLambdaUtils.generateMessage(response.getBody().getBytes(StandardCharsets.UTF_8),
|
Message<byte[]> eventMessage = AWSLambdaUtils.generateMessage(response.getBody().getBytes(StandardCharsets.UTF_8),
|
||||||
fromHttp(response.getHeaders()), function.getInputType(), mapper);
|
fromHttp(response.getHeaders()), function.getInputType(), mapper);
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
@@ -172,7 +172,8 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FunctionInvocationWrapper locateFunction(Environment environment, FunctionCatalog functionCatalog, MediaType contentType) {
|
private FunctionInvocationWrapper locateFunction(Environment environment, FunctionCatalog functionCatalog, HttpHeaders httpHeaders) {
|
||||||
|
MediaType contentType = httpHeaders.getContentType();
|
||||||
String handlerName = environment.getProperty("DEFAULT_HANDLER");
|
String handlerName = environment.getProperty("DEFAULT_HANDLER");
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Value of DEFAULT_HANDLER env: " + handlerName);
|
logger.debug("Value of DEFAULT_HANDLER env: " + handlerName);
|
||||||
@@ -201,6 +202,15 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle {
|
|||||||
function = functionCatalog.lookup(handlerName, contentType.toString());
|
function = functionCatalog.lookup(handlerName, contentType.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (function == null) {
|
||||||
|
logger.info("Could not determine DEFAULT_HANDLER, _HANDLER or 'spring.cloud.function.definition'");
|
||||||
|
handlerName = httpHeaders.get("spring.cloud.function.definition");
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Value of 'spring.cloud.function.definition' header: " + handlerName);
|
||||||
|
}
|
||||||
|
function = functionCatalog.lookup(handlerName, contentType.toString());
|
||||||
|
}
|
||||||
|
|
||||||
Assert.notNull(function, "Failed to locate function. Tried locating default function, "
|
Assert.notNull(function, "Failed to locate function. Tried locating default function, "
|
||||||
+ "function by 'DEFAULT_HANDLER', '_HANDLER' env variable as well as'spring.cloud.function.definition'. "
|
+ "function by 'DEFAULT_HANDLER', '_HANDLER' env variable as well as'spring.cloud.function.definition'. "
|
||||||
+ "Functions available in catalog are: " + functionCatalog.getNames(null));
|
+ "Functions available in catalog are: " + functionCatalog.getNames(null));
|
||||||
|
|||||||
Reference in New Issue
Block a user