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 to
ResponseType - The expected Lambda function response object. Responses from the container will be written to this model object
ContainerRequestType - The request type for the wrapped Java container
ContainerResponseType - 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
  • Field Details

  • Constructor Details

  • Method Details

    • onStartup

      You can use the onStartup to intercept the ServletContext as the Spring application is initialized and inject custom values. The StartupHandler is called after the onStartup method of the LambdaSpringApplicationinitializer implementation. 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 the StartupHandler functional 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 new FilterChainManager
      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 HttpServletRequest
      response - The response object. This must be an implementation of HttpServletResponse
      servlet - Servlet at the end of the chain (optional).
      Throws:
      IOException
      jakarta.servlet.ServletException
    • initialize

      public void initialize() throws ContainerInitializationException
      Description copied from interface: InitializableLambdaContainerHandler
      This method is called on the first (cold) invocation
      Specified by:
      initialize in interface InitializableLambdaContainerHandler
      Specified by:
      initialize in class LambdaContainerHandler<RequestType,ResponseType,ContainerRequestType extends jakarta.servlet.http.HttpServletRequest,ContainerResponseType extends jakarta.servlet.http.HttpServletResponse>
      Throws:
      ContainerInitializationException - in case initialization fails