Package org.rapidcontext.core.type
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
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.rapidcontext.util.HttpUtil
HttpUtil.HEADER, HttpUtil.Helper, HttpUtil.METHOD, HttpUtil.STATUS
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The dictionary key for the description text.static final String
The dictionary key for the request match array.protected ArrayList
<WebMatcher> The array of matcher objects.static final String[]
An array with only the HTTP GET method.static final String[]
An array with only the HTTP GET and HTTP POST methods.static final String[]
An array with only the HTTP POST method.static final Path
The web service object storage path.Fields inherited from class org.rapidcontext.core.storage.StorableObject
dict, KEY_ACTIVATED_TIME, KEY_CLASSNAME, KEY_ID, KEY_TYPE, PREFIX_COMPUTED, PREFIX_HIDDEN
-
Constructor Summary
ConstructorsConstructorDescriptionWebService
(String id, String type, Dict dict) Creates a new web service from a serialized representation. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stream
<WebService> Returns a stream of all web services found in the storage.Returns the description text.protected void
Processes an HTTP DELETE request.protected void
Processes an HTTP GET request.protected void
Processes an HTTP HEAD request.protected void
Processes an HTTP OPTIONS request.protected void
Processes an HTTP PATCH request.protected void
Processes an HTTP POST request.protected void
Processes an HTTP PUT request.protected void
Processes an HTTP TRACE request.protected void
errorBadRequest
(Request request, String message) Sends an HTTP 400 bad request error.protected void
errorForbidden
(Request request) Sends an HTTP 403 forbidden error.protected void
errorInternal
(Request request, String message) Sends an HTTP 500 internal server error.protected void
errorMethodNotAllowed
(Request request) Sends an HTTP 405 method not allowed error.protected void
errorNotFound
(Request request) Sends an HTTP 404 not found error.protected void
errorUnauthorized
(Request request) Sends an HTTP 401 unauthorized or 403 forbidden error.protected void
headerAllow
(Request request) Adds the HTTP allow header to the response.protected void
init()
Initializes this web service after loading it from a storage.static Stream
<WebMatcher> Returns a stream of all web matchers found in the storage (tied to a web service).String[]
Returns the HTTP methods supported for the specified request.protected abstract String[]
methodsImpl
(Request request) Returns the HTTP methods implemented for the specified request.void
Processes a request for this handler.Returns the current session for the request.Methods inherited from class org.rapidcontext.core.storage.StorableObject
activate, activatedTime, destroy, id, isActive, isModified, passivate, path, serialize, sterilize, toString, type
-
Field Details
-
METHODS_GET
An array with only the HTTP GET method. -
METHODS_POST
An array with only the HTTP POST method. -
METHODS_GET_POST
An array with only the HTTP GET and HTTP POST methods. -
KEY_DESCRIPTION
The dictionary key for the description text.- See Also:
-
KEY_MATCH
The dictionary key for the request match array.- See Also:
-
PATH
The web service object storage path. -
matchers
The array of matcher objects.
-
-
Constructor Details
-
WebService
Creates a new web service from a serialized representation.- Parameters:
id
- the object identifiertype
- the object type namedict
- the serialized representation
-
-
Method Details
-
all
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
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 classStorableObject
-
description
Returns the description text.- Returns:
- the description text.
-
methods
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
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
Returns the current session for the request. Or creates a new one if none existed.- Parameters:
request
- the request to checkcreate
- the session create flag- Returns:
- the user session found or created, or null if not available
-
process
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
Processes an HTTP OPTIONS request.- Parameters:
request
- the request to process
-
doHead
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
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
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
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
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
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
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
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
Sends an HTTP 400 bad request error.- Parameters:
request
- the request to processmessage
- the additional error message
-
errorUnauthorized
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
Sends an HTTP 403 forbidden error.- Parameters:
request
- the request to process
-
errorNotFound
Sends an HTTP 404 not found error.- Parameters:
request
- the request to process
-
errorMethodNotAllowed
Sends an HTTP 405 method not allowed error.- Parameters:
request
- the request to process
-
errorInternal
Sends an HTTP 500 internal server error.- Parameters:
request
- the request to processmessage
- the additional error message
-