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,javax.servlet.http.HttpServletRequest,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(Class<RequestType> requestTypeClass,
Class<ResponseType> responseTypeClass,
RequestReader<RequestType,javax.servlet.http.HttpServletRequest> 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(javax.servlet.http.HttpServletRequest request,
CountDownLatch latch) |
static SparkLambdaContainerHandler<HttpApiV2ProxyRequest,AwsProxyResponse> |
getHttpApiV2ProxyHandler()
Returns a new instance of an SparkLambdaContainerHandler initialized to work with
HttpApiV2ProxyRequest
and AwsProxyResponse objects. |
javax.servlet.Servlet |
getServlet() |
protected void |
handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest,
AwsHttpServletResponse httpServletResponse,
com.amazonaws.services.lambda.runtime.Context lambdaContext) |
void |
initialize() |
doFilter, getFilterChain, getServletContext, onStartup, setServletContextgetContainerConfig, getInitializationWrapper, getObjectMapper, proxy, proxyStream, setInitializationWrapper, setLogFormatter, stripBasePathpublic SparkLambdaContainerHandler(Class<RequestType> requestTypeClass, Class<ResponseType> responseTypeClass, RequestReader<RequestType,javax.servlet.http.HttpServletRequest> 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 containerpublic static SparkLambdaContainerHandler<HttpApiV2ProxyRequest,AwsProxyResponse> getHttpApiV2ProxyHandler() throws ContainerInitializationException
HttpApiV2ProxyRequest
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(javax.servlet.http.HttpServletRequest request, CountDownLatch latch)
getContainerResponse in class LambdaContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>protected void handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest,
AwsHttpServletResponse httpServletResponse,
com.amazonaws.services.lambda.runtime.Context lambdaContext)
throws Exception
handleRequest in class LambdaContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>Exceptionpublic void initialize()
throws ContainerInitializationException
initialize in class AwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>ContainerInitializationExceptionpublic javax.servlet.Servlet getServlet()
Copyright © 2022. All rights reserved.