RequestType - The request object used by the RequestReader implementation passed to the constructorResponseType - The response object produced by the ResponseWriter implementation in the constructorpublic class SparkLambdaContainerHandler<RequestType,ResponseType> extends AwsLambdaServletContainerHandler<RequestType,ResponseType,AwsProxyHttpServletRequest,AwsHttpServletResponse>
LambdaContainerHandler object that supports the Spark framework: http://sparkjava.com/
Because of the way this container is implemented, using reflection to change accessibility of methods in the Spark framework and inserting itself as the default embedded container, it is important that you initialize the Handler before declaring your spark routes.
This implementation uses the default AwsProxyHttpServletRequest and Response implementations.
// always initialize the handler first
SparkLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler =
SparkLambdaContainerHandler.getAwsProxyHandler();
get("/hello", (req, res) -> {
res.status(200);
res.body("Hello World");
});
AwsLambdaServletContainerHandler.StartupHandlerservletContext, startupHandlerlambdaContext, SERVER_INFO| Constructor and Description |
|---|
SparkLambdaContainerHandler(java.lang.Class<RequestType> requestTypeClass,
java.lang.Class<ResponseType> responseTypeClass,
RequestReader<RequestType,AwsProxyHttpServletRequest> requestReader,
ResponseWriter<AwsHttpServletResponse,ResponseType> responseWriter,
SecurityContextWriter<RequestType> securityContextWriter,
ExceptionHandler<ResponseType> exceptionHandler,
LambdaEmbeddedServerFactory embeddedServerFactory) |
| Modifier and Type | Method and Description |
|---|---|
static SparkLambdaContainerHandler<AwsProxyRequest,AwsProxyResponse> |
getAwsProxyHandler()
Returns a new instance of an SparkLambdaContainerHandler initialized to work with
AwsProxyRequest
and AwsProxyResponse objects. |
protected AwsHttpServletResponse |
getContainerResponse(AwsProxyHttpServletRequest request,
java.util.concurrent.CountDownLatch latch) |
protected void |
handleRequest(AwsProxyHttpServletRequest httpServletRequest,
AwsHttpServletResponse httpServletResponse,
com.amazonaws.services.lambda.runtime.Context lambdaContext) |
void |
initialize() |
doFilter, forward, getFilterChain, getServletContext, include, onStartup, setServletContextgetContainerConfig, getObjectMapper, proxy, proxyStream, setLogFormatter, stripBasePathpublic SparkLambdaContainerHandler(java.lang.Class<RequestType> requestTypeClass, java.lang.Class<ResponseType> responseTypeClass, RequestReader<RequestType,AwsProxyHttpServletRequest> requestReader, ResponseWriter<AwsHttpServletResponse,ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler, LambdaEmbeddedServerFactory embeddedServerFactory) throws ContainerInitializationException
ContainerInitializationExceptionpublic static SparkLambdaContainerHandler<AwsProxyRequest,AwsProxyResponse> getAwsProxyHandler() throws ContainerInitializationException
AwsProxyRequest
and AwsProxyResponse objects.SparkLambdaContainerHandlerContainerInitializationException - Throws this exception if we fail to initialize the Spark container.
This could be caused by the introspection used to insert the library as the default embedded containerprotected AwsHttpServletResponse getContainerResponse(AwsProxyHttpServletRequest request, java.util.concurrent.CountDownLatch latch)
getContainerResponse in class LambdaContainerHandler<RequestType,ResponseType,AwsProxyHttpServletRequest,AwsHttpServletResponse>protected void handleRequest(AwsProxyHttpServletRequest httpServletRequest, AwsHttpServletResponse httpServletResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext) throws java.lang.Exception
handleRequest in class LambdaContainerHandler<RequestType,ResponseType,AwsProxyHttpServletRequest,AwsHttpServletResponse>java.lang.Exceptionpublic void initialize()
throws ContainerInitializationException
initialize in class LambdaContainerHandler<RequestType,ResponseType,AwsProxyHttpServletRequest,AwsHttpServletResponse>ContainerInitializationExceptionCopyright © 2018. All Rights Reserved.