Search in sources :

Example 6 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class DSP method GET.

/**
 * GET dataset.
 * <p>
 * If the remote end is a graph, the result is a dataset with that
 * graph data in the default graph of the dataset.
 */
public DatasetGraph GET() {
    ensureAcceptHeader(WebContent.defaultRDFAcceptHeader);
    DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
    HttpClient hc = requestHttpClient(serviceEndpoint, serviceEndpoint);
    HttpRDF.httpGetToStream(hc, serviceEndpoint, httpHeaders, StreamRDFLib.dataset(dsg));
    return dsg;
}
Also used : HttpClient(java.net.http.HttpClient) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 7 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class DSP method PUT.

/**
 * PUT a dataset
 */
public void PUT(DatasetGraph dataset) {
    RDFFormat requestFmt = rdfFormat(HttpEnv.defaultQuadsFormat);
    HttpClient hc = requestHttpClient(serviceEndpoint, serviceEndpoint);
    HttpRDF.httpPutDataset(hc, serviceEndpoint, dataset, requestFmt, httpHeaders);
}
Also used : HttpClient(java.net.http.HttpClient) RDFFormat(org.apache.jena.riot.RDFFormat)

Example 8 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class RDFParserBuilder method build.

/**
 * Build an {@link RDFParser}. The parser takes it's configuration from this builder and can not then be changed.
 * The source must be set.
 * When a parser is used, it is takes the source and sends output to an {@link StreamRDF}.
 * <p>
 * Shortcuts:
 * <ul>
 * <li>{@link #parse(DatasetGraph)} - parse the source and output to a {@code DatasetGraph}
 * <li>{@link #parse(Graph)} - parse the source and output to a {@code Graph}
 * <li>{@link #parse(StreamRDF)} - parse the source and output to a {@code StreamRDF}
 * </ul>
 *
 * @return RDFParser
 */
public RDFParser build() {
    // Build what we can now - some things have to be built in the parser.
    if (uri == null && path == null && stringToParse == null && inputStream == null && javaReader == null)
        throw new RiotException("No source specified");
    Context context = contextAcc.context();
    // Setup the HTTP client.
    HttpClient clientJDK = (httpClient != null) ? httpClient : HttpEnv.getDftHttpClient();
    FactoryRDF factory$ = buildFactoryRDF();
    ErrorHandler errorHandler$ = errorHandler;
    if (errorHandler$ == null)
        errorHandler$ = ErrorHandlerFactory.getDefaultErrorHandler();
    // Select base for the parser.
    // The order is baseURI > path > uri.
    // baseURI or uri may be a filename or relative and need converting to a URI.
    String parserBaseURI;
    if (baseURI != null)
        parserBaseURI = IRIs.toBase(baseURI);
    else if (path != null)
        parserBaseURI = IRILib.filenameToIRI(path.toString());
    else if (uri != null)
        parserBaseURI = IRIs.toBase(uri);
    else
        parserBaseURI = null;
    StreamManager sMgr = streamManager;
    if (sMgr == null)
        sMgr = StreamManager.get(context);
    // Can't build the profile here as it is Lang/conneg dependent.
    return new RDFParser(uri, path, stringToParse, inputStream, javaReader, sMgr, appAcceptHeader, httpHeaders, clientJDK, hintLang, forceLang, parserBaseURI, strict, checking, canonicalValues, langTagForm, resolveURIs, resolver, factory$, errorHandler$, context);
}
Also used : Context(org.apache.jena.sparql.util.Context) StreamManager(org.apache.jena.riot.system.stream.StreamManager) HttpClient(java.net.http.HttpClient)

Example 9 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class GSP method POST.

// /**
// * Get a graph.
// * <p>
// * Synonym for {@link #GET()}.
// */
// public Graph getGraph() {
// // Synonym
// return GET();
// }
/**
 * POST the contents of a file using the filename extension to determine the
 * Content-Type to use if it is not already set.
 * <p>
 * This operation does not parse the file.
 */
public void POST(String file) {
    validateGraphOperation();
    String url = graphRequestURL();
    String fileExtContentType = contentTypeFromFilename(file);
    HttpClient hc = requestHttpClient(serviceEndpoint, url);
    uploadTriples(hc, url, file, fileExtContentType, httpHeaders, Push.POST);
}
Also used : HttpClient(java.net.http.HttpClient)

Example 10 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class GSP method GET.

// Synonyms mirror the dataset names, so getGraph/getDataset
/**
 * Get a graph
 */
public Graph GET() {
    validateGraphOperation();
    ensureAcceptHeader(WebContent.defaultGraphAcceptHeader);
    String url = graphRequestURL();
    Graph graph = GraphFactory.createDefaultGraph();
    HttpClient hc = requestHttpClient(serviceEndpoint, url);
    HttpRDF.httpGetToStream(hc, url, httpHeaders, StreamRDFLib.graph(graph));
    return graph;
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) HttpClient(java.net.http.HttpClient)

Aggregations

HttpClient (java.net.http.HttpClient)42 Authenticator (java.net.Authenticator)11 HttpRequest (java.net.http.HttpRequest)8 HttpResponse (java.net.http.HttpResponse)6 URI (java.net.URI)4 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)4 RDFFormat (org.apache.jena.riot.RDFFormat)4 Context (org.apache.jena.sparql.util.Context)4 SerializedClassRunner (io.pravega.test.common.SerializedClassRunner)3 TestUtils (io.pravega.test.common.TestUtils)3 URISyntaxException (java.net.URISyntaxException)3 Duration (java.time.Duration)3 Pattern (java.util.regex.Pattern)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 Cleanup (lombok.Cleanup)3 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 Counter (io.pravega.shared.metrics.Counter)2