Class AwsLambdaServletContainerHandler<RequestType,ResponseType,ContainerRequestType extends jakarta.servlet.http.HttpServletRequest,ContainerResponseType extends jakarta.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
- All Implemented Interfaces:
InitializableLambdaContainerHandler
public abstract class AwsLambdaServletContainerHandler<RequestType,ResponseType,ContainerRequestType extends jakarta.servlet.http.HttpServletRequest,ContainerResponseType extends jakarta.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 jakarta.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(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.Servlet servlet) Applies the filter chain in the request lifecycleprotected jakarta.servlet.FilterChaingetFilterChain(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.Servlet servlet) jakarta.servlet.ServletContextReturns the current ServletContext.voidThis method is called on the first (cold) invocationvoidYou can use theonStartupto intercept the ServletContext as the Spring application is initialized and inject custom values.protected voidsetServletContext(jakarta.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 jakarta.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 jakarta.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(jakarta.servlet.ServletContext context) Sets the ServletContext in the handler and initialized a newFilterChainManager- Parameters:
context- An initialized ServletContext
-
getFilterChain
protected jakarta.servlet.FilterChain getFilterChain(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.Servlet servlet) -
doFilter
protected void doFilter(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.Servlet servlet) throws IOException, jakarta.servlet.ServletException Applies 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:
IOExceptionjakarta.servlet.ServletException
-
initialize
Description copied from interface:InitializableLambdaContainerHandlerThis method is called on the first (cold) invocation- Specified by:
initializein interfaceInitializableLambdaContainerHandler- Specified by:
initializein classLambdaContainerHandler<RequestType,ResponseType, ContainerRequestType extends jakarta.servlet.http.HttpServletRequest, ContainerResponseType extends jakarta.servlet.http.HttpServletResponse> - Throws:
ContainerInitializationException- in case initialization fails
-