Search in sources :

Example 36 with HttpDelete

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

the class RFC4918IfHeaderTest method testPutIfEtag.

public void testPutIfEtag() throws IOException, DavException, URISyntaxException {
    String testuri = this.root + "iftest";
    try {
        HttpPut put = new HttpPut(testuri);
        String condition = "<" + testuri + "> ([" + "\"an-etag-this-testcase-invented\"" + "])";
        put.setEntity(new StringEntity("1"));
        put.setHeader("If", condition);
        int status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals("status: " + status, 412, status);
    } finally {
        HttpDelete delete = new HttpDelete(testuri);
        int status = this.client.execute(delete, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204 || status == 404);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpPut(org.apache.http.client.methods.HttpPut)

Example 37 with HttpDelete

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

the class RFC4918IfHeaderTest method testPutIfLockToken.

public void testPutIfLockToken() throws IOException, DavException, URISyntaxException {
    String testuri = this.root + "iflocktest";
    String locktoken = null;
    try {
        HttpPut put = new HttpPut(testuri);
        put.setEntity(new StringEntity("1"));
        int status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 201 || status == 204);
        HttpLock lock = new HttpLock(testuri, new LockInfo(Scope.EXCLUSIVE, Type.WRITE, "testcase", 10000, true));
        HttpResponse response = this.client.execute(lock, this.context);
        status = response.getStatusLine().getStatusCode();
        assertEquals("status", 200, status);
        locktoken = lock.getLockToken(response);
        assertNotNull(locktoken);
        System.out.println(locktoken);
        System.out.println(response.getFirstHeader("lock-token").getValue());
        // try to overwrite without lock token
        put = new HttpPut(testuri);
        put.setEntity(new StringEntity("2"));
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals("status: " + status, 423, status);
        // try to overwrite using bad lock token
        put = new HttpPut(testuri);
        put.setEntity(new StringEntity("2"));
        put.setHeader("If", "(<" + "DAV:foobar" + ">)");
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals("status: " + status, 412, status);
        // try to overwrite using correct lock token, using  No-Tag-list format
        put = new HttpPut(testuri);
        put.setEntity(new StringEntity("2"));
        put.setHeader("If", "(<" + locktoken + ">)");
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204);
        // try to overwrite using correct lock token, using Tagged-list format
        // and full URI
        put = new HttpPut(testuri);
        put.setEntity(new StringEntity("3"));
        put.setHeader("If", "<" + testuri + ">" + "(<" + locktoken + ">)");
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204);
        // try to overwrite using correct lock token, using Tagged-list format
        // and absolute path only
        put = new HttpPut(testuri);
        put.setEntity(new StringEntity("4"));
        put.setHeader("If", "<" + new URI(testuri).getRawPath() + ">" + "(<" + locktoken + ">)");
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204);
        // try to overwrite using correct lock token, using Tagged-list format
        // and bad path
        put = new HttpPut(testuri);
        put.setEntity(new StringEntity("5"));
        put.setHeader("If", "</foobar>" + "(<" + locktoken + ">)");
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 404 || status == 412);
    } finally {
        HttpDelete delete = new HttpDelete(testuri);
        if (locktoken != null) {
            delete.setHeader("If", "(<" + locktoken + ">)");
        }
        int status = this.client.execute(delete, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204 || status == 404);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) HttpLock(org.apache.jackrabbit.webdav.client.methods.HttpLock) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut)

Example 38 with HttpDelete

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

the class BrocadeVcsApi method executeDeleteObject.

protected void executeDeleteObject(String uri) throws BrocadeVcsApiException {
    if (_host == null || _host.isEmpty() || _adminuser == null || _adminuser.isEmpty() || _adminpass == null || _adminpass.isEmpty()) {
        throw new BrocadeVcsApiException("Hostname/credentials are null or empty");
    }
    final HttpDelete dm = (HttpDelete) createMethod("delete", uri);
    dm.setHeader("Accept", "application/vnd.configuration.resource+xml");
    final HttpResponse response = executeMethod(dm);
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) {
        String errorMessage;
        try {
            errorMessage = responseToErrorMessage(response);
        } catch (final IOException e) {
            s_logger.error("Failed to delete object : " + e.getMessage());
            throw new BrocadeVcsApiException("Failed to delete object : " + e.getMessage());
        }
        dm.releaseConnection();
        s_logger.error("Failed to delete object : " + errorMessage);
        throw new BrocadeVcsApiException("Failed to delete object : " + errorMessage);
    }
    dm.releaseConnection();
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 39 with HttpDelete

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

the class GatewayFastTestsSuite method doDelete.

public static HttpResponse doDelete(String resource) throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpDelete delete = new HttpDelete(GatewayTestBase.getEndPoint(resource));
    delete.setHeader(AUTH_HEADER);
    return client.execute(delete);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 40 with HttpDelete

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

the class IndyClientHttp method deleteWithChangelog.

public void deleteWithChangelog(final String path, final String changelog, final int... responseCodes) throws IndyClientException {
    connect();
    HttpDelete delete = null;
    CloseableHttpResponse response = null;
    CloseableHttpClient client = null;
    try {
        client = newClient();
        delete = newDelete(buildUrl(baseUrl, path));
        delete.setHeader(ArtifactStore.METADATA_CHANGELOG, changelog);
        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)

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