use of java.net.http.HttpRequest in project jena by apache.
the class HttpLib method createBuilder.
/**
* Create a {@code HttpRequest.Builder} from an {@code HttpRequest}.
*/
public static HttpRequest.Builder createBuilder(HttpRequest request) {
HttpRequest.Builder builder = HttpRequest.newBuilder().expectContinue(request.expectContinue()).uri(request.uri());
builder.method(request.method(), request.bodyPublisher().orElse(BodyPublishers.noBody()));
request.timeout().ifPresent(builder::timeout);
request.version().ifPresent(builder::version);
request.headers().map().forEach((name, values) -> values.forEach(value -> builder.header(name, value)));
return builder;
}
use of java.net.http.HttpRequest in project jena by apache.
the class HttpRDF method execGetToInput.
/**
* MUST consume or close the input stream
* @see HttpLib#finish(HttpResponse)
*/
private static HttpResponse<InputStream> execGetToInput(HttpClient client, String url, Consumer<HttpRequest.Builder> modifier) {
Objects.requireNonNull(client);
Objects.requireNonNull(url);
HttpRequest requestData = HttpLib.newGetRequest(url, modifier);
HttpResponse<InputStream> response = execute(client, requestData);
handleHttpStatusCode(response);
return response;
}
use of java.net.http.HttpRequest in project jena by apache.
the class HttpOp method httpOptions.
/**
* OPTIONS. Returns the HTTP response "Allow" field string.
*/
public static String httpOptions(HttpClient httpClient, String url) {
// Need to access the response headers
HttpRequest.Builder builder = HttpLib.requestBuilderFor(url).uri(toRequestURI(url)).method(HttpNames.METHOD_OPTIONS, BodyPublishers.noBody());
HttpRequest request = builder.build();
HttpResponse<InputStream> response = execute(httpClient, request);
String allowValue = HttpLib.responseHeader(response, HttpNames.hAllow);
handleResponseNoBody(response);
return allowValue;
}
use of java.net.http.HttpRequest in project jena by apache.
the class HttpOp method httpGetString.
/**
* Perform an HTTP and return the body as a string. Return null for a "404 Not Found".
*/
public static String httpGetString(HttpClient httpClient, String url, String acceptHeader) {
HttpRequest request = newGetRequest(url, setAcceptHeader(acceptHeader));
HttpResponse<InputStream> response = execute(httpClient, request);
try {
return handleResponseRtnString(response);
} catch (HttpException ex) {
if (ex.getStatusCode() == HttpSC.NOT_FOUND_404)
return null;
throw ex;
}
}
use of java.net.http.HttpRequest in project jena by apache.
the class HttpOp method execPostForm.
private static TypedInputStream execPostForm(HttpClient httpClient, String url, Params params, String acceptString) {
Objects.requireNonNull(url);
acceptString = HttpLib.dft(acceptString, "*/*");
URI uri = toRequestURI(url);
String formData = params.httpString();
HttpRequest request = HttpLib.requestBuilderFor(url).uri(uri).POST(BodyPublishers.ofString(formData)).header(HttpNames.hContentType, WebContent.contentTypeHTMLForm).header(HttpNames.hAccept, acceptString).build();
HttpResponse<InputStream> response = execute(httpClient, request);
return handleResponseTypedInputStream(response);
}
Aggregations