Search in sources :

Example 1 with DataService

use of org.apache.jena.fuseki.server.DataService in project jena by apache.

the class TestEmbeddedFuseki method embedded_04.

@Test
public void embedded_04() {
    DatasetGraph dsg = dataset();
    Txn.executeWrite(dsg, () -> {
        Quad q = SSE.parseQuad("(_ :s :p _:b)");
        dsg.add(q);
    });
    // A service with just being able to do quads operations
    // That is, GET, POST, PUT on  "/data" in N-quads and TriG. 
    DataService dataService = new DataService(dsg);
    dataService.addEndpoint(OperationName.Quads_RW, "");
    dataService.addEndpoint(OperationName.Query, "");
    dataService.addEndpoint(OperationName.Update, "");
    int port = FusekiLib.choosePort();
    FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).add("/data", dataService).build();
    server.start();
    try {
        // Put data in.
        String data = "(graph (:s :p 1) (:s :p 2) (:s :p 3))";
        Graph g = SSE.parseGraph(data);
        HttpEntity e = graphToHttpEntity(g);
        HttpOp.execHttpPut("http://localhost:" + port + "/data", e);
        // Get data out.
        try (TypedInputStream in = HttpOp.execHttpGet("http://localhost:" + port + "/data")) {
            Graph g2 = GraphFactory.createDefaultGraph();
            RDFDataMgr.read(g2, in, RDFLanguages.contentTypeToLang(in.getContentType()));
            assertTrue(g.isIsomorphicWith(g2));
        }
        // Query.
        query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
            ResultSet rs = qExec.execSelect();
            int x = ResultSetFormatter.consume(rs);
            assertEquals(3, x);
        });
        // Update
        UpdateRequest req = UpdateFactory.create("CLEAR DEFAULT");
        UpdateExecutionFactory.createRemote(req, "http://localhost:" + port + "/data").execute();
        // Query again.
        query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
            ResultSet rs = qExec.execSelect();
            int x = ResultSetFormatter.consume(rs);
            assertEquals(0, x);
        });
    } finally {
        server.stop();
    }
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) HttpEntity(org.apache.http.HttpEntity) UpdateRequest(org.apache.jena.update.UpdateRequest) ResultSet(org.apache.jena.query.ResultSet) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DataService(org.apache.jena.fuseki.server.DataService) Test(org.junit.Test)

Example 2 with DataService

use of org.apache.jena.fuseki.server.DataService in project jena by apache.

the class TestEmbeddedFuseki method embedded_20.

@Test
public void embedded_20() {
    DatasetGraph dsg = dataset();
    int port = FusekiLib.choosePort();
    DataService dSrv = new DataService(dsg);
    dSrv.addEndpoint(OperationName.Query, "q");
    dSrv.addEndpoint(OperationName.GSP_R, "gsp");
    FusekiEmbeddedServer server = FusekiEmbeddedServer.create().add("/dsrv1", dSrv).setPort(port).build();
    server.start();
    try {
        query("http://localhost:" + port + "/dsrv1/q", "ASK{}", x -> {
        });
        String x1 = HttpOp.execHttpGetString("http://localhost:" + port + "/dsrv1/gsp");
        assertNotNull(x1);
    } finally {
        server.stop();
    }
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DataService(org.apache.jena.fuseki.server.DataService) Test(org.junit.Test)

Example 3 with DataService

use of org.apache.jena.fuseki.server.DataService in project jena by apache.

the class FusekiBuilder method buildDataService.

/** Build a DatasetRef starting at Resource svc */
private static DataService buildDataService(Resource svc, DatasetDescriptionRegistry dsDescMap) {
    if (log.isDebugEnabled())
        log.debug("Service: " + nodeLabel(svc));
    Resource datasetDesc = ((Resource) getOne(svc, "fu:dataset"));
    Dataset ds = getDataset(datasetDesc, dsDescMap);
    // In case the assembler included ja:contents
    DataService dataService = new DataService(ds.asDatasetGraph());
    addServiceEP(dataService, OperationName.Query, svc, pServiceQueryEP);
    addServiceEP(dataService, OperationName.Update, svc, pServiceUpdateEP);
    addServiceEP(dataService, OperationName.Upload, svc, pServiceUploadEP);
    addServiceEP(dataService, OperationName.GSP_R, svc, pServiceReadGraphStoreEP);
    addServiceEP(dataService, OperationName.GSP_RW, svc, pServiceReadWriteGraphStoreEP);
    addServiceEP(dataService, OperationName.Quads_R, svc, pServiceReadQuadsEP);
    addServiceEP(dataService, OperationName.Quads_RW, svc, pServiceReadWriteQuadsEP);
    // In the config file they are also implicit when using GSP.
    if (!dataService.getOperation(OperationName.GSP_RW).isEmpty() || !dataService.getOperation(OperationName.Quads_RW).isEmpty()) {
        dataService.addEndpoint(OperationName.Quads_RW, "");
    } else if (!dataService.getOperation(OperationName.GSP_R).isEmpty() || !dataService.getOperation(OperationName.Quads_R).isEmpty()) {
        dataService.addEndpoint(OperationName.Quads_R, "");
    }
    return dataService;
}
Also used : Dataset(org.apache.jena.query.Dataset) Resource(org.apache.jena.rdf.model.Resource) DataService(org.apache.jena.fuseki.server.DataService)

Example 4 with DataService

use of org.apache.jena.fuseki.server.DataService in project jena by apache.

the class FusekiBuilder method buildDataService.

/** Build a DataService starting at Resource svc */
public static DataService buildDataService(DatasetGraph dsg, boolean allowUpdate) {
    DataService dataService = new DataService(dsg);
    addServiceEP(dataService, OperationName.Query, "query");
    addServiceEP(dataService, OperationName.Query, "sparql");
    if (!allowUpdate) {
        addServiceEP(dataService, OperationName.GSP_R, "data");
        addServiceEP(dataService, OperationName.Quads_R, "");
        return dataService;
    }
    addServiceEP(dataService, OperationName.GSP_RW, "data");
    addServiceEP(dataService, OperationName.GSP_R, "get");
    addServiceEP(dataService, OperationName.Update, "update");
    addServiceEP(dataService, OperationName.Upload, "upload");
    addServiceEP(dataService, OperationName.Quads_RW, "");
    return dataService;
}
Also used : DataService(org.apache.jena.fuseki.server.DataService)

Example 5 with DataService

use of org.apache.jena.fuseki.server.DataService in project jena by apache.

the class FusekiBuilder method buildDataAccessPoint.

/** Build a DataAccessPoint, including DataService at Resource svc */
public static DataAccessPoint buildDataAccessPoint(Resource svc, DatasetDescriptionRegistry dsDescMap) {
    RDFNode n = FusekiLib.getOne(svc, "fu:name");
    if (!n.isLiteral())
        throw new FusekiConfigException("Not a literal for access point name: " + FmtUtils.stringForRDFNode(n));
    Literal object = n.asLiteral();
    if (object.getDatatype() != null && !object.getDatatype().equals(XSDDatatype.XSDstring))
        Fuseki.configLog.error(format("Service name '%s' is not a string", FmtUtils.stringForRDFNode(object)));
    String name = object.getLexicalForm();
    name = DataAccessPoint.canonical(name);
    DataService dataService = FusekiBuilder.buildDataService(svc, dsDescMap);
    DataAccessPoint dataAccess = new DataAccessPoint(name, dataService);
    return dataAccess;
}
Also used : FusekiConfigException(org.apache.jena.fuseki.FusekiConfigException) Literal(org.apache.jena.rdf.model.Literal) DataAccessPoint(org.apache.jena.fuseki.server.DataAccessPoint) RDFNode(org.apache.jena.rdf.model.RDFNode) DataService(org.apache.jena.fuseki.server.DataService)

Aggregations

DataService (org.apache.jena.fuseki.server.DataService)6 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)3 Test (org.junit.Test)3 HttpEntity (org.apache.http.HttpEntity)1 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)1 FusekiConfigException (org.apache.jena.fuseki.FusekiConfigException)1 DataAccessPoint (org.apache.jena.fuseki.server.DataAccessPoint)1 Graph (org.apache.jena.graph.Graph)1 Dataset (org.apache.jena.query.Dataset)1 ResultSet (org.apache.jena.query.ResultSet)1 Literal (org.apache.jena.rdf.model.Literal)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 Resource (org.apache.jena.rdf.model.Resource)1 Quad (org.apache.jena.sparql.core.Quad)1 UpdateRequest (org.apache.jena.update.UpdateRequest)1