Class JerseyLambdaContainerHandler<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.jersey.JerseyLambdaContainerHandler<RequestType,ResponseType>
- Type Parameters:
RequestType- The type for the incoming Lambda eventResponseType- The type for Lambda's return value
public class JerseyLambdaContainerHandler<RequestType,ResponseType>
extends AwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
Jersey-specific implementation of the
LambdaContainerHandler interface. Given a Jax-Rs application
starts Jersey's ApplicationHandler and proxies requests and responses using the RequestReader and
ResponseWriter objects. The reader and writer objects are inherited from the BaseLambdaContainerHandler
object.
public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyResponse> {
private ResourceConfig jerseyApplication = new ResourceConfig().packages("your.app.package");
private JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> container = JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) {
return container.proxy(awsProxyRequest, context);
}
}
- See Also:
LambdaContainerHandler
-
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
ConstructorsConstructorDescriptionJerseyLambdaContainerHandler(Class<RequestType> requestTypeClass, Class<ResponseType> responseTypeClass, RequestReader<RequestType,javax.servlet.http.HttpServletRequest> requestReader, ResponseWriter<AwsHttpServletResponse,ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler, javax.ws.rs.core.Application jaxRsApplication)Private constructor for a LambdaContainer. -
Method Summary
Modifier and TypeMethodDescriptiongetAwsProxyHandler(javax.ws.rs.core.Application jaxRsApplication)Returns an initializedJerseyLambdaContainerHandlerthat includesRequestReaderandResponseWriterobjects for theAwsProxyRequestandAwsProxyResponseobjects.protected AwsHttpServletResponsegetContainerResponse(javax.servlet.http.HttpServletRequest request, CountDownLatch latch)getHttpApiV2ProxyHandler(javax.ws.rs.core.Application jaxRsApplication)Returns an initializedJerseyLambdaContainerHandlerthat includesRequestReaderandResponseWriterobjects for theHttpApiV2ProxyRequestandAwsProxyResponseobjects.org.glassfish.jersey.internal.inject.InjectionManagerjavax.servlet.Servletprotected voidhandleRequest(javax.servlet.http.HttpServletRequest httpServletRequest, AwsHttpServletResponse httpServletResponse, 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
-
JerseyLambdaContainerHandler
public JerseyLambdaContainerHandler(Class<RequestType> requestTypeClass, Class<ResponseType> responseTypeClass, RequestReader<RequestType,javax.servlet.http.HttpServletRequest> requestReader, ResponseWriter<AwsHttpServletResponse,ResponseType> responseWriter, SecurityContextWriter<RequestType> securityContextWriter, ExceptionHandler<ResponseType> exceptionHandler, javax.ws.rs.core.Application jaxRsApplication)Private constructor for a LambdaContainer. Sets the application object, sets the ApplicationHandler, and initializes the application using theonStartupmethod.- Parameters:
requestTypeClass- The class for the expected event typeresponseTypeClass- The class for the output typerequestReader- A request reader instanceresponseWriter- A response writer instancesecurityContextWriter- A security context writer objectexceptionHandler- An exception handlerjaxRsApplication- The JaxRs application
-
-
Method Details
-
getAwsProxyHandler
public static JerseyLambdaContainerHandler<AwsProxyRequest,AwsProxyResponse> getAwsProxyHandler(javax.ws.rs.core.Application jaxRsApplication)Returns an initializedJerseyLambdaContainerHandlerthat includesRequestReaderandResponseWriterobjects for theAwsProxyRequestandAwsProxyResponseobjects.- Parameters:
jaxRsApplication- A configured Jax-Rs application object. For Jersey apps this can be the defaultResourceConfigobject- Returns:
- A
JerseyLambdaContainerHandlerobject
-
getHttpApiV2ProxyHandler
public static JerseyLambdaContainerHandler<HttpApiV2ProxyRequest,AwsProxyResponse> getHttpApiV2ProxyHandler(javax.ws.rs.core.Application jaxRsApplication)Returns an initializedJerseyLambdaContainerHandlerthat includesRequestReaderandResponseWriterobjects for theHttpApiV2ProxyRequestandAwsProxyResponseobjects.- Parameters:
jaxRsApplication- A configured Jax-Rs application object. For Jersey apps this can be the defaultResourceConfigobject- Returns:
- A
JerseyLambdaContainerHandlerobject
-
handleRequest
protected void handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest, AwsHttpServletResponse httpServletResponse, com.amazonaws.services.lambda.runtime.Context lambdaContext) throws Exception- Specified by:
handleRequestin classLambdaContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>- Throws:
Exception
-
getContainerResponse
protected AwsHttpServletResponse getContainerResponse(javax.servlet.http.HttpServletRequest request, CountDownLatch latch)- Specified by:
getContainerResponsein classLambdaContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
-
initialize
public void initialize()- Overrides:
initializein classAwsLambdaServletContainerHandler<RequestType,ResponseType,javax.servlet.http.HttpServletRequest,AwsHttpServletResponse>
-
getInjectionManager
public org.glassfish.jersey.internal.inject.InjectionManager getInjectionManager() -
getServlet
public javax.servlet.Servlet getServlet()
-