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);
}
}
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);
}
}
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();
}
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);
}
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);
}
}
Aggregations