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 containerpublic abstract class AbstractLambdaContainerHandler<RequestType,ResponseType,ContainerRequestType,ContainerResponseType>
extends java.lang.Object
LambdaContainerHandler
.Modifier and Type | Field and Description |
---|---|
protected com.amazonaws.services.lambda.runtime.Context |
lambdaContext |
static java.lang.String |
SERVER_INFO |
Modifier | Constructor and Description |
---|---|
protected |
AbstractLambdaContainerHandler(java.lang.Class<RequestType> requestClass,
java.lang.Class<ResponseType> responseClass,
com.amazonaws.serverless.proxy.RequestReader<RequestType,ContainerRequestType> requestReader,
com.amazonaws.serverless.proxy.ResponseWriter<ContainerResponseType,ResponseType> responseWriter,
com.amazonaws.serverless.proxy.SecurityContextWriter<RequestType> securityContextWriter,
com.amazonaws.serverless.proxy.ExceptionHandler<ResponseType> exceptionHandler)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
static com.amazonaws.serverless.proxy.model.ContainerConfig |
getContainerConfig()
Returns the current container configuration object.
|
protected abstract ContainerResponseType |
getContainerResponse(ContainerRequestType request,
java.util.concurrent.CountDownLatch latch)
Get the container response.
|
protected abstract void |
handleRequest(ContainerRequestType containerRequest,
ContainerResponseType containerResponse,
com.amazonaws.services.lambda.runtime.Context lambdaContext)
Handle the request.
|
abstract void |
initialize()
Initialize the container.
|
protected abstract com.fasterxml.jackson.databind.ObjectMapper |
objectMapper()
The object mapper.
|
ResponseType |
proxy(RequestType request,
com.amazonaws.services.lambda.runtime.Context context)
Proxies requests to the underlying container given the incoming Lambda request.
|
void |
proxyStream(java.io.InputStream input,
java.io.OutputStream output,
com.amazonaws.services.lambda.runtime.Context context)
Handles Lambda
RequestStreamHandler method. |
protected abstract com.fasterxml.jackson.databind.ObjectReader |
readerFor(java.lang.Class<RequestType> requestClass)
Gets a reader for the given request class.
|
void |
setLogFormatter(com.amazonaws.serverless.proxy.LogFormatter<ContainerRequestType,ContainerResponseType> formatter)
Sets the formatter used to log request data in CloudWatch.
|
void |
stripBasePath(java.lang.String basePath)
Configures the library to strip a base path from incoming requests before passing them on to the wrapped
framework.
|
protected abstract com.fasterxml.jackson.databind.ObjectWriter |
writerFor(java.lang.Class<ResponseType> responseClass)
Gets a writer for the given response class.
|
public static final java.lang.String SERVER_INFO
protected com.amazonaws.services.lambda.runtime.Context lambdaContext
protected AbstractLambdaContainerHandler(java.lang.Class<RequestType> requestClass, java.lang.Class<ResponseType> responseClass, com.amazonaws.serverless.proxy.RequestReader<RequestType,ContainerRequestType> requestReader, com.amazonaws.serverless.proxy.ResponseWriter<ContainerResponseType,ResponseType> responseWriter, com.amazonaws.serverless.proxy.SecurityContextWriter<RequestType> securityContextWriter, com.amazonaws.serverless.proxy.ExceptionHandler<ResponseType> exceptionHandler)
requestClass
- The request classresponseClass
- The response classrequestReader
- The request readerresponseWriter
- The response writersecurityContextWriter
- The security context writerexceptionHandler
- The exception handlerprotected abstract com.fasterxml.jackson.databind.ObjectMapper objectMapper()
protected abstract com.fasterxml.jackson.databind.ObjectWriter writerFor(java.lang.Class<ResponseType> responseClass)
responseClass
- The response classprotected abstract com.fasterxml.jackson.databind.ObjectReader readerFor(java.lang.Class<RequestType> requestClass)
requestClass
- The request classprotected abstract ContainerResponseType getContainerResponse(ContainerRequestType request, java.util.concurrent.CountDownLatch latch)
request
- The requestlatch
- The count down latchprotected abstract void handleRequest(ContainerRequestType containerRequest, ContainerResponseType containerResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext) throws java.lang.Exception
containerRequest
- The container requestcontainerResponse
- The responselambdaContext
- The lambda contextjava.lang.Exception
- The exceptionpublic abstract void initialize() throws com.amazonaws.serverless.exceptions.ContainerInitializationException
com.amazonaws.serverless.exceptions.ContainerInitializationException
- when an error occurspublic void stripBasePath(java.lang.String basePath)
basePath
- The base path to be stripped from the requestpublic void setLogFormatter(com.amazonaws.serverless.proxy.LogFormatter<ContainerRequestType,ContainerResponseType> formatter)
com.amazonaws.serverless.proxy.internal.servlet.ApacheCombinedServletLogFormatter
.formatter
- The log formatter objectpublic ResponseType proxy(RequestType request, com.amazonaws.services.lambda.runtime.Context context)
request
- The incoming Lambda requestcontext
- The execution context for the Lambda functionpublic void proxyStream(java.io.InputStream input, java.io.OutputStream output, com.amazonaws.services.lambda.runtime.Context context) throws java.io.IOException
RequestStreamHandler
method. The method uses an ObjectMapper
to transform the incoming input stream into the given RequestType
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.input
- Lambda's incoming input streamoutput
- Lambda's response output streamcontext
- Lambda's context objectjava.io.IOException
- If an error occurs during the stream processingpublic static com.amazonaws.serverless.proxy.model.ContainerConfig getContainerConfig()