Class SpringLambdaContainerHandler<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.SpringLambdaContainerHandler<RequestType,ResponseType>
- Type Parameters:
RequestType- The incoming event typeResponseType- The expected return type
public class SpringLambdaContainerHandler<RequestType,ResponseType>
extends AwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
Spring 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler
AwsLambdaServletContainerHandler.StartupHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.web.context.ConfigurableWebApplicationContextFields 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
ConstructorsConstructorDescriptionSpringLambdaContainerHandler(Class<RequestType> requestTypeClass, Class<ResponseType> responseTypeClass, RequestReader<RequestType,javax.servlet.http.HttpServletRequest> requestReader, ResponseWriter<AwsHttpServletResponse,ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler, org.springframework.web.context.ConfigurableWebApplicationContext applicationContext, InitializationWrapper init)Creates a new container handler with the given reader and writer objects -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateSpringProfiles(String... p)Activates the given Spring profiles in the application.getAwsProxyHandler(Class<?>... config)Creates a default SpringLambdaContainerHandler initialized with the `AwsProxyRequest` and `AwsProxyResponse` objectsgetAwsProxyHandler(org.springframework.web.context.ConfigurableWebApplicationContext applicationContext, String... profiles)Creates a default SpringLambdaContainerHandler initialized with the `AwsProxyRequest` and `AwsProxyResponse` objects and sets the given profiles as activeprotected AwsHttpServletResponsegetContainerResponse(javax.servlet.http.HttpServletRequest request, CountDownLatch latch)getHttpApiV2ProxyHandler(Class<?>... config)Creates a default SpringLambdaContainerHandler initialized with the `HttpApiV2ProxyRequest` and `AwsProxyResponse` objectsprotected voidhandleRequest(javax.servlet.http.HttpServletRequest containerRequest, AwsHttpServletResponse containerResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext)voidprotected voidOverriding this method allows to customize the standard Spring DispatcherServlet or to register additional servletsvoidsetRefreshContext(boolean refresh)Asks the custom web application initializer to refresh the Spring context.Methods 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
-
Field Details
-
appContext
protected final org.springframework.web.context.ConfigurableWebApplicationContext appContext
-
-
Constructor Details
-
SpringLambdaContainerHandler
public SpringLambdaContainerHandler(Class<RequestType> requestTypeClass, Class<ResponseType> responseTypeClass, RequestReader<RequestType,javax.servlet.http.HttpServletRequest> requestReader, ResponseWriter<AwsHttpServletResponse,ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler, org.springframework.web.context.ConfigurableWebApplicationContext applicationContext, InitializationWrapper init)Creates a new container handler with the given reader and writer objects- Parameters:
requestTypeClass- The class for the incoming Lambda eventrequestReader- An implementation of `RequestReader`responseWriter- An implementation of `ResponseWriter`securityContextWriter- An implementation of `SecurityContextWriter`exceptionHandler- An implementation of `ExceptionHandler`
-
-
Method Details
-
getAwsProxyHandler
public static SpringLambdaContainerHandler<AwsProxyRequest,AwsProxyResponse> getAwsProxyHandler(Class<?>... config) throws ContainerInitializationExceptionCreates a default SpringLambdaContainerHandler initialized with the `AwsProxyRequest` and `AwsProxyResponse` objects- Parameters:
config- A set of classes annotated with the Spring @Configuration annotation- Returns:
- An initialized instance of the `SpringLambdaContainerHandler`
- Throws:
ContainerInitializationException- When the Spring framework fails to start.
-
getAwsProxyHandler
public static SpringLambdaContainerHandler<AwsProxyRequest,AwsProxyResponse> getAwsProxyHandler(org.springframework.web.context.ConfigurableWebApplicationContext applicationContext, String... profiles) throws ContainerInitializationExceptionCreates a default SpringLambdaContainerHandler initialized with the `AwsProxyRequest` and `AwsProxyResponse` objects and sets the given profiles as active- Parameters:
applicationContext- A custom ConfigurableWebApplicationContext to be usedprofiles- The spring profiles to activate- Returns:
- An initialized instance of the `SpringLambdaContainerHandler`
- Throws:
ContainerInitializationException- When the Spring framework fails to start.
-
getHttpApiV2ProxyHandler
public static SpringLambdaContainerHandler<HttpApiV2ProxyRequest,AwsProxyResponse> getHttpApiV2ProxyHandler(Class<?>... config) throws ContainerInitializationExceptionCreates a default SpringLambdaContainerHandler initialized with the `HttpApiV2ProxyRequest` and `AwsProxyResponse` objects- Parameters:
config- A set of classes annotated with the Spring @Configuration annotation- Returns:
- An initialized instance of the `SpringLambdaContainerHandler`
- Throws:
ContainerInitializationException- When the Spring framework fails to start.
-
setRefreshContext
public void setRefreshContext(boolean refresh)Asks the custom web application initializer to refresh the Spring context.- Parameters:
refresh- true if the context should be refreshed
-
getContainerResponse
protected AwsHttpServletResponse getContainerResponse(javax.servlet.http.HttpServletRequest request, CountDownLatch latch)- Specified by:
getContainerResponsein classLambdaContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
-
activateSpringProfiles
Activates the given Spring profiles in the application. This method will cause the context to be refreshed. To use a single Spring profile, use the static methodgetAwsProxyHandler(ConfigurableWebApplicationContext, String...)- Parameters:
p- A number of spring profiles- Throws:
ContainerInitializationException- if the initializer is not set yet.
-
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
-
registerServlets
protected void registerServlets()Overriding this method allows to customize the standard Spring DispatcherServlet or to register additional servlets
-