Class WebService

java.lang.Object
org.rapidcontext.core.storage.StorableObject
org.rapidcontext.core.type.WebService
All Implemented Interfaces:
HttpUtil
Direct Known Subclasses:
FileWebService, LogWebService, ProcedureWebService, StatusWebService, StorageWebService

public abstract class WebService extends StorableObject implements HttpUtil
An HTTP web service (request handler). This is a generic type, providing basic support for matching HTTP requests to the actual handlers (file handler, app handler, etc). A custom web service usually subclasses this class directly.
Version:
1.0
  • Field Details

    • METHODS_GET

      public static final String[] METHODS_GET
      An array with only the HTTP GET method.
    • METHODS_POST

      public static final String[] METHODS_POST
      An array with only the HTTP POST method.
    • METHODS_GET_POST

      public static final String[] METHODS_GET_POST
      An array with only the HTTP GET and HTTP POST methods.
    • KEY_DESCRIPTION

      public static final String KEY_DESCRIPTION
      The dictionary key for the description text.
      See Also:
    • KEY_MATCH

      public static final String KEY_MATCH
      The dictionary key for the request match array.
      See Also:
    • PATH

      public static final Path PATH
      The web service object storage path.
    • matchers

      protected ArrayList<WebMatcher> matchers
      The array of matcher objects.
  • Constructor Details

    • WebService

      public WebService(String id, String type, Dict dict)
      Creates a new web service from a serialized representation.
      Parameters:
      id - the object identifier
      type - the object type name
      dict - the serialized representation
  • Method Details

    • all

      public static Stream<WebService> all(Storage storage)
      Returns a stream of all web services found in the storage.
      Parameters:
      storage - the storage to search
      Returns:
      a stream of web service instances found
    • matchers

      public static Stream<WebMatcher> matchers(Storage storage)
      Returns a stream of all web matchers found in the storage (tied to a web service).
      Parameters:
      storage - the storage to search in
      Returns:
      a stream of web matcher instances found
    • init

      protected void init()
      Initializes this web service after loading it from a storage.
      Overrides:
      init in class StorableObject
    • description

      public String description()
      Returns the description text.
      Returns:
      the description text.
    • methods

      public String[] methods(Request request)
      Returns the HTTP methods supported for the specified request. The OPTIONS method is always supported and the HEAD method is automatically added if GET is supported.
      Parameters:
      request - the request to check
      Returns:
      the array of HTTP method names supported
    • methodsImpl

      protected abstract String[] methodsImpl(Request request)
      Returns the HTTP methods implemented for the specified request. The OPTIONS or HEAD methods doesn't have to be added to the result (added automatically later).
      Parameters:
      request - the request to check
      Returns:
      the array of HTTP method names supported
      See Also:
    • session

      public Session session(Request request, boolean create)
      Returns the current session for the request. Or creates a new one if none existed.
      Parameters:
      request - the request to check
      create - the session create flag
      Returns:
      the user session found or created, or null if not available
    • process

      public void process(Request request)
      Processes a request for this handler. This method assumes local request paths (removal of the mapped URL base).
      Parameters:
      request - the request to process
      See Also:
    • doOptions

      protected void doOptions(Request request)
      Processes an HTTP OPTIONS request.
      Parameters:
      request - the request to process
    • doHead

      protected void doHead(Request request)
      Processes an HTTP HEAD request. By default this method will call doGet() and set the response headers only flag if a result was generated. There is normally no need to subclass this method.
      Parameters:
      request - the request to process
    • doGet

      protected void doGet(Request request)
      Processes an HTTP GET request. By default this method will generate an HTTP 405 method not allowed error.
      Parameters:
      request - the request to process
    • doPost

      protected void doPost(Request request)
      Processes an HTTP POST request. By default this method will generate an HTTP 405 method not allowed error.
      Parameters:
      request - the request to process
    • doPatch

      protected void doPatch(Request request)
      Processes an HTTP PATCH request. By default this method will generate an HTTP 405 method not allowed error.
      Parameters:
      request - the request to process
    • doPut

      protected void doPut(Request request)
      Processes an HTTP PUT request. By default this method will generate an HTTP 405 method not allowed error.
      Parameters:
      request - the request to process
    • doDelete

      protected void doDelete(Request request)
      Processes an HTTP DELETE request. By default this method will generate an HTTP 405 method not allowed error.
      Parameters:
      request - the request to process
    • doTrace

      protected void doTrace(Request request)
      Processes an HTTP TRACE request. By default this method will generate an HTTP 405 method not allowed error.
      Parameters:
      request - the request to process
    • headerAllow

      protected void headerAllow(Request request)
      Adds the HTTP allow header to the response. The allowed methods listed in the header are retrieved from the methods() method.
      Parameters:
      request - the request to modify
    • errorBadRequest

      protected void errorBadRequest(Request request, String message)
      Sends an HTTP 400 bad request error.
      Parameters:
      request - the request to process
      message - the additional error message
    • errorUnauthorized

      protected void errorUnauthorized(Request request)
      Sends an HTTP 401 unauthorized or 403 forbidden error. The HTTP 401 authorization request will only be sent if the user is not already logged in.
      Parameters:
      request - the request to process
    • errorForbidden

      protected void errorForbidden(Request request)
      Sends an HTTP 403 forbidden error.
      Parameters:
      request - the request to process
    • errorNotFound

      protected void errorNotFound(Request request)
      Sends an HTTP 404 not found error.
      Parameters:
      request - the request to process
    • errorMethodNotAllowed

      protected void errorMethodNotAllowed(Request request)
      Sends an HTTP 405 method not allowed error.
      Parameters:
      request - the request to process
    • errorInternal

      protected void errorInternal(Request request, String message)
      Sends an HTTP 500 internal server error.
      Parameters:
      request - the request to process
      message - the additional error message