Class LambdaContainerHandler<RequestType,​ResponseType,​ContainerRequestType,​ContainerResponseType>

java.lang.Object
com.amazonaws.serverless.proxy.internal.LambdaContainerHandler<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
Direct Known Subclasses:
AwsLambdaServletContainerHandler

public abstract class LambdaContainerHandler<RequestType,​ResponseType,​ContainerRequestType,​ContainerResponseType> extends Object
Abstract class that declares the basic methods and objects for implementations of LambdaContainerHandler.
  • Field Details

    • SERVER_INFO

      public static final String SERVER_INFO
      See Also:
      Constant Field Values
    • lambdaContext

      protected com.amazonaws.services.lambda.runtime.Context lambdaContext
  • Constructor Details

  • Method Details

    • getContainerResponse

      protected abstract ContainerResponseType getContainerResponse(ContainerRequestType request, CountDownLatch latch)
    • handleRequest

      protected abstract void handleRequest(ContainerRequestType containerRequest, ContainerResponseType containerResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext) throws Exception
      Throws:
      Exception
    • initialize

      public abstract void initialize() throws ContainerInitializationException
      Throws:
      ContainerInitializationException
    • getObjectMapper

      public static com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • getInitializationWrapper

      public InitializationWrapper getInitializationWrapper()
      Returns the initialization wrapper this container handler will monitor to handle events
      Returns:
      The initialization wrapper that was passed to the constructor and this instance will use to decide whether it can start handling events.
    • setInitializationWrapper

      public void setInitializationWrapper(InitializationWrapper wrapper)
      Sets a new initialization wrapper.
      Parameters:
      wrapper - The wrapper this instance will use to decide whether it can start handling events.
    • stripBasePath

      public void stripBasePath(String basePath)
      Configures the library to strip a base path from incoming requests before passing them on to the wrapped framework. This was added in response to issue #34 (https://github.com/awslabs/aws-serverless-java-container/issues/34). When creating a base path mapping for custom domain names in API Gateway we want to be able to strip the base path from the request - the underlying service may not recognize this path.
      Parameters:
      basePath - The base path to be stripped from the request
    • setLogFormatter

      public void setLogFormatter(LogFormatter<ContainerRequestType,​ContainerResponseType> formatter)
      Sets the formatter used to log request data in CloudWatch. By default this is set to use an Apache combined log format based on the servlet request and response object ApacheCombinedServletLogFormatter.
      Parameters:
      formatter - The log formatter object
    • proxy

      public ResponseType proxy(RequestType request, com.amazonaws.services.lambda.runtime.Context context)
      Proxies requests to the underlying container given the incoming Lambda request. This method returns a populated return object for the Lambda function.
      Parameters:
      request - The incoming Lambda request
      context - The execution context for the Lambda function
      Returns:
      A valid response type
    • proxyStream

      public void proxyStream(InputStream input, OutputStream output, com.amazonaws.services.lambda.runtime.Context context) throws IOException
      Handles Lambda RequestStreamHandler method. The method uses an ObjectMapper to transform the incoming input stream into the given LambdaContainerHandler and then calls the proxy(Object, Context) method to handle the request. The output from the proxy method is written on the given output stream.
      Parameters:
      input - Lambda's incoming input stream
      output - Lambda's response output stream
      context - Lambda's context object
      Throws:
      IOException - If an error occurs during the stream processing
    • getContainerConfig

      public static ContainerConfig getContainerConfig()
      Returns the current container configuration object.
      Returns:
      The container configuration object