Search in sources :

Example 11 with RDFLink

use of org.apache.jena.rdflink.RDFLink in project jena by apache.

the class TestService method service_query_bad_no_service.

@Test(expected = QueryExceptionHTTP.class)
public void service_query_bad_no_service() {
    DatasetGraph dsg = env.dsg();
    dsg.executeWrite(() -> dsg.add(SSE.parseQuad("(_ :s :p :o)")));
    // Not a service of the dataset.
    String queryString = "SELECT * { SERVICE <" + SERVICE + "/JUNK> { ?s ?p ?o }} ";
    // Connect to local, unused, permanently empty dataset
    try (RDFLink link = RDFLinkFactory.connect(localDataset())) {
        try (QueryExec qExec = link.query(queryString)) {
            RowSet rs = qExec.select();
            // Should go on execution.
            rs.hasNext();
            fail("Should not get here");
        }
    }
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) RowSet(org.apache.jena.sparql.exec.RowSet) RDFLink(org.apache.jena.rdflink.RDFLink) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 12 with RDFLink

use of org.apache.jena.rdflink.RDFLink in project jena by apache.

the class TestService method service_query_bad_3.

@Test(expected = QueryExceptionHTTP.class)
public void service_query_bad_3() {
    DatasetGraph dsg = env.dsg();
    dsg.executeWrite(() -> dsg.add(SSE.parseQuad("(_ :s :p :o)")));
    // Not a dataset of the server
    String queryString = "SELECT * { SERVICE <http://nosuchsite/> { ?s ?p ?o }} ";
    // Connect to local, unused, permanently empty dataset
    try (RDFLink link = RDFLinkFactory.connect(localDataset())) {
        try (QueryExec qExec = link.query(queryString)) {
            // Where it should go wrong.
            RowSet rs = qExec.select();
            // Should go on execution.
            rs.hasNext();
            fail("Should not get here");
        }
    }
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) RowSet(org.apache.jena.sparql.exec.RowSet) RDFLink(org.apache.jena.rdflink.RDFLink) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 13 with RDFLink

use of org.apache.jena.rdflink.RDFLink in project jena by apache.

the class TestSetupHTTP method setup_RDFLink.

@Test
public void setup_RDFLink() {
    try (RDFLink link = RDFLinkHTTP.service(URL).httpClient(httpClient).acceptHeaderGraph("application/rdf+xml").acceptHeaderDataset("application/n-quads").quadsFormat(Lang.NQ).triplesFormat(Lang.RDFXML).build()) {
        link.load(g);
        link.get();
        link.loadDataset(dsg);
        link.getDataset();
    }
}
Also used : RDFLink(org.apache.jena.rdflink.RDFLink) Test(org.junit.Test)

Example 14 with RDFLink

use of org.apache.jena.rdflink.RDFLink in project jena by apache.

the class ExModification01 method exampleMod.

private static void exampleMod() {
    AtomicLong counter = new AtomicLong(0);
    HttpRequestModifier modifier = (params, headers) -> {
        long x = counter.incrementAndGet();
        headers.put("X-Tracker", "Call=" + x);
    };
    RegistryRequestModifier.get().addPrefix(serverURL, modifier);
    // RegistryRequestModifier.get().add(dataURL, modifier);
    // GSP : NO MODIFICATION no call to modifyByService
    // GSP : calls HttpRDF
    // Pass in request or at least request type.
    /*
org.apache.jena.http.sys.RegistryRequestModifier.get()
auth.examples.ExModification01.exampleMod()

org.apache.jena.http.HttpLib.modifyByService(String, Context, Params, Map<String, String>)
  org.apache.jena.sparql.exec.http.UpdateExecHTTP.execute()
  org.apache.jena.sparql.exec.http.QueryExecHTTP.query(String)
  ==> SERVICE via QueryExecHTTP
  ==> GSP ?

org.apache.jena.sparql.exec.http.TestService.runWithModifier(String, HttpRequestModifier, Runnable)

         */
    GSP.service(dataURL).defaultGraph().GET();
    try (RDFLink link = RDFLinkHTTP.service(dataURL).build()) {
        boolean b = link.queryAsk("ASK{}");
    }
}
Also used : GSP(org.apache.jena.sparql.exec.http.GSP) AtomicLong(java.util.concurrent.atomic.AtomicLong) DatasetGraphFactory(org.apache.jena.sparql.core.DatasetGraphFactory) RDFLinkHTTP(org.apache.jena.rdflink.RDFLinkHTTP) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) FusekiLogging(org.apache.jena.fuseki.system.FusekiLogging) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) RDFLink(org.apache.jena.rdflink.RDFLink) RegistryRequestModifier(org.apache.jena.http.sys.RegistryRequestModifier) AtomicLong(java.util.concurrent.atomic.AtomicLong) RDFLink(org.apache.jena.rdflink.RDFLink) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier)

Aggregations

RDFLink (org.apache.jena.rdflink.RDFLink)14 Test (org.junit.Test)13 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)12 EnvTest (org.apache.jena.test.conn.EnvTest)12 QueryExec (org.apache.jena.sparql.exec.QueryExec)8 RowSet (org.apache.jena.sparql.exec.RowSet)7 HttpRequestModifier (org.apache.jena.http.sys.HttpRequestModifier)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Graph (org.apache.jena.graph.Graph)2 RegistryRequestModifier (org.apache.jena.http.sys.RegistryRequestModifier)2 RDFLinkHTTP (org.apache.jena.rdflink.RDFLinkHTTP)2 DatasetGraphFactory (org.apache.jena.sparql.core.DatasetGraphFactory)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2 GSP (org.apache.jena.sparql.exec.http.GSP)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 FusekiServer (org.apache.jena.fuseki.main.FusekiServer)1 FusekiLogging (org.apache.jena.fuseki.system.FusekiLogging)1 HttpTest.expect401 (org.apache.jena.fuseki.test.HttpTest.expect401)1 Triple (org.apache.jena.graph.Triple)1 ARQ (org.apache.jena.query.ARQ)1