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();
}
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations