Search in sources :

Example 6 with UpdateExecution

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

the class ExAuth03_UpdateExecutionPW method exampleUpdateAuth.

public static void exampleUpdateAuth() {
    System.out.println();
    UpdateExecution uExec1 = UpdateExecutionHTTP.service(dataURL).update("INSERT DATA{}").build();
    try {
        // Expect failed because there is no authentication credentials.
        System.out.println("Update/no auth");
        uExec1.execute();
    } catch (HttpException ex) {
        System.out.println("Failed: " + ex.getMessage());
    }
    System.out.println("Register user/password + UpdateExecution");
    AuthEnv.get().registerUsernamePassword(URI.create(dataURL), "u", "p");
    UpdateExecution uExec3 = UpdateExecutionHTTP.service(dataURL).update("INSERT DATA{}").build();
    // Expect success because there will be a challenge and Jena will resend with the auth information.
    uExec3.execute();
    AuthEnv.get().clearActiveAuthentication();
}
Also used : UpdateExecution(org.apache.jena.update.UpdateExecution) HttpException(org.apache.jena.atlas.web.HttpException)

Example 7 with UpdateExecution

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

the class TestAuthUpdate_JDK method update_jdk_auth_02.

@Test
public void update_jdk_auth_02() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateExecution ue = withAuthJDK(UpdateExecutionHTTP.create().endpoint(databaseURL()).update(updates), "allowed", "bad-password");
    expect401(() -> ue.execute());
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateExecution(org.apache.jena.update.UpdateExecution) Test(org.junit.Test)

Example 8 with UpdateExecution

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

the class TestAuthUpdate_JDK method update_jdk_auth_01.

@Test
public void update_jdk_auth_01() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateExecution ue = UpdateExecutionHTTP.create().endpoint(databaseURL()).update(updates).build();
    // No auth credentials should result in an error
    expect401(() -> ue.execute());
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateExecution(org.apache.jena.update.UpdateExecution) Test(org.junit.Test)

Example 9 with UpdateExecution

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

the class TestAuthUpdate_JDK method update_jdk_auth_03.

@Test
public void update_jdk_auth_03() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateExecution ue = withAuthJDK(UpdateExecutionHTTP.create().endpoint(databaseURL()).update(updates), "allowed", "password");
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateExecution(org.apache.jena.update.UpdateExecution) Test(org.junit.Test)

Example 10 with UpdateExecution

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

the class AbstractTestRDFConnection method update_05.

@Test
public void update_05() {
    UpdateRequest update = new UpdateRequest();
    update.add("INSERT DATA { <urn:ex:s> <urn:ex:p> <urn:ex:o>}");
    try (RDFConnection conn = connection()) {
        UpdateExecutionBuilder updateBuilder = conn.newUpdate();
        UpdateExecution uExec = updateBuilder.update(update).build();
        Txn.executeWrite(conn, () -> uExec.execute());
    }
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateExecutionBuilder(org.apache.jena.update.UpdateExecutionBuilder) UpdateExecution(org.apache.jena.update.UpdateExecution) Test(org.junit.Test)

Aggregations

UpdateExecution (org.apache.jena.update.UpdateExecution)10 UpdateRequest (org.apache.jena.update.UpdateRequest)9 Test (org.junit.Test)7 URI (java.net.URI)1 HttpException (org.apache.jena.atlas.web.HttpException)1 UpdateExecutionBuilder (org.apache.jena.update.UpdateExecutionBuilder)1