use of java.net.http.HttpRequest in project jena by apache.
the class RDFParser method openTypedInputStream.
@SuppressWarnings("resource")
private TypedInputStream openTypedInputStream(String urlStr, Path path) {
// If path, use that.
if (path != null) {
try {
InputStream in = Files.newInputStream(path);
ContentType ct = RDFLanguages.guessContentType(urlStr);
return new TypedInputStream(in, ct);
} catch (NoSuchFileException | FileNotFoundException ex) {
throw new RiotNotFoundException();
} catch (IOException ex) {
IO.exception(ex);
}
}
TypedInputStream in;
// Need more control than LocatorURL provides to get the Accept header in and the HttpCLient.
// So map now.
urlStr = streamManager.mapURI(urlStr);
if (urlStr.startsWith("http://") || urlStr.startsWith("https://")) {
// HTTP
String acceptHeader = HttpLib.dft(appAcceptHeader, WebContent.defaultRDFAcceptHeader);
HttpRequest request = HttpLib.newGetRequest(urlStr, (b) -> {
if (httpHeaders != null)
httpHeaders.forEach(b::header);
b.setHeader(HttpNames.hAccept, acceptHeader);
});
HttpResponse<InputStream> response = HttpLib.execute(httpClient, request);
in = HttpLib.handleResponseTypedInputStream(response);
} else {
// Already mapped.
in = streamManager.openNoMapOrNull(urlStr);
}
if (in == null)
throw new RiotNotFoundException("Not found: " + urlStr);
return in;
}
use of java.net.http.HttpRequest in project jena by apache.
the class HttpRDF method httpDeleteGraph.
public static void httpDeleteGraph(HttpClient httpClient, String url) {
URI uri = toRequestURI(url);
HttpRequest requestData = HttpLib.requestBuilderFor(url).DELETE().uri(uri).build();
HttpResponse<InputStream> response = execute(httpClient, requestData);
handleResponseNoBody(response);
}
use of java.net.http.HttpRequest in project jena by apache.
the class AsyncHttpRDF method asyncGetToInput.
/**
* MUST consume or close the input stream
* @see HttpLib#finish(HttpResponse)
*/
private static CompletableFuture<HttpResponse<InputStream>> asyncGetToInput(HttpClient httpClient, String url, Consumer<HttpRequest.Builder> modifier) {
Objects.requireNonNull(httpClient);
Objects.requireNonNull(url);
HttpRequest requestData = HttpLib.newGetRequest(url, modifier);
return HttpLib.asyncExecute(httpClient, requestData);
}
use of java.net.http.HttpRequest in project jena by apache.
the class TestWebappMetrics method can_retrieve_metrics.
@Test
public void can_retrieve_metrics() {
String r = ServerCtl.urlRoot() + "$/metrics";
HttpRequest request = HttpRequest.newBuilder().uri(HttpLib.toRequestURI(r)).build();
HttpResponse<InputStream> response = HttpLib.executeJDK(HttpEnv.getDftHttpClient(), request, BodyHandlers.ofInputStream());
String body = handleResponseRtnString(response);
String ct = response.headers().firstValue(HttpNames.hContentType).orElse(null);
assertTrue(ct.contains(WebContent.contentTypeTextPlain));
assertTrue(ct.contains(WebContent.charsetUTF8));
assertTrue(body.contains("fuseki_requests_good"));
}
use of java.net.http.HttpRequest in project jena by apache.
the class ExFusekiMain_3_FusekiModule method main.
public static void main(String... a) throws Exception {
JenaSystem.init();
FusekiLogging.setLogging();
// Normally done with ServiceLoader
// A file /META-INF/services/org.apache.jena.fuseki.main.sys.FusekiModule
// in the jar file with contents:
// org.apache.jena.fuseki.main.examples.ExampleModule
//
// The file is typically put into the jar by having
// src/main/resources/META-INF/services/org.apache.jena.fuseki.main.sys.FusekiModule
FusekiModule module = new FMod_ProvidePATCH();
FusekiModules.add(module);
// Create server.
FusekiServer server = FusekiServer.create().port(0).build().start();
int port = server.getPort();
// Client HTTP request: "PATCH /extra"
HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://localhost:" + port + "/extra")).method("PATCH", BodyPublishers.ofString("hello world!")).build();
HttpResponse<Void> response = HttpEnv.getDftHttpClient().send(request, BodyHandlers.discarding());
server.stop();
}
Aggregations