Class AbstractHandler<B extends BotConfiguration,​I,​O>

  • Type Parameters:
    B - The Bot configuration
    I - input type.
    O - output type.
    All Implemented Interfaces:
    com.amazonaws.services.lambda.runtime.RequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent,​com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent>, io.micronaut.context.ApplicationContextProvider, io.micronaut.function.aws.MicronautLambdaContext, io.micronaut.function.executor.FunctionExecutor<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent,​com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent>, java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    Handler, Handler

    public abstract class AbstractHandler<B extends BotConfiguration,​I,​O>
    extends io.micronaut.function.aws.MicronautRequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent,​com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent>
    Abstract class to handle a Chatbots webhook in an AWS Lambda Handler.
    Since:
    1.0.0
    Author:
    Sergio del Amo
    • Field Summary

      • Fields inherited from class io.micronaut.function.aws.MicronautRequestHandler

        ENV_X_AMZN_TRACE_ID, LAMBDA_TRACE_HEADER_PROP, MDC_DEFAULT_AWS_REQUEST_ID, MDC_DEFAULT_FUNCTION_ARN, MDC_DEFAULT_FUNCTION_MEMORY_SIZE, MDC_DEFAULT_FUNCTION_NAME, MDC_DEFAULT_FUNCTION_REMAINING_TIME, MDC_DEFAULT_FUNCTION_VERSION, MDC_DEFAULT_XRAY_TRACE_ID
      • Fields inherited from class io.micronaut.function.executor.AbstractExecutor

        applicationContext
      • Fields inherited from interface io.micronaut.function.aws.MicronautLambdaContext

        ENVIRONMENT_LAMBDA
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractHandler()
      Default constructor; will initialize a suitable ApplicationContext for Lambda deployment.
      protected AbstractHandler​(io.micronaut.context.ApplicationContext applicationContext)
      Constructor used to inject a preexisting ApplicationContext.
      protected AbstractHandler​(io.micronaut.context.ApplicationContextBuilder applicationContextBuilder)
      Constructor used to inject a preexisting ApplicationContextBuilder.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent execute​(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)  
      protected abstract Dispatcher<B,​I,​O> getDispatcher()  
      protected abstract io.micronaut.serde.ObjectMapper getObjectMapper()  
      protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent ok()  
      protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent ok​(java.lang.Object body, java.lang.String contentType)  
      protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okHtml​(java.lang.Object body)  
      protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okJson​(java.lang.Object body)  
      protected abstract com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okSerializer​(java.lang.Object body)  
      protected abstract java.util.Optional<B> parseBot​(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)  
      protected java.util.Optional<java.lang.String> parseHeader​(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request, java.lang.String headerName)  
      protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent response​(io.micronaut.http.HttpStatus httpStatus)  
      protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent serverError()  
      protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent unauthorized()  
      protected abstract boolean validate​(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)  
      • Methods inherited from class io.micronaut.function.aws.MicronautRequestHandler

        buildApplicationContext, convertInput, handleRequest, mdcput, newApplicationContextBuilder, parseXrayTraceId, populateMappingDiagnosticContextValues, populateMappingDiagnosticContextWithXrayTraceId
      • Methods inherited from class io.micronaut.function.executor.AbstractExecutor

        close, getApplicationContext, resolveFunction, resolveFunctionName, startEnvironment
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractHandler

        protected AbstractHandler()
        Default constructor; will initialize a suitable ApplicationContext for Lambda deployment.
      • AbstractHandler

        protected AbstractHandler​(io.micronaut.context.ApplicationContext applicationContext)
        Constructor used to inject a preexisting ApplicationContext.
        Parameters:
        applicationContext - the application context
      • AbstractHandler

        protected AbstractHandler​(io.micronaut.context.ApplicationContextBuilder applicationContextBuilder)
        Constructor used to inject a preexisting ApplicationContextBuilder.
        Parameters:
        applicationContextBuilder - the application context builder
    • Method Detail

      • execute

        public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent execute​(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)
      • validate

        @NonNull
        protected abstract boolean validate​(@NonNull
                                            com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)
        Parameters:
        request - API Gateway Request
        Returns:
        Whether the request is valid or not
      • parseBot

        @NonNull
        protected abstract java.util.Optional<B> parseBot​(@NonNull
                                                          com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)
        Parameters:
        request - API Gateway Request
        Returns:
        The Bot associated to the request
      • getObjectMapper

        @NonNull
        protected abstract io.micronaut.serde.ObjectMapper getObjectMapper()
        Returns:
        The Object Mapper
      • getDispatcher

        @NonNull
        protected abstract Dispatcher<B,​I,​O> getDispatcher()
        Returns:
        The Dispatcher
      • ok

        @NonNull
        protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent ok()
        Returns:
        Returns a 200 response
      • unauthorized

        @NonNull
        protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent unauthorized()
        Returns:
        Returns a 401 response
      • serverError

        @NonNull
        protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent serverError()
        Returns:
        Returns a 500 response
      • response

        protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent response​(io.micronaut.http.HttpStatus httpStatus)
        Parameters:
        httpStatus - HTTP Status
        Returns:
        Returns a 500 response
      • okSerializer

        @NonNull
        protected abstract com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okSerializer​(@NonNull
                                                                                                                  java.lang.Object body)
      • okJson

        @NonNull
        protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okJson​(@NonNull
                                                                                                   java.lang.Object body)
        Parameters:
        body - The Body to be serialized as JSoN
        Returns:
        Returns a 200 response
      • okHtml

        @NonNull
        protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okHtml​(@NonNull
                                                                                                   java.lang.Object body)
        Parameters:
        body - The Body as an HTML String
        Returns:
        Returns a 200 response with HTML content type
      • ok

        @NonNull
        protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent ok​(@NonNull
                                                                                               java.lang.Object body,
                                                                                               @NonNull
                                                                                               java.lang.String contentType)
        Parameters:
        body - The Body to respond
        contentType - Content Type of the resonse
        Returns:
        Returns a 200 response with the supplied content type and body
      • parseHeader

        @NonNull
        protected java.util.Optional<java.lang.String> parseHeader​(@NonNull
                                                                   com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request,
                                                                   @NonNull
                                                                   java.lang.String headerName)
        Parameters:
        request - The API Gateway Request
        headerName - HTTP Header Name
        Returns:
        The HTTP Header Value