Package de.srsoftware.tools
Klasse PathHandler
java.lang.Object
de.srsoftware.tools.PathHandler
- Alle implementierten Schnittstellen:
HttpHandler
implementation of HttpHandler that attaches to a given path
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic final recordObject to hold auth dataclassthis class allows to bind a PathHandler to a HttpServer instance -
Feldübersicht
FelderModifizierer und TypFeldBeschreibungstatic final String"Authorization"static final String"Content-Type"static final StringDELETEstatic final Stringx-forwarded-hoststatic final StringX-forwarded-protostatic final StringGETstatic final StringhostSystem Loggerstatic final StringOPTIONSstatic final StringPATCHstatic final StringPOST -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic HttpExchangethis method sets the 'Access-Control-Allow-Credentials' header value to truestatic HttpExchangeallowOrigin(HttpExchange ex, String origin) this method sets the 'Access-Control-Allow-Origin' header valuebooleanbadRequest(HttpExchange ex, byte[] bytes) create a response with status code 400, send payloadbooleanbadRequest(HttpExchange ex, Object o) create a response with status code 400, send payloadBind the PathHandler object to one/several pathsstatic Stringbody(HttpExchange ex) extracts the body of an HttpExchangeextracts the request content type of a given HttpExchangebooleandoDelete(Path path, HttpExchange ex) "not found" default implementationbooleandoGet(Path path, HttpExchange ex) "not found" default implementationbooleandoOptions(Path path, HttpExchange ex) "not found" default implementationbooleandoPatch(Path path, HttpExchange ex) "not found" default implementationbooleandoPost(Path path, HttpExchange ex) "not found" default implementationformData(HttpExchange ex) fetches data from an form-urlencoded message bodyextract the value of an Authorization header, if presentstatic Optional<PathHandler.BasicAuth> retrieve and decode a basic auth headertry to extract a bearer token from the headers of the HttpExchangegetHeader(HttpExchange ex, String key) get the value of a specific header fieldvoidhandle(HttpExchange ex) booleanhandleMethod(String method, Path path, HttpExchange ex) Default implementation, defaulting to notFound(ex).static Stringhostname(HttpExchange ex) get the hostname requested by the client from the host header or – if set – the hostname submitted in the x-forwarded-host headerstatic org.json.JSONObjectjson(HttpExchange ex) Try to parse the body of this HttpExchange as JSON objectrequest the Accept-Language headerbooleannotFound(HttpExchange ex) sends a "not found" responsemap the query from the Request URI to a mapconvert the request URI to a path objectbooleansendContent(HttpExchange ex, byte[] bytes) send an array of bytesbooleansendContent(HttpExchange ex, int status, byte[] bytes) create a response given status code, send payloadbooleansendContent(HttpExchange ex, int status, Object o) create a response given status code, send payloadbooleansendContent(HttpExchange ex, Object o) send an object, thereby trying to guess the correct mime and transmission type.static booleansendEmptyResponse(int statusCode, HttpExchange ex) send a response without bodystatic booleansendRedirect(HttpExchange ex, String url) send a redirect to the clientbooleanserverError(HttpExchange ex, Object o) create a "internal server error" responsestatic Stringurl(HttpExchange ex) recover the URL from an HttpExchange object
-
Felddetails
-
AUTHORIZATION
"Authorization"- Siehe auch:
-
CONTENT_TYPE
"Content-Type"- Siehe auch:
-
DELETE
DELETE- Siehe auch:
-
FORWARDED_HOST
x-forwarded-host- Siehe auch:
-
FORWARDED_PROTO
X-forwarded-proto- Siehe auch:
-
GET
GET- Siehe auch:
-
HOST
host- Siehe auch:
-
OPTIONS
OPTIONS- Siehe auch:
-
PATCH
PATCH- Siehe auch:
-
POST
POST- Siehe auch:
-
LOG
System Logger
-
-
Konstruktordetails
-
PathHandler
public PathHandler()Creates a new instance
-
-
Methodendetails
-
allowOrigin
this method sets the 'Access-Control-Allow-Origin' header value- Parameter:
ex- the HttpExchange, whose response headers are to be modifiedorigin- the value for the header- Gibt zurück:
- the HttpExchange
-
allowCredentials
this method sets the 'Access-Control-Allow-Credentials' header value to true- Parameter:
ex- the HttpExchange, whose response headers are to be modified- Gibt zurück:
- the HttpExchange
-
badRequest
create a response with status code 400, send payload- Parameter:
ex- the HttpExchange to write tobytes- the payload- Gibt zurück:
- true – result is only created to allow return badRequest(…)
- Löst aus:
IOException- if writing to the HttpEchange object fails
-
badRequest
create a response with status code 400, send payload- Parameter:
ex- the HttpExchange to write too- the payload- Gibt zurück:
- true – result is only created to allow return badRequest(…)
- Löst aus:
IOException- if writing to the HttpEchange object fails
-
bindPath
Bind the PathHandler object to one/several paths- Parameter:
path- the paths to bind to- Gibt zurück:
- a bond, that can be used to create a context on a HttpServer
-
doDelete
"not found" default implementation- Parameter:
path- ignoredex- HttpExchange used to return the not-implemented notification- Gibt zurück:
- false
- Löst aus:
IOException- if sending the response fails
-
doGet
"not found" default implementation- Parameter:
path- ignoredex- HttpExchange used to return the not-implemented notification- Gibt zurück:
- false
- Löst aus:
IOException- if sending the response fails
-
doOptions
"not found" default implementation- Parameter:
path- ignoredex- HttpExchange used to return the not-implemented notification- Gibt zurück:
- false
- Löst aus:
IOException- if sending the response fails
-
doPatch
"not found" default implementation- Parameter:
path- ignoredex- HttpExchange used to return the not-implemented notification- Gibt zurück:
- false
- Löst aus:
IOException- if sending the response fails
-
doPost
"not found" default implementation- Parameter:
path- ignoredex- HttpExchange used to return the not-implemented notification- Gibt zurück:
- false
- Löst aus:
IOException- if sending the response fails
-
handle
- Angegeben von:
handlein SchnittstelleHttpHandler- Löst aus:
IOException
-
handleMethod
Default implementation, defaulting to notFound(ex). You can override this method to implement own httpRequest method handlers- Parameter:
method- method from the request headerpath- path from the request headerex- http exchange to process- Gibt zurück:
- a boolean that is ignored
- Löst aus:
IOException- if the transmission fails
-
relativePath
convert the request URI to a path object- Parameter:
ex- the http exchange to process- Gibt zurück:
- the path object
-
body
extracts the body of an HttpExchange- Parameter:
ex- the exchange to process- Gibt zurück:
- the content of the HttpExchange
- Löst aus:
IOException- if reading the body failed
-
contentType
extracts the request content type of a given HttpExchange- Parameter:
ex- the exchange whose content type is to be investigated- Gibt zurück:
- an Optional containing the content type or empty if no content type was submitted
-
formData
fetches data from an form-urlencoded message body- Parameter:
ex- the exchange whose content type is to be evaluated- Gibt zurück:
- a data map representing the form data
- Löst aus:
IOException- if the data cannot be read
-
getAuthToken
extract the value of an Authorization header, if present- Parameter:
ex- the HttpExchange to extract from- Gibt zurück:
- an optional, carrying the first value of an Authorization header, of present. empty, otherwise.
-
getBasicAuth
retrieve and decode a basic auth header- Parameter:
ex- the HttpExchange to process- Gibt zurück:
- an optional containing the basic auth data, of such a header is present. empty otherwise.
-
getBearer
try to extract a bearer token from the headers of the HttpExchange- Parameter:
ex- the HttpExchange to process- Gibt zurück:
- an optional carrying the token without the 'Bearer' prefix or empty, if no such token is given
-
getHeader
get the value of a specific header field- Parameter:
ex- the HttpExchange to extract fromkey- the key to search for- Gibt zurück:
- an Optional carrying the value belonging to the key, or empty, if no value is set
-
hostname
get the hostname requested by the client from the host header or – if set – the hostname submitted in the x-forwarded-host header- Parameter:
ex- the HttpExchange to process- Gibt zurück:
- the host url, e.g. https://example.com
-
json
Try to parse the body of this HttpExchange as JSON object- Parameter:
ex- the HttpExchange- Gibt zurück:
- a json object build from the contents of this exchange
- Löst aus:
IOException- if anything bad happens
-
languages
request the Accept-Language header- Parameter:
ex- the HttpExchange to prompt- Gibt zurück:
- the set of languages passed via header
-
notFound
sends a "not found" response- Parameter:
ex- the HttpExchange to act upon- Gibt zurück:
- false
- Löst aus:
IOException- if sending the response fails
-
queryParam
map the query from the Request URI to a map- Parameter:
ex- the HttpExchange to read the entries from- Gibt zurück:
- the query parameters as key → value map
-
sendEmptyResponse
send a response without body- Parameter:
statusCode- send this status codeex- the HttpExchange to act on- Gibt zurück:
- false
- Löst aus:
IOException- if the response cannot be sent
-
sendRedirect
send a redirect to the client- Parameter:
ex- the HttpExchange to useurl- the targeted location- Gibt zurück:
- false
- Löst aus:
IOException- if the anser cannot be sent
-
sendContent
create a response given status code, send payload- Parameter:
ex- the HttpExchange to write tostatus- the status codebytes- the payload- Gibt zurück:
- true – result is only created to allow return badRequest(…)
- Löst aus:
IOException- if writing to the HttpEchange object fails
-
sendContent
create a response given status code, send payload- Parameter:
ex- the HttpExchange to write tostatus- the status codeo- the payload- Gibt zurück:
- true – result is only created to allow return badRequest(…)
- Löst aus:
IOException- if writing to the HttpEchange object fails
-
sendContent
send an array of bytes- Parameter:
ex- the http exchange to respond tobytes- the payload to send- Gibt zurück:
- a boolean that is ignored
- Löst aus:
IOException- if writing to the HttpExchange object fails
-
sendContent
send an object, thereby trying to guess the correct mime and transmission type.- Parameter:
ex- the http exchange to respond too- the payload to send- Gibt zurück:
- a boolean that is ignored
- Löst aus:
IOException- if writing to the HttpExchange object fails
-
serverError
create a "internal server error" response- Parameter:
ex- the HttpExchange objecto- an additional payload- Gibt zurück:
- false
- Löst aus:
IOException- if the content cannot be sent
-
url
recover the URL from an HttpExchange object- Parameter:
ex- the HttpExchange object- Gibt zurück:
- the url of this object
-