Search in sources :

Example 41 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project indy by Commonjava.

the class IndyClientHttp method delete.

public void delete(final String path, final int... responseCodes) throws IndyClientException {
    connect();
    HttpDelete delete = null;
    CloseableHttpResponse response = null;
    CloseableHttpClient client = null;
    try {
        client = newClient();
        delete = newDelete(buildUrl(baseUrl, path));
        response = client.execute(delete, newContext());
        final StatusLine sl = response.getStatusLine();
        if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
            throw new IndyClientException(sl.getStatusCode(), "Error deleting: %s.\n%s", path, new IndyResponseErrorDetails(response));
        }
    } catch (final IOException e) {
        throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
    } finally {
        cleanupResources(delete, response, client);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException)

Example 42 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project stanbol by apache.

the class SessionTest method testCRUD.

@Test
public void testCRUD() throws Exception {
    RequestExecutor request;
    // The needed Web resources to GET from.
    executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", KRFormat.TURTLE)).assertStatus(200);
    log.info("Request: " + SESSION_URI + " ... DONE");
    String tempScopeUri = SESSION_URI + "/" + getClass().getCanonicalName() + "-" + System.currentTimeMillis();
    // Scope should not be there
    request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
    request.assertStatus(404);
    log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
    // Create scope
    executor.execute(builder.buildOtherRequest(new HttpPut(builder.buildUrl(tempScopeUri))));
    log.info("PUT Request: " + tempScopeUri + " ... DONE");
    // Scope should be there now
    request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
    request.assertStatus(200).assertContentContains(tempScopeUri);
    log.info("Request: " + tempScopeUri + " ... DONE");
    // TODO the U of CRUD
    // Delete scope
    executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl(tempScopeUri))));
    log.info("DELETE Request: " + tempScopeUri + " ... DONE");
    // Scope should not be there
    request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
    request.assertStatus(404);
    log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 43 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project stanbol by apache.

the class ScopeTest method testCRUD.

@Test
public void testCRUD() throws Exception {
    RequestExecutor request;
    // The needed Web resources to GET from.
    executor.execute(builder.buildGetRequest(BASE_SCOPES_URI).withHeader("Accept", KRFormat.TURTLE)).assertStatus(200);
    log.info("Request: " + BASE_SCOPES_URI + " ... DONE");
    String tempScopeUri = BASE_SCOPES_URI + "/" + getClass().getCanonicalName() + "-" + System.currentTimeMillis();
    // Scope should not be there
    request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
    request.assertStatus(404);
    log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
    // Create scope
    executor.execute(builder.buildOtherRequest(new HttpPut(builder.buildUrl(tempScopeUri))));
    log.info("PUT Request: " + tempScopeUri + " ... DONE");
    // Scope should be there now
    request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
    request.assertStatus(200).assertContentContains(tempScopeUri);
    log.info("Request: " + tempScopeUri + " ... DONE");
    // TODO the U of CRUD
    // Delete scope
    executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl(tempScopeUri))));
    log.info("DELETE Request: " + tempScopeUri + " ... DONE");
    // Scope should not be there
    request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
    request.assertStatus(404);
    log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 44 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project stanbol by apache.

the class EntityhubTest method testEntityDelete.

private void testEntityDelete() throws IOException {
    String stanbolProjectUri = "http://stanbol.apache.org";
    Request request = builder.buildOtherRequest(new HttpDelete(builder.buildUrl("/entityhub/entity", "id", stanbolProjectUri)));
    RequestExecutor re = executor.execute(request);
    re.assertStatus(200);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Request(org.apache.stanbol.commons.testing.http.Request) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor)

Example 45 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project stanbol by apache.

the class EntityhubTest method testQueries.

@Test
public void testQueries() throws IOException, JSONException {
    //first load the data for the rquery test
    URL url = EntityhubTest.class.getClassLoader().getResource("apache-project-doap-files.zip");
    Assert.assertNotNull(url);
    File f;
    try {
        f = new File(url.toURI());
    } catch (URISyntaxException e) {
        f = new File(url.getPath());
    }
    Assert.assertNotNull(f.isFile());
    ZipFile archive = new ZipFile(f);
    try {
        for (Enumeration<? extends ZipEntry> e = archive.entries(); e.hasMoreElements(); ) {
            ZipEntry entry = e.nextElement();
            log.debug(" - uploading {} to entityhub", entry);
            RequestExecutor re = executor.execute(buildImportRdfData(archive.getInputStream(entry), RDF_XML, false, null));
            //assert that the entity was created (or already existed)
            //some projects seams to have more than a single doap file
            int status = re.getResponse().getStatusLine().getStatusCode();
            Assert.assertTrue("Unable to add '" + entry.getName() + "'! Status:" + re.getResponse().getStatusLine(), status == 200 || status == 304);
        }
    } finally {
        archive.close();
    }
    testFindNameQuery();
    testFindWildcards();
    testFindLimitAndOffsetQuery();
    testFieldQueryTextConstraints();
    //finally delete all added entity
    RequestExecutor re = executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl("/entityhub/entity", "id", "*"))));
    re.assertStatus(200);
}
Also used : ZipFile(java.util.zip.ZipFile) HttpDelete(org.apache.http.client.methods.HttpDelete) ZipEntry(java.util.zip.ZipEntry) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) URISyntaxException(java.net.URISyntaxException) ZipFile(java.util.zip.ZipFile) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

HttpDelete (org.apache.http.client.methods.HttpDelete)108 HttpResponse (org.apache.http.HttpResponse)25 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)22 Test (org.junit.Test)21 HttpGet (org.apache.http.client.methods.HttpGet)16 HttpPut (org.apache.http.client.methods.HttpPut)16 HttpPost (org.apache.http.client.methods.HttpPost)15 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)14 IOException (java.io.IOException)12 Deployment (org.activiti.engine.test.Deployment)12 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)11 Task (org.activiti.engine.task.Task)9 StringEntity (org.apache.http.entity.StringEntity)9 URI (java.net.URI)7 RequestExecutor (org.apache.stanbol.commons.testing.http.RequestExecutor)7 URISyntaxException (java.net.URISyntaxException)6 Header (org.apache.http.Header)6 HttpEntity (org.apache.http.HttpEntity)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 User (org.activiti.engine.identity.User)5