Class AbstractHandler<B extends BotConfiguration,I,O>

java.lang.Object
io.micronaut.function.executor.AbstractExecutor<C>
io.micronaut.function.executor.AbstractFunctionExecutor<I,O,com.amazonaws.services.lambda.runtime.Context>
io.micronaut.function.aws.MicronautRequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent,com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent>
io.micronaut.chatbots.lambda.AbstractHandler<B,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>, Closeable, 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

    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
    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

    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>
     
    protected abstract io.micronaut.serde.ObjectMapper
     
    protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    ok()
     
    protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    ok(Object body, String contentType)
     
    protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    okHtml(Object body)
     
    protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    okJson(Object body)
     
    protected abstract com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
     
    protected abstract Optional<B>
    parseBot(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)
     
    protected Optional<String>
    parseHeader(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request, String headerName)
     
    protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    response(io.micronaut.http.HttpStatus httpStatus)
     
    protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
     
    protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
     
    protected abstract boolean
    validate(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)
     

    Methods inherited from class io.micronaut.function.aws.MicronautRequestHandler

    buildApplicationContext, convertInput, handleRequest, newApplicationContextBuilder

    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 Details

    • 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 Details

    • 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 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 Object body)
    • okJson

      @NonNull protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okJson(@NonNull 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 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 Object body, @NonNull 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 Optional<String> parseHeader(@NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request, @NonNull String headerName)
      Parameters:
      request - The API Gateway Request
      headerName - HTTP Header Name
      Returns:
      The HTTP Header Value