Class SpringBootLambdaContainerHandler<RequestType,ResponseType>
java.lang.Object
com.amazonaws.serverless.proxy.internal.LambdaContainerHandler<RequestType,ResponseType,ContainerRequestType,ContainerResponseType>
com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler<RequestType,ResponseType>
- Type Parameters:
RequestType- The incoming event typeResponseType- The expected return type
public class SpringBootLambdaContainerHandler<RequestType,ResponseType>
extends AwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
SpringBoot 1.x implementation of the `LambdaContainerHandler` abstract class. This class uses the `LambdaSpringApplicationInitializer`
object behind the scenes to proxy requests. The default implementation leverages the `AwsProxyHttpServletRequest` and
`AwsHttpServletResponse` implemented in the `aws-serverless-java-container-core` package.
Important: Make sure to add
LambdaFlushResponseListener in your SpringBootServletInitializer subclass configure().-
Nested Class Summary
Nested classes/interfaces inherited from class com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler
AwsLambdaServletContainerHandler.StartupHandler -
Field Summary
Fields inherited from class com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler
servletContext, startupHandlerFields inherited from class com.amazonaws.serverless.proxy.internal.LambdaContainerHandler
lambdaContext, SERVER_INFO -
Constructor Summary
ConstructorsConstructorDescriptionSpringBootLambdaContainerHandler(Class<RequestType> requestTypeClass, Class<ResponseType> responseTypeClass, RequestReader<RequestType,javax.servlet.http.HttpServletRequest> requestReader, ResponseWriter<AwsHttpServletResponse,ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler, Class<?> springBootInitializer, InitializationWrapper init, org.springframework.boot.WebApplicationType applicationType)Creates a new container handler with the given reader and writer objects -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateSpringProfiles(String... profiles)getAwsProxyHandler(Class<?> springBootInitializer, String... profiles)Creates a default SpringLambdaContainerHandler initialized with the `AwsProxyRequest` and `AwsProxyResponse` objects and the given Spring profilesprotected AwsHttpServletResponsegetContainerResponse(javax.servlet.http.HttpServletRequest request, CountDownLatch latch)getHttpApiV2ProxyHandler(Class<?> springBootInitializer, String... profiles)Creates a default SpringLambdaContainerHandler initialized with the `AwsProxyRequest` and `HttpApiV2ProxyRequest` objects and the given Spring profilesWe need to rely on the static instance of this for SpringBoot because we need it to access the ServletContext.protected voidhandleRequest(javax.servlet.http.HttpServletRequest containerRequest, AwsHttpServletResponse containerResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext)voidMethods inherited from class com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler
doFilter, getFilterChain, getServletContext, onStartup, setServletContextMethods inherited from class com.amazonaws.serverless.proxy.internal.LambdaContainerHandler
getContainerConfig, getInitializationWrapper, getObjectMapper, proxy, proxyStream, setInitializationWrapper, setLogFormatter, stripBasePath
-
Constructor Details
-
SpringBootLambdaContainerHandler
public SpringBootLambdaContainerHandler(Class<RequestType> requestTypeClass, Class<ResponseType> responseTypeClass, RequestReader<RequestType,javax.servlet.http.HttpServletRequest> requestReader, ResponseWriter<AwsHttpServletResponse,ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler, Class<?> springBootInitializer, InitializationWrapper init, org.springframework.boot.WebApplicationType applicationType)Creates a new container handler with the given reader and writer objects- Parameters:
requestTypeClass- The class for the incoming Lambda eventresponseTypeClass- The class for the Lambda function outputrequestReader- An implementation of `RequestReader`responseWriter- An implementation of `ResponseWriter`securityContextWriter- An implementation of `SecurityContextWriter`exceptionHandler- An implementation of `ExceptionHandler`springBootInitializer-SpringBootServletInitializerclassinit- The initialization Wrapper that will be used to start Spring BootapplicationType- The Spring Web Application Type
-
-
Method Details
-
getInstance
We need to rely on the static instance of this for SpringBoot because we need it to access the ServletContext. Normally, SpringBoot would initialize its own embedded container through theSpringApplication.run()method. However, in our case we need to rely on the pre-initialized handler and need to fetch information from it for our mockServerlessReactiveServletEmbeddedServerFactory.- Returns:
- The initialized instance
-
getAwsProxyHandler
public static SpringBootLambdaContainerHandler<AwsProxyRequest,AwsProxyResponse> getAwsProxyHandler(Class<?> springBootInitializer, String... profiles) throws ContainerInitializationExceptionCreates a default SpringLambdaContainerHandler initialized with the `AwsProxyRequest` and `AwsProxyResponse` objects and the given Spring profiles- Parameters:
springBootInitializer-SpringBootServletInitializerclassprofiles- A list of Spring profiles to activate- Returns:
- An initialized instance of the `SpringLambdaContainerHandler`
- Throws:
ContainerInitializationException- If an error occurs while initializing the Spring framework
-
getHttpApiV2ProxyHandler
public static SpringBootLambdaContainerHandler<HttpApiV2ProxyRequest,AwsProxyResponse> getHttpApiV2ProxyHandler(Class<?> springBootInitializer, String... profiles) throws ContainerInitializationExceptionCreates a default SpringLambdaContainerHandler initialized with the `AwsProxyRequest` and `HttpApiV2ProxyRequest` objects and the given Spring profiles- Parameters:
springBootInitializer-SpringBootServletInitializerclassprofiles- A list of Spring profiles to activate- Returns:
- An initialized instance of the `SpringLambdaContainerHandler`
- Throws:
ContainerInitializationException- If an error occurs while initializing the Spring framework
-
activateSpringProfiles
-
getContainerResponse
protected AwsHttpServletResponse getContainerResponse(javax.servlet.http.HttpServletRequest request, CountDownLatch latch)- Specified by:
getContainerResponsein classLambdaContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
-
handleRequest
protected void handleRequest(javax.servlet.http.HttpServletRequest containerRequest, AwsHttpServletResponse containerResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext) throws Exception- Specified by:
handleRequestin classLambdaContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>- Throws:
Exception
-
initialize
- Overrides:
initializein classAwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>- Throws:
ContainerInitializationException
-