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 @NonNull Dispatcher<B,I,O>
     
    protected abstract @NonNull io.micronaut.serde.ObjectMapper
     
    protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    ok()
     
    protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    ok(@NonNull Object body, @NonNull String contentType)
     
    protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    okHtml(@NonNull Object body)
     
    protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    okJson(@NonNull Object body)
     
    protected abstract @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    okSerializer(@NonNull Object body)
     
    protected abstract @NonNull Optional<B>
    parseBot(@NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)
     
    protected @NonNull Optional<String>
    parseHeader(@NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request, @NonNull String headerName)
     
    protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
    response(io.micronaut.http.HttpStatus httpStatus)
     
    protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
     
    protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
     
    protected abstract @io.micronaut.core.annotation.NonNull boolean
    validate(@NonNull 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 @io.micronaut.core.annotation.NonNull boolean validate(@NonNull @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 @NonNull Optional<B> parseBot(@NonNull @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 @NonNull io.micronaut.serde.ObjectMapper getObjectMapper()
      Returns:
      The Object Mapper
    • getDispatcher

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

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

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

      @NonNull protected @NonNull 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 @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okSerializer(@NonNull @NonNull Object body)
    • okJson

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

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

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