Class AwsLambdaServletContainerHandler<RequestType,ResponseType,ContainerRequestType extends javax.servlet.http.HttpServletRequest,ContainerResponseType extends javax.servlet.http.HttpServletResponse>
java.lang.Object
com.amazonaws.serverless.proxy.internal.LambdaContainerHandler<RequestType,ResponseType,ContainerRequestType,ContainerResponseType>
com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler<RequestType,ResponseType,ContainerRequestType,ContainerResponseType>
- Type Parameters:
RequestType- The expected request object. This is the model class that the event JSON is de-serialized toResponseType- The expected Lambda function response object. Responses from the container will be written to this model objectContainerRequestType- The request type for the wrapped Java containerContainerResponseType- The response or response writer type for the wrapped Java container
public abstract class AwsLambdaServletContainerHandler<RequestType,ResponseType,ContainerRequestType extends javax.servlet.http.HttpServletRequest,ContainerResponseType extends javax.servlet.http.HttpServletResponse>
extends LambdaContainerHandler<RequestType,ResponseType,ContainerRequestType,ContainerResponseType>
Abstract extension of the code
LambdaContainerHandler object that adds protected variables for the
ServletContext and FilterChainManager. This object should be extended by the framework-specific
implementations that want to support the servlet 3.1 specs.
Because Lambda only allows one event per container at a time, this object also acts as the RequestDispatcher-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected javax.servlet.ServletContextFields inherited from class com.amazonaws.serverless.proxy.internal.LambdaContainerHandler
lambdaContext, SERVER_INFO -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAwsLambdaServletContainerHandler(Class<RequestType> requestTypeClass, Class<ResponseType> responseTypeClass, RequestReader<RequestType,ContainerRequestType> requestReader, ResponseWriter<ContainerResponseType,ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.Servlet servlet)Applies the filter chain in the request lifecycleprotected javax.servlet.FilterChaingetFilterChain(javax.servlet.http.HttpServletRequest req, javax.servlet.Servlet servlet)javax.servlet.ServletContextReturns the current ServletContext.voidvoidYou can use theonStartupto intercept the ServletContext as the Spring application is initialized and inject custom values.protected voidsetServletContext(javax.servlet.ServletContext context)Sets the ServletContext in the handler and initialized a newFilterChainManagerMethods inherited from class com.amazonaws.serverless.proxy.internal.LambdaContainerHandler
getContainerConfig, getContainerResponse, getInitializationWrapper, getObjectMapper, handleRequest, proxy, proxyStream, setInitializationWrapper, setLogFormatter, stripBasePath
-
Field Details
-
startupHandler
-
servletContext
protected javax.servlet.ServletContext servletContext
-
-
Constructor Details
-
AwsLambdaServletContainerHandler
protected AwsLambdaServletContainerHandler(Class<RequestType> requestTypeClass, Class<ResponseType> responseTypeClass, RequestReader<RequestType,ContainerRequestType> requestReader, ResponseWriter<ContainerResponseType,ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler)
-
-
Method Details
-
onStartup
You can use theonStartupto intercept the ServletContext as the Spring application is initialized and inject custom values. The StartupHandler is called after theonStartupmethod of theLambdaSpringApplicationinitializerimplementation. For example, you can use this method to add custom filters to the servlet context:handler = SpringLambdaContainerHandler.getAwsProxyHandler(EchoSpringAppConfig.class); handler.onStartup(c -> { // the "c" parameter to this function is the initialized servlet context c.addFilter("CustomHeaderFilter", CustomHeaderFilter.class); });- Parameters:
h- A lambda expression that implements theStartupHandlerfunctional interface
-
getServletContext
public javax.servlet.ServletContext getServletContext()Returns the current ServletContext. If the framework implementation does not set the value for servlet context this method will return null.- Returns:
- The initialized servlet context if the framework-specific implementation requires one, otherwise null
-
setServletContext
protected void setServletContext(javax.servlet.ServletContext context)Sets the ServletContext in the handler and initialized a newFilterChainManager- Parameters:
context- An initialized ServletContext
-
getFilterChain
protected javax.servlet.FilterChain getFilterChain(javax.servlet.http.HttpServletRequest req, javax.servlet.Servlet servlet) -
doFilter
protected void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.Servlet servlet) throws IOException, javax.servlet.ServletExceptionApplies the filter chain in the request lifecycle- Parameters:
request- The Request object. This must be an implementation of HttpServletRequestresponse- The response object. This must be an implementation of HttpServletResponseservlet- Servlet at the end of the chain (optional).- Throws:
IOExceptionjavax.servlet.ServletException
-
initialize
- Specified by:
initializein classLambdaContainerHandler<RequestType,ResponseType,ContainerRequestType extends javax.servlet.http.HttpServletRequest,ContainerResponseType extends javax.servlet.http.HttpServletResponse>- Throws:
ContainerInitializationException
-