Class ServiceRequest<T>

Type Parameters:
T - generic type
Direct Known Subclasses:
BsonFromCsvRequest, BsonRequest, ByteArrayRequest, GraphQLRequest, JsonRequest, StringRequest, UninitializedRequest

public abstract class ServiceRequest<T> extends Request<T>
Base class for Request implementations that can be used in service requests. Only one request object can be instantiated per exchage. The request object is instantiated by ServiceExchangeInitializer using the requestInitializer() function defined by the handling service
Author:
Andrea Di Cesare <andrea@softinstigate.com>
  • Field Details

    • content

      protected T content
    • CONTENT_INJECTED

      public static final io.undertow.util.AttachmentKey<Boolean> CONTENT_INJECTED
      CONTENT_INJECTED is true if the request body has been already injected. calling setContent() and setFileInputStream() sets CONTENT_INJECTED to true. calling getContent() or getFileInputStream() when CONTENT_INJECTED=false triggers content injection via MongoRequestContentInjector
  • Constructor Details

    • ServiceRequest

      protected ServiceRequest(io.undertow.server.HttpServerExchange exchange)
  • Method Details

    • of

      public static ServiceRequest<?> of(io.undertow.server.HttpServerExchange exchange)
    • of

      public static <R extends ServiceRequest<?>> R of(io.undertow.server.HttpServerExchange exchange, Class<R> type)
    • getContent

      public T getContent() throws BadRequestException
      Retrieves the content of the request. If the content has not been previously read, this method invokes parseContent() to parse and attach the content to the request. If an error occurs during the parsing of the content, the request is marked as errored, indicating that the content could not be successfully parsed and attached.
      Returns:
      the content of the request, which may be newly parsed or previously retrieved
      Throws:
      BadRequestException
    • setContent

      public void setContent(T content)
    • parseContent

      public abstract T parseContent() throws IOException, BadRequestException
      Parses the content from the exchange and converts it into an instance of the specified type T. This method retrieves data from the exchange, interprets it according to the expected format, and attempts to convert this data into an object of type T.
      Returns:
      an instance of T representing the parsed content
      Throws:
      IOException - if an IO error occurs
      BadRequestException - if the content does not match the expected format for type T
    • isHandledBy

      public boolean isHandledBy(String serviceName)
      Parameters:
      serviceName -
      Returns:
      true if the request is handled by the specified Service
    • isContentInjected

      public final boolean isContentInjected()
    • setContentInjected

      public final void setContentInjected(boolean value)