Search in sources :

Example 66 with UpdateRequest

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();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 67 with UpdateRequest

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);
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) UpdateRequest(org.apache.jena.update.UpdateRequest) ARQException(org.apache.jena.sparql.ARQException) Syntax(org.apache.jena.query.Syntax) ARQException(org.apache.jena.sparql.ARQException)

Example 68 with UpdateRequest

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();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 69 with UpdateRequest

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();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 70 with UpdateRequest

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();
    }
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) CmdException(jena.cmd.CmdException) UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateLoad(org.apache.jena.sparql.modify.request.UpdateLoad) Node(org.apache.jena.graph.Node)

Aggregations

UpdateRequest (org.apache.jena.update.UpdateRequest)71 Test (org.junit.Test)46 UpdateProcessRemoteBase (org.apache.jena.sparql.modify.UpdateProcessRemoteBase)13 UpdateProcessor (org.apache.jena.update.UpdateProcessor)7 Node (org.apache.jena.graph.Node)6 RDFNode (org.apache.jena.rdf.model.RDFNode)5 HashMap (java.util.HashMap)4 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)4 Resource (org.apache.jena.rdf.model.Resource)4 AuthScope (org.apache.http.auth.AuthScope)3 Dataset (org.apache.jena.query.Dataset)3 QueryParseException (org.apache.jena.query.QueryParseException)3 Model (org.apache.jena.rdf.model.Model)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 Map (java.util.Map)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 CmdException (jena.cmd.CmdException)2 HttpClient (org.apache.http.client.HttpClient)2