Search in sources :

Example 36 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestAuth method update_with_auth_09.

@Test(expected = HttpException.class)
public void update_with_auth_09() throws URISyntaxException {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
    // Auth credentials for valid user with correct password but scoped to
    // wrong URI
    ue.setClient(withBasicAuth(new AuthScope("example", authPort), "allowed", "password"));
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) AuthScope(org.apache.http.auth.AuthScope) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 37 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestAuth method update_with_auth_05.

@Test(expected = HttpException.class)
public void update_with_auth_05() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(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 38 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestAuth method update_with_auth_04.

@Test(expected = HttpException.class)
public void update_with_auth_04() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
    // Auth credentials for valid user with correct password BUT not in
    // correct role
    ue.setClient(withBasicAuth(ANY, "forbidden", "password"));
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 39 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class SPARQL_Update method execute.

private void execute(HttpAction action, InputStream input) {
    // OPTIONS
    if (action.request.getMethod().equals(HttpNames.METHOD_OPTIONS)) {
        // Share with update via SPARQL_Protocol.
        doOptions(action);
        return;
    }
    UsingList usingList = processProtocol(action.request);
    // If the dsg is transactional, then we can parse and execute the update in a streaming fashion.
    // If it isn't, we need to read the entire update request before performing any updates, because
    // we have to attempt to make the request atomic in the face of malformed updates
    UpdateRequest req = null;
    if (!action.isTransactional()) {
        try {
            req = UpdateFactory.read(usingList, input, UpdateParseBase, Syntax.syntaxARQ);
        } catch (UpdateException ex) {
            ServletOps.errorBadRequest(ex.getMessage());
            return;
        } catch (QueryParseException ex) {
            ServletOps.errorBadRequest(messageForQueryException(ex));
            return;
        }
    }
    action.beginWrite();
    try {
        if (req == null)
            UpdateAction.parseExecute(usingList, action.getActiveDSG(), input, UpdateParseBase, Syntax.syntaxARQ);
        else
            UpdateAction.execute(req, action.getActiveDSG());
        action.commit();
    } catch (UpdateException ex) {
        action.abort();
        incCounter(action.getEndpoint().getCounters(), UpdateExecErrors);
        ServletOps.errorOccurred(ex.getMessage());
    } catch (QueryParseException | QueryBuildException ex) {
        action.abort();
        // Counter inc'ed further out.
        ServletOps.errorBadRequest(messageForQueryException(ex));
    } catch (Throwable ex) {
        if (!(ex instanceof ActionErrorException)) {
            try {
                action.abort();
            } catch (Exception ex2) {
            }
            ServletOps.errorOccurred(ex.getMessage(), ex);
        }
    } finally {
        action.endWrite();
    }
}
Also used : UsingList(org.apache.jena.sparql.modify.UsingList) UpdateRequest(org.apache.jena.update.UpdateRequest) QueryBuildException(org.apache.jena.query.QueryBuildException) UpdateException(org.apache.jena.update.UpdateException) ServletException(javax.servlet.ServletException) QueryParseException(org.apache.jena.query.QueryParseException) QueryBuildException(org.apache.jena.query.QueryBuildException) IOException(java.io.IOException) UpdateException(org.apache.jena.update.UpdateException) QueryParseException(org.apache.jena.query.QueryParseException)

Example 40 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class ExTDB_Txn2 method execUpdate.

public static void execUpdate(String sparqlUpdateString, GraphStore graphStore) {
    UpdateRequest request = UpdateFactory.create(sparqlUpdateString);
    UpdateProcessor proc = UpdateExecutionFactory.create(request, graphStore);
    proc.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessor(org.apache.jena.update.UpdateProcessor)

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