Search in sources :

Example 26 with HttpRequest

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;
}
Also used : HttpRequest(java.net.http.HttpRequest) Context(org.apache.jena.sparql.util.Context) java.util(java.util) GZIPInputStream(java.util.zip.GZIPInputStream) IO(org.apache.jena.atlas.io.IO) BodyHandlers(java.net.http.HttpResponse.BodyHandlers) URISyntaxException(java.net.URISyntaxException) BodyPublishers(java.net.http.HttpRequest.BodyPublishers) InflaterInputStream(java.util.zip.InflaterInputStream) BodySubscribers(java.net.http.HttpResponse.BodySubscribers) BodyHandler(java.net.http.HttpResponse.BodyHandler) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) HttpNames(org.apache.jena.riot.web.HttpNames) HttpRequest(java.net.http.HttpRequest) Builder(java.net.http.HttpRequest.Builder) Duration(java.time.Duration) HttpClient(java.net.http.HttpClient) URI(java.net.URI) AuthLib(org.apache.jena.http.auth.AuthLib) HttpResponse(java.net.http.HttpResponse) RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) Params(org.apache.jena.sparql.exec.http.Params) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) HttpException(org.apache.jena.atlas.web.HttpException) BodyPublisher(java.net.http.HttpRequest.BodyPublisher) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) IRILib(org.apache.jena.atlas.lib.IRILib) HttpSC(org.apache.jena.web.HttpSC) AuthEnv(org.apache.jena.http.auth.AuthEnv) ARQ(org.apache.jena.query.ARQ) RegistryRequestModifier(org.apache.jena.http.sys.RegistryRequestModifier) InputStream(java.io.InputStream) Builder(java.net.http.HttpRequest.Builder)

Example 27 with HttpRequest

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;
}
Also used : HttpRequest(java.net.http.HttpRequest) InputStream(java.io.InputStream)

Example 28 with HttpRequest

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;
}
Also used : HttpRequest(java.net.http.HttpRequest) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) InputStream(java.io.InputStream)

Example 29 with HttpRequest

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;
    }
}
Also used : HttpRequest(java.net.http.HttpRequest) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) InputStream(java.io.InputStream) HttpException(org.apache.jena.atlas.web.HttpException)

Example 30 with HttpRequest

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);
}
Also used : HttpRequest(java.net.http.HttpRequest) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) InputStream(java.io.InputStream) URI(java.net.URI)

Aggregations

HttpRequest (java.net.http.HttpRequest)38 InputStream (java.io.InputStream)15 HttpClient (java.net.http.HttpClient)10 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)10 URI (java.net.URI)9 IOException (java.io.IOException)7 HttpResponse (java.net.http.HttpResponse)7 Duration (java.time.Duration)6 Test (org.junit.Test)5 HttpException (org.apache.jena.atlas.web.HttpException)4 SerializedClassRunner (io.pravega.test.common.SerializedClassRunner)3 TestUtils (io.pravega.test.common.TestUtils)3 URISyntaxException (java.net.URISyntaxException)3 Pattern (java.util.regex.Pattern)3 Cleanup (lombok.Cleanup)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 RunWith (org.junit.runner.RunWith)3 JsonParser (com.google.gson.JsonParser)2 Counter (io.pravega.shared.metrics.Counter)2 MetricsConfig (io.pravega.shared.metrics.MetricsConfig)2