use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class TestAuth method update_with_auth_01.
@Test(expected = HttpException.class)
public void update_with_auth_01() {
UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
// No auth credentials should result in an error
ue.execute();
}
use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class UpdateValidatorHTML method executeHTML.
//static final String paramSyntaxExtended = "extendedSyntax" ;
public static void executeHTML(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
try {
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>");
output(outStream, (out) -> out.print(updateString), 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>");
output(outStream, (out) -> updateRequest.output(out), 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_07.
@Test
public void update_with_auth_07() {
UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate);
// Auth credentials for valid user with correct password
ue.setClient(withBasicAuth(ANY, "allowed", "password"));
ue.execute();
}
use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class TestAuth method update_with_auth_03.
@Test
public void update_with_auth_03() {
UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
// Auth credentials for valid user with correct password
ue.setClient(withBasicAuth(ANY, "allowed", "password"));
ue.execute();
}
use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class load method execUpdate.
@Override
protected void execUpdate(DatasetGraph graphStore) {
if (loadFiles.size() == 0)
throw new CmdException("Nothing to do");
UpdateRequest req = new UpdateRequest();
for (String filename : loadFiles) {
UpdateLoad loadReq = new UpdateLoad(filename, graphName);
req.add(loadReq);
}
if (true) {
// Need a better way
monitor(graphStore.getDefaultGraph());
for (Iterator<Node> iter = graphStore.listGraphNodes(); iter.hasNext(); ) {
Graph g = graphStore.getGraph(iter.next());
monitor(g);
}
}
UpdateExecutionFactory.create(req, graphStore).execute();
if (dump) {
IndentedWriter out = IndentedWriter.stdout;
SSE.write(graphStore);
out.flush();
}
}
Aggregations