use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class sdbupdate method execOne.
private void execOne(String requestString, Dataset store) {
UpdateRequest req = UpdateFactory.create(requestString, Syntax.syntaxARQ);
UpdateExecutionFactory.create(req, store).execute();
}
use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class UpdateTest method runTestForReal.
@Override
protected void runTestForReal() {
try {
UpdateRequest request = UpdateFactory.read(updateFile, Syntax.syntaxSPARQL_11);
UpdateAction.execute(request, input);
boolean b = datasetSame(input, output, false);
if (!b) {
System.out.println("---- " + getName());
System.out.println("---- Got: ");
System.out.println(input.asDatasetGraph());
System.out.println("---- Expected");
System.out.println(output.asDatasetGraph());
datasetSame(input, output, true);
System.out.println("----------------------------------------");
}
assertTrue("Datasets are different", b);
} catch (RuntimeException ex) {
ex.printStackTrace(System.err);
throw ex;
}
}
use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class UpdateValidator method execute.
//static final String paramSyntaxExtended = "extendedSyntax" ;
@Override
protected void execute(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
try {
// if ( log.isInfoEnabled() )
// log.info("validation request") ;
String[] args = httpRequest.getParameterValues(paramUpdate);
if (args == null || args.length == 0) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "No update parameter to validator");
return;
}
if (args.length > 1) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Too many update parameters");
return;
}
final String updateString = httpRequest.getParameter(paramUpdate).replaceAll("(\r|\n| )*$", "");
String updateSyntax = httpRequest.getParameter(paramSyntax);
if (updateSyntax == null || updateSyntax.equals(""))
updateSyntax = "SPARQL";
Syntax language = Syntax.lookup(updateSyntax);
if (language == null) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown syntax: " + updateSyntax);
return;
}
String lineNumbersArg = httpRequest.getParameter(paramLineNumbers);
String[] a = httpRequest.getParameterValues(paramFormat);
// Currently default.
boolean outputSPARQL = true;
boolean lineNumbers = true;
if (lineNumbersArg != null)
lineNumbers = lineNumbersArg.equalsIgnoreCase("true") || lineNumbersArg.equalsIgnoreCase("yes");
// Headers
setHeaders(httpResponse);
ServletOutputStream outStream = httpResponse.getOutputStream();
outStream.println("<html>");
printHead(outStream, "SPARQL Update Validation Report");
outStream.println("<body>");
outStream.println("<h1>SPARQL Update Validator</h1>");
// Print as received
{
outStream.println("<p>Input:</p>");
// Not Java's finest hour.
Content c = new Content() {
@Override
public void print(IndentedWriter out) {
out.print(updateString);
}
};
output(outStream, c, lineNumbers);
}
// Attempt to parse it.
UpdateRequest request = null;
try {
request = UpdateFactory.create(updateString, "http://example/base/", language);
} catch (ARQException ex) {
// Over generous exception (should be QueryException)
// but this makes the code robust.
outStream.println("<p>Syntax error:</p>");
startFixed(outStream);
outStream.println(ex.getMessage());
finishFixed(outStream);
} catch (RuntimeException ex) {
outStream.println("<p>Internal error:</p>");
startFixed(outStream);
outStream.println(ex.getMessage());
finishFixed(outStream);
}
// Because we pass into anon inner classes
final UpdateRequest updateRequest = request;
// OK? Pretty print
if (updateRequest != null && outputSPARQL) {
outStream.println("<p>Formatted, parsed update request:</p>");
Content c = new Content() {
@Override
public void print(IndentedWriter out) {
updateRequest.output(out);
}
};
output(outStream, c, lineNumbers);
}
outStream.println("</body>");
outStream.println("</html>");
} catch (Exception ex) {
serviceLog.warn("Exception in doGet", ex);
}
}
use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class TestAuth method update_with_auth_11.
@Test
public void update_with_auth_11() {
UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
// Auth credentials for valid user with correct password scoped to correct URI
// Also using pre-emptive auth
BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
URI scope = URI.create(authServiceUpdate);
credsProv.setCredentials(new AuthScope(scope.getHost(), scope.getPort()), new UsernamePasswordCredentials("allowed", "password"));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost(scope.getHost()), basicAuth);
// Add AuthCache to the execution context
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProv);
context.setAuthCache(authCache);
HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
ue.setClient(client);
ue.setHttpContext(context);
ue.execute();
}
use of org.apache.jena.update.UpdateRequest 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();
}
}
Aggregations