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
Felder -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungallowOrigin(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 implementationbooleandoPatch(Path path, HttpExchange ex) "not found" default implementationbooleandoPost(Path path, HttpExchange ex) "not found" default implementationextract the value of an Authorization header, if presentstatic Optional<PathHandler.BasicAuth> try 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) static Stringhostname(HttpExchange ex) static org.json.JSONObjectjson(HttpExchange ex) Try to parse the body of this HttpExchange as JSON objectstatic Stringlanguage(HttpExchange ex) request the Accept-Language headerbooleannotFound(HttpExchange ex) sends a "not found" responsemap the query from the Request URI to a mapquerySplit(String query) map the query from the string to a mapbooleansendContent(HttpExchange ex, byte[] bytes) booleansendContent(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) 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
- Siehe auch:
-
CONTENT_TYPE
- Siehe auch:
-
DEFAULT_LANGUAGE
- Siehe auch:
-
DELETE
- Siehe auch:
-
GET
- Siehe auch:
-
HOST
- Siehe auch:
-
LOG
-
PATCH
- Siehe auch:
-
POST
- Siehe auch:
-
-
Konstruktordetails
-
PathHandler
public PathHandler()
-
-
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
-
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
-
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
- Löst aus:
IOException
-
relativePath
-
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
-
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
-
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
-
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
-
language
request the Accept-Language header- Parameter:
ex- the HttpExchange to prompt- Gibt zurück:
- the first language from the Accept-Language header or the default language
-
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
-
querySplit
map the query from the string to a map- Parameter:
query- the query string- 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
- Löst aus:
IOException
-
sendContent
- Löst aus:
IOException
-
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
-