-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic HttpRequest.Builder
acceptHeader
(HttpRequest.Builder builder, String acceptHeader) Set the "Accept" header if value is not null.static String
Calculate basic auth header value.static String
bearerAuthHeader
(String tokenBase64) Calculate bearer auth header value.static String
bearerAuthTokenFromHeader
(String authHeaderString) Extract the token, without decoding, The token supplied is expected to already be in base 64.static HttpRequest.Builder
contentTypeHeader
(HttpRequest.Builder builder, String contentType) Set the "Content-Type" header if value is not null.static <X> List<X>
static HttpRequest.Builder
createBuilder
(HttpRequest request) Create aHttpRequest.Builder
from anHttpRequest
.static <X> X
dft
(X value, X dftValue) static String
Return a string (assumed to be an absolute URI) without query string or fragment.static URI
endpointURI
(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 HttpResponse<InputStream>
executeJDK
(HttpClient httpClient, HttpRequest httpRequest) Execute request and return aHttpResponse<InputStream>
response.static <T> HttpResponse<T>
executeJDK
(HttpClient httpClient, HttpRequest httpRequest, HttpResponse.BodyHandler<T> bodyHandler) Execute request and return a response without authentication challenge handling.static void
finish
(InputStream input) Read to end ofInputStream
.static InputStream
getInputStream
(HttpResponse<InputStream> httpResponse) Get the InputStream from an HttpResponse, handling possible compression settings.static void
handleHttpStatusCode
(HttpResponse<InputStream> response) Deal with status code and any error message sent as a body in the response.static InputStream
handleResponseInputStream
(HttpResponse<InputStream> httpResponse) Handle the HTTP response (seehandleHttpStatusCode(HttpResponse)
) and return the InputStream if a 200.static void
handleResponseNoBody
(HttpResponse<InputStream> response) Handle the HTTP response and consume the body if a 200.static String
handleResponseRtnString
(HttpResponse<InputStream> response) Handle the HTTP response and read the body to produce a string if a 200.static TypedInputStream
handleResponseTypedInputStream
(HttpResponse<InputStream> httpResponse) Handle the HTTP response (seehandleHttpStatusCode(HttpResponse)
) and return the TypedInputStream that includes theContent-Type
if a 200.static void
httpPushData
(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 boolean
isEndpoint
(URI uri) Test whether a URI is a service endpoint.static boolean
Test whether a URL identifies a Fuseki server.static void
Allow setting additional/optional HTTP headers and query parameters on a per remote service (including for SERVICE) basis.static HttpRequest
newGetRequest
(String url, Consumer<HttpRequest.Builder> modifier) Return a HttpRequeststatic HttpResponse.BodyHandler<Void>
noBody()
static HttpRequest.Builder
requestBuilder
(String url, Map<String, String> httpHeaders, long readTimeout, TimeUnit readTimeoutUnit) static HttpRequest.Builder
requestBuilderFor
(String serviceEndpoint) static String
requestTargetServer
(URI uri) The "request target" for digest auth.static String
requestURL
(String url, String queryString) Query string is assumed to already be encoded.static String
responseHeader
(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 the Accept header to the value.static HttpRequest.BodyPublisher
stringBody
(String str) static URI
toRequestURI
(String uriStr) String toURI
.static String
Encode 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
(seefinish(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
HttpException
for 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-Type
if 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
-
finish
Read to end ofInputStream
.close
may close the underlying HTTP connection. SeeHttpResponse.BodySubscribers.ofInputStream()
. -
toRequestURI
String toURI
. ThrowsHttpException
on 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.Builder
from 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
AuthEnv
for authentication registration.
SeeexecuteJDK(java.net.http.HttpClient, java.net.http.HttpRequest)
to execute exactly once without challenge response handling.- Parameters:
httpClient
-httpRequest
-- Returns:
- HttpResponse
- See Also:
-
executeJDK
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
-
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.send
converting exceptions toHttpException
. request and responses are logged as "debug" to loggerorg.apache.jena.http.HTTP
.- Parameters:
httpClient
-httpRequest
-bodyHandler
-- Returns:
- HttpResponse
-
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 the Accept header to the value. 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.
-