Class SparkLambdaContainerHandler<RequestType,ResponseType>
java.lang.Object
com.amazonaws.serverless.proxy.internal.LambdaContainerHandler<RequestType,ResponseType,ContainerRequestType,ContainerResponseType>
com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
com.amazonaws.serverless.proxy.spark.SparkLambdaContainerHandler<RequestType,ResponseType>
- Type Parameters:
RequestType- The request object used by theRequestReaderimplementation passed to the constructorResponseType- The response object produced by theResponseWriterimplementation in the constructor
public class SparkLambdaContainerHandler<RequestType,ResponseType>
extends AwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
Implementation of the
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");
});
-
Nested Class Summary
Nested classes/interfaces inherited from class com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler
AwsLambdaServletContainerHandler.StartupHandler -
Field Summary
Fields inherited from class com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler
servletContext, startupHandlerFields inherited from class com.amazonaws.serverless.proxy.internal.LambdaContainerHandler
lambdaContext, SERVER_INFO -
Constructor Summary
ConstructorsConstructorDescriptionSparkLambdaContainerHandler(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) -
Method Summary
Modifier and TypeMethodDescriptionReturns a new instance of an SparkLambdaContainerHandler initialized to work withAwsProxyRequestandAwsProxyResponseobjects.protected AwsHttpServletResponsegetContainerResponse(javax.servlet.http.HttpServletRequest request, CountDownLatch latch)Returns a new instance of an SparkLambdaContainerHandler initialized to work withHttpApiV2ProxyRequestandAwsProxyResponseobjects.javax.servlet.Servletprotected voidhandleRequest(javax.servlet.http.HttpServletRequest httpServletRequest, AwsHttpServletResponse httpServletResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext)voidMethods inherited from class com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler
doFilter, getFilterChain, getServletContext, onStartup, setServletContextMethods inherited from class com.amazonaws.serverless.proxy.internal.LambdaContainerHandler
getContainerConfig, getInitializationWrapper, getObjectMapper, proxy, proxyStream, setInitializationWrapper, setLogFormatter, stripBasePath
-
Constructor Details
-
SparkLambdaContainerHandler
public 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- Throws:
ContainerInitializationException
-
-
Method Details
-
getAwsProxyHandler
public static SparkLambdaContainerHandler<AwsProxyRequest,AwsProxyResponse> getAwsProxyHandler() throws ContainerInitializationExceptionReturns a new instance of an SparkLambdaContainerHandler initialized to work withAwsProxyRequestandAwsProxyResponseobjects.- Returns:
- a new instance of
SparkLambdaContainerHandler - Throws:
ContainerInitializationException- 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 container
-
getHttpApiV2ProxyHandler
public static SparkLambdaContainerHandler<HttpApiV2ProxyRequest,AwsProxyResponse> getHttpApiV2ProxyHandler() throws ContainerInitializationExceptionReturns a new instance of an SparkLambdaContainerHandler initialized to work withHttpApiV2ProxyRequestandAwsProxyResponseobjects.- Returns:
- a new instance of
SparkLambdaContainerHandler - Throws:
ContainerInitializationException- 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 container
-
getContainerResponse
protected AwsHttpServletResponse getContainerResponse(javax.servlet.http.HttpServletRequest request, CountDownLatch latch)- Specified by:
getContainerResponsein classLambdaContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
-
handleRequest
protected void handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest, AwsHttpServletResponse httpServletResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext) throws Exception- Specified by:
handleRequestin classLambdaContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>- Throws:
Exception
-
initialize
- Overrides:
initializein classAwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>- Throws:
ContainerInitializationException
-
getServlet
public javax.servlet.Servlet getServlet()
-