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 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
- Direct Known Subclasses:
AwsLambdaServletContainerHandler
public abstract class LambdaContainerHandler<RequestType,ResponseType,ContainerRequestType,ContainerResponseType>
extends Object
implements InitializableLambdaContainerHandler
Abstract class that declares the basic methods and objects for implementations of
LambdaContainerHandler.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.amazonaws.services.lambda.runtime.Contextstatic final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLambdaContainerHandler(Class<RequestType> requestClass, Class<ResponseType> responseClass, RequestReader<RequestType, ContainerRequestType> requestReader, ResponseWriter<ContainerResponseType, ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler) protectedLambdaContainerHandler(Class<RequestType> requestClass, Class<ResponseType> responseClass, RequestReader<RequestType, ContainerRequestType> requestReader, ResponseWriter<ContainerResponseType, ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler, InitializationWrapper init) -
Method Summary
Modifier and TypeMethodDescriptionstatic ContainerConfigReturns the current container configuration object.protected abstract ContainerResponseTypegetContainerResponse(ContainerRequestType request, CountDownLatch latch) Returns the initialization wrapper this container handler will monitor to handle eventsstatic com.fasterxml.jackson.databind.ObjectMapperprotected abstract voidhandleRequest(ContainerRequestType containerRequest, ContainerResponseType containerResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext) abstract voidThis method is called on the first (cold) invocationproxy(RequestType request, com.amazonaws.services.lambda.runtime.Context context) Proxies requests to the underlying container given the incoming Lambda request.voidproxyStream(InputStream input, OutputStream output, com.amazonaws.services.lambda.runtime.Context context) Handles LambdaRequestStreamHandlermethod.voidSets a new initialization wrapper.voidSets the formatter used to log request data in CloudWatch.voidstripBasePath(String basePath) Configures the library to strip a base path from incoming requests before passing them on to the wrapped framework.
-
Field Details
-
SERVER_INFO
- See Also:
-
lambdaContext
protected com.amazonaws.services.lambda.runtime.Context lambdaContext
-
-
Constructor Details
-
LambdaContainerHandler
protected LambdaContainerHandler(Class<RequestType> requestClass, Class<ResponseType> responseClass, RequestReader<RequestType, ContainerRequestType> requestReader, ResponseWriter<ContainerResponseType, ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler, InitializationWrapper init) -
LambdaContainerHandler
protected LambdaContainerHandler(Class<RequestType> requestClass, Class<ResponseType> responseClass, RequestReader<RequestType, ContainerRequestType> requestReader, ResponseWriter<ContainerResponseType, ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler)
-
-
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
Description copied from interface:InitializableLambdaContainerHandlerThis method is called on the first (cold) invocation- Specified by:
initializein interfaceInitializableLambdaContainerHandler- Throws:
ContainerInitializationException- in case initialization fails
-
getObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() -
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
Sets a new initialization wrapper.- Parameters:
wrapper- The wrapper this instance will use to decide whether it can start handling events.
-
stripBasePath
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/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
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 objectApacheCombinedServletLogFormatter.- 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 requestcontext- 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 LambdaRequestStreamHandlermethod. The method uses anObjectMapperto transform the incoming input stream into the givenLambdaContainerHandlerand then calls theproxy(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 streamoutput- Lambda's response output streamcontext- Lambda's context object- Throws:
IOException- If an error occurs during the stream processing
-
getContainerConfig
Returns the current container configuration object.- Returns:
- The container configuration object
-