GH-249, Add full HTTP support to SpringBootApiGatewayRequestHandler
* Add support for handling APIGatewayProxyRequestEvent objects with empty body (should apply to all GET and DELETE requests, which comply with recommandation of RFC-7231) * Add support ReSTful APIs: path and query string parameters as well as the HTTP method are now extracted from the APIGatewayProxyRequestEvent object and forwarded to the function as message headers * Extend unit tests accordingly
This commit is contained in:
committed by
Oleg Zhurakousky
parent
570bbb23b5
commit
01e813ec52
@@ -18,6 +18,7 @@ package org.springframework.cloud.function.adapter.aws;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||
@@ -36,6 +37,7 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
* @author Dave Syer
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Semyon Fishman
|
||||
* @author Markus Gulden
|
||||
*/
|
||||
public class SpringBootApiGatewayRequestHandler extends
|
||||
SpringBootRequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
||||
@@ -56,12 +58,22 @@ public class SpringBootApiGatewayRequestHandler extends
|
||||
|
||||
@Override
|
||||
protected Object convertEvent(APIGatewayProxyRequestEvent event) {
|
||||
Object body = deserializeBody(event.getBody());
|
||||
if (functionAcceptsMessage()) {
|
||||
return new GenericMessage<>(body, getHeaders(event));
|
||||
|
||||
if (event.getBody() != null) {
|
||||
if (functionAcceptsMessage()) {
|
||||
return new GenericMessage<>(deserializeBody(event.getBody()), getHeaders(event));
|
||||
}
|
||||
else {
|
||||
return deserializeBody(event.getBody());
|
||||
}
|
||||
}
|
||||
else {
|
||||
return body;
|
||||
if (functionAcceptsMessage()) {
|
||||
return new GenericMessage<Optional<Void>>(Optional.empty(), getHeaders(event));
|
||||
}
|
||||
else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +95,13 @@ public class SpringBootApiGatewayRequestHandler extends
|
||||
if (event.getHeaders() != null) {
|
||||
headers.putAll(event.getHeaders());
|
||||
}
|
||||
if (event.getQueryStringParameters() != null) {
|
||||
headers.putAll(event.getQueryStringParameters());
|
||||
}
|
||||
if (event.getPathParameters() != null) {
|
||||
headers.putAll(event.getPathParameters());
|
||||
}
|
||||
headers.put("httpMethod", event.getHttpMethod());
|
||||
headers.put("request", event);
|
||||
return new MessageHeaders(headers);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user