-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpRequest.BuilderacceptHeader(HttpRequest.Builder builder, String acceptHeader) Set the "Accept" header if value is not null.static StringCalculate basic auth header value.static StringbearerAuthHeader(String tokenBase64) Calculate bearer auth header value.static StringbearerAuthTokenFromHeader(String authHeaderString) Extract the token, without decoding, The token supplied is expected to already be in base 64.static HttpRequest.BuildercontentTypeHeader(HttpRequest.Builder builder, String contentType) Set the "Content-Type" header if value is not null.static <X> List<X>static HttpRequest.BuildercreateBuilder(HttpRequest request) Create aHttpRequest.Builderfrom anHttpRequest.static <X> Xdft(X value, X dftValue) static StringReturn a string (assumed to be an absolute URI) without query string or fragment.static URIendpointURI(URI uri) URI, without query string and fragment.static HttpResponse<InputStream>execute(HttpClient httpClient, HttpRequest httpRequest) Execute a request, return aHttpResponse<InputStream>which can be passed tohandleResponseInputStream(HttpResponse)which will convert non-2xx status code toHttpExceptions.static CompletableFuture<HttpResponse<InputStream>>executeAsync(HttpClient httpClient, HttpRequest httpRequest) Execute a request, return aHttpResponse<X>which can be passed tohandleHttpStatusCode(HttpResponse)which will convert non-2xx status code toHttpExceptions.static <T> HttpResponse<T>executeJDK(HttpClient httpClient, HttpRequest httpRequest, HttpResponse.BodyHandler<T> bodyHandler) Execute request and return a response without authentication challenge handling.static CompletableFuture<HttpResponse<InputStream>>executeJDKAsync(HttpClient httpClient, HttpRequest httpRequest) Execute request and return aHttpResponse<InputStream>response.static <T> CompletableFuture<HttpResponse<T>>executeJDKAsync(HttpClient httpClient, HttpRequest httpRequest, HttpResponse.BodyHandler<T> bodyHandler) static voidfinishInputStream(InputStream input) Read to end ofInputStream.static voidfinishResponse(HttpResponse<InputStream> response) Finish withHttpResponse<InputStream>.static InputStreamgetInputStream(HttpResponse<InputStream> httpResponse) Get the InputStream from an HttpResponse, handling possible compression settings.static voidhandleHttpStatusCode(HttpResponse<InputStream> response) Deal with status code and any error message sent as a body in the response.static InputStreamhandleResponseInputStream(HttpResponse<InputStream> httpResponse) Handle the HTTP response (seehandleHttpStatusCode(HttpResponse)) and return the InputStream if a 200.static voidhandleResponseNoBody(HttpResponse<InputStream> response) Handle the HTTP response and consume the body if a 200.static StringhandleResponseRtnString(HttpResponse<InputStream> response) Handle the HTTP response and read the body to produce a string if a 200.static StringhandleResponseRtnString(HttpResponse<InputStream> response, Consumer<InputStream> callback) Handle the HTTP response and read the body to produce a string if a 200.static TypedInputStreamhandleResponseTypedInputStream(HttpResponse<InputStream> httpResponse) Handle the HTTP response (seehandleHttpStatusCode(HttpResponse)) and return the TypedInputStream that includes theContent-Typeif a 200.static voidhttpPushData(HttpClient httpClient, Push style, String url, Consumer<HttpRequest.Builder> modifier, HttpRequest.BodyPublisher body) Push data.static HttpResponse<InputStream>httpPushWithResponse(HttpClient httpClient, Push style, String url, Consumer<HttpRequest.Builder> modifier, HttpRequest.BodyPublisher body) static booleanisEndpoint(URI uri) Test whether a URI is a service endpoint.static booleanTest whether a URL identifies a Fuseki server.static voidAllow setting additional/optional HTTP headers and query parameters on a per remote service (including for SERVICE) basis.static HttpRequestnewGetRequest(String url, Consumer<HttpRequest.Builder> modifier) Return a HttpRequeststatic HttpResponse.BodyHandler<Void>noBody()static HttpRequest.BuilderrequestBuilder(String url, Map<String, String> httpHeaders, long readTimeout, TimeUnit readTimeoutUnit) static HttpRequest.BuilderrequestBuilderFor(String serviceEndpoint) static StringrequestTargetServer(URI uri) The "request target" for digest auth.static StringrequestURL(String url, String queryString) Query string is assumed to already be encoded.static StringresponseHeader(HttpResponse<?> response, String headerName) Return the first header of the given name, or null if nonestatic Consumer<HttpRequest.Builder>setHeaders(Map<String, String> headers) Return a modifier that will set headers using the values in the map.static HttpRequest.BodyPublisherstringBody(String str) static URItoRequestURI(String uriStr) String toURI.static StringEncode a string suitable for use in an URL query string
-
Field Details
-
BEARER
-
BEARER_PREFIX
-
FusekiRequestIdHeader
-
-
Method Details
-
noBody
-
stringBody
-
basicAuth
Calculate basic auth header value. Use with header "Authorization" (constantHttpNames.hAuthorization). Best used over https. -
bearerAuthHeader
Calculate bearer auth header value. The token supplied is expected to already be in base 64. Use with header "Authorization" (constantHttpNames.hAuthorization). -
bearerAuthTokenFromHeader
Extract the token, without decoding, The token supplied is expected to already be in base 64. Use with header "Authorization" (constantHttpNames.hAuthorization). -
getInputStream
Get the InputStream from an HttpResponse, handling possible compression settings. The application must consume or close theInputStream(seefinishInputStream(InputStream)). Closing the InputStream may close the HTTP connection. Assumes the status code has been handled e.g.handleHttpStatusCode(java.net.http.HttpResponse<java.io.InputStream>)has been called. -
handleHttpStatusCode
Deal with status code and any error message sent as a body in the response.It is this handling 4xx/5xx error messages in the body that forces the use of
InputStream, not genericT. We don't know until we see the status code how we are going to process the response body.Exits normally without processing the body if the response is 200.
Throws
HttpExceptionfor 3xx (redirection should have happened by now), 4xx and 5xx, having consumed the body input stream. -
handleResponseInputStream
Handle the HTTP response (seehandleHttpStatusCode(HttpResponse)) and return the InputStream if a 200.- Parameters:
httpResponse-- Returns:
- InputStream
-
handleResponseTypedInputStream
public static TypedInputStream handleResponseTypedInputStream(HttpResponse<InputStream> httpResponse) Handle the HTTP response (seehandleHttpStatusCode(HttpResponse)) and return the TypedInputStream that includes theContent-Typeif a 200.- Parameters:
httpResponse-- Returns:
- TypedInputStream
-
handleResponseNoBody
Handle the HTTP response and consume the body if a 200. Otherwise, throw anHttpException.- Parameters:
response-
-
handleResponseRtnString
Handle the HTTP response and read the body to produce a string if a 200. Otherwise, throw anHttpException.- Parameters:
response-- Returns:
- String
-
handleResponseRtnString
public static String handleResponseRtnString(HttpResponse<InputStream> response, Consumer<InputStream> callback) Handle the HTTP response and read the body to produce a string if a 200. Otherwise, throw anHttpException.- Parameters:
response-callback- A callback that receives the opened input stream.- Returns:
- String
-
finishResponse
Finish withHttpResponse<InputStream>. This read and drops any remaining bytes in the response body.closemay close the underlying HTTP connection. SeeHttpResponse.BodySubscribers.ofInputStream(). -
finishInputStream
Read to end ofInputStream.closemay close the underlying HTTP connection. SeeHttpResponse.BodySubscribers.ofInputStream(). -
toRequestURI
String toURI. ThrowsHttpExceptionon bad syntax or if the URI isn't absolute. -
isEndpoint
Test whether a URI is a service endpoint. It must be absolute, with host and path, and without query string or fragment. -
endpoint
Return a string (assumed to be an absolute URI) without query string or fragment. -
endpointURI
URI, without query string and fragment. -
requestTargetServer
The "request target" for digest auth. The server-side name of a resource - no authority (the host part).RFC 7616 (digest auth), section 3.4 The Effective Request URI (Section 5.5 of RFC7230).
For SPARQL, the target is the service, not a resource named by the uri+query string.
This makes query-by-GET and query-by-POST work the same way.
-
newGetRequest
Return a HttpRequest -
dft
public static <X> X dft(X value, X dftValue) -
copyArray
-
urlEncodeQueryString
Encode a string suitable for use in an URL query string -
requestURL
Query string is assumed to already be encoded. -
requestBuilderFor
-
requestBuilder
-
createBuilder
Create aHttpRequest.Builderfrom anHttpRequest. -
acceptHeader
Set the "Accept" header if value is not null. Returns the builder. -
contentTypeHeader
public static HttpRequest.Builder contentTypeHeader(HttpRequest.Builder builder, String contentType) Set the "Content-Type" header if value is not null. Returns the builder. -
execute
Execute a request, return aHttpResponse<InputStream>which can be passed tohandleResponseInputStream(HttpResponse)which will convert non-2xx status code toHttpExceptions.This function applies the HTTP authentication challenge support and will repeat the request if necessary with added authentication.
See
AuthEnvfor authentication registration.
SeeexecuteJDK(java.net.http.HttpClient, java.net.http.HttpRequest, java.net.http.HttpResponse.BodyHandler<T>)to execute exactly once without challenge response handling.- Parameters:
httpClient-httpRequest-- Returns:
- HttpResponse
- See Also:
-
executeAsync
public static CompletableFuture<HttpResponse<InputStream>> executeAsync(HttpClient httpClient, HttpRequest httpRequest) Execute a request, return aHttpResponse<X>which can be passed tohandleHttpStatusCode(HttpResponse)which will convert non-2xx status code toHttpExceptions.This function applies the HTTP authentication challenge support and will repeat the request if necessary with added authentication.
See
AuthEnvfor authentication registration.
SeeexecuteJDK(java.net.http.HttpClient, java.net.http.HttpRequest, java.net.http.HttpResponse.BodyHandler<T>)to execute exactly once without challenge response handling.- Parameters:
httpClient-httpRequest-- Returns:
- HttpResponse
- See Also:
-
executeJDK
public static <T> HttpResponse<T> executeJDK(HttpClient httpClient, HttpRequest httpRequest, HttpResponse.BodyHandler<T> bodyHandler) Execute request and return a response without authentication challenge handling. Status codes have not been handled. This is a call toHttpClient.sendconverting exceptions toHttpException. request and responses are logged as "debug" to loggerorg.apache.jena.http.HTTP.- Parameters:
httpClient-httpRequest-bodyHandler-- Returns:
- HttpResponse
-
executeJDKAsync
public static CompletableFuture<HttpResponse<InputStream>> executeJDKAsync(HttpClient httpClient, HttpRequest httpRequest) Execute request and return aHttpResponse<InputStream>response. Status codes have not been handled. The response can be passed tohandleResponseInputStream(HttpResponse)which will convert non-2xx status code toHttpExceptions.- Parameters:
httpClient-httpRequest-- Returns:
- HttpResponse
-
executeJDKAsync
public static <T> CompletableFuture<HttpResponse<T>> executeJDKAsync(HttpClient httpClient, HttpRequest httpRequest, HttpResponse.BodyHandler<T> bodyHandler) -
httpPushData
public static void httpPushData(HttpClient httpClient, Push style, String url, Consumer<HttpRequest.Builder> modifier, HttpRequest.BodyPublisher body) Push data. POST, PUT, PATCH request with no response body data. -
httpPushWithResponse
public static HttpResponse<InputStream> httpPushWithResponse(HttpClient httpClient, Push style, String url, Consumer<HttpRequest.Builder> modifier, HttpRequest.BodyPublisher body) -
modifyByService
public static void modifyByService(String serviceURI, Context context, Params params, Map<String, String> httpHeaders) Allow setting additional/optional HTTP headers and query parameters on a per remote service (including for SERVICE) basis.- ARQ.httpRequestModifer - the specific modifier
- ARQ.httpRegistryRequestModifer - the registry, keyed by service URL.
-
setHeaders
Return a modifier that will set headers using the values in the map. An argument of "null" means "no action". -
responseHeader
Return the first header of the given name, or null if none -
isFuseki
Test whether a URL identifies a Fuseki server. This operation can not guarantee to detect a Fuseki server - for example, it may be behind a reverse proxy that masks the signature.
-