use of java.net.http.HttpRequest.Builder in project jena by apache.
the class HttpLib method httpPushWithResponse.
// Worker
/*package*/
static HttpResponse<InputStream> httpPushWithResponse(HttpClient httpClient, Push style, String url, Consumer<HttpRequest.Builder> modifier, BodyPublisher body) {
URI uri = toRequestURI(url);
HttpRequest.Builder builder = requestBuilderFor(url);
builder.uri(uri);
builder.method(style.method(), body);
if (modifier != null)
modifier.accept(builder);
HttpResponse<InputStream> response = execute(httpClient, builder.build());
return response;
}
use of java.net.http.HttpRequest.Builder in project feign by OpenFeign.
the class Http2Client method newRequestBuilder.
private Builder newRequestBuilder(Request request, Options options) throws URISyntaxException {
URI uri = new URI(request.url());
final BodyPublisher body;
final byte[] data = request.body();
if (data == null) {
body = BodyPublishers.noBody();
} else {
body = BodyPublishers.ofByteArray(data);
}
final Builder requestBuilder = HttpRequest.newBuilder().uri(uri).timeout(Duration.ofMillis(options.readTimeoutMillis())).version(client.version());
final Map<String, Collection<String>> headers = filterRestrictedHeaders(request.headers());
if (!headers.isEmpty()) {
requestBuilder.headers(asString(headers));
}
switch(request.httpMethod()) {
case GET:
return requestBuilder.GET();
case POST:
return requestBuilder.POST(body);
case PUT:
return requestBuilder.PUT(body);
case DELETE:
return requestBuilder.DELETE();
default:
// fall back scenario, http implementations may restrict some methods
return requestBuilder.method(request.httpMethod().toString(), body);
}
}
use of java.net.http.HttpRequest.Builder in project jena by apache.
the class HttpLib method 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.
*/
public static boolean isFuseki(String datasetURL) {
HttpRequest.Builder builder = HttpRequest.newBuilder().uri(toRequestURI(datasetURL)).method(HttpNames.METHOD_HEAD, BodyPublishers.noBody());
HttpRequest request = builder.build();
HttpClient httpClient = HttpEnv.getDftHttpClient();
HttpResponse<InputStream> response = execute(httpClient, request);
handleResponseNoBody(response);
Optional<String> value1 = response.headers().firstValue(FusekiRequestIdHeader);
if (value1.isPresent())
return true;
Optional<String> value2 = response.headers().firstValue("Server");
if (value2.isEmpty())
return false;
String headerValue = value2.get();
boolean isFuseki = headerValue.startsWith("Apache Jena Fuseki") || headerValue.toLowerCase().contains("fuseki");
return isFuseki;
}
use of java.net.http.HttpRequest.Builder in project jena by apache.
the class HttpLib method requestBuilder.
public static Builder requestBuilder(String url, Map<String, String> httpHeaders, long readTimeout, TimeUnit readTimeoutUnit) {
HttpRequest.Builder builder = HttpLib.requestBuilderFor(url);
headers(builder, httpHeaders);
builder.uri(toRequestURI(url));
if (readTimeout >= 0)
builder.timeout(Duration.ofMillis(readTimeoutUnit.toMillis(readTimeout)));
return builder;
}
use of java.net.http.HttpRequest.Builder 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;
}
Aggregations