use of org.apache.http.client.methods.HttpDelete in project OpenAttestation by OpenAttestation.
the class ApacheHttpClient method delete.
public ApiResponse delete(String requestURL) throws IOException, SignatureException {
log.debug("DELETE url: {}", requestURL);
HttpDelete request = new HttpDelete(requestURL);
// send the request and print the response
HttpResponse httpResponse = httpClient.execute(request);
ApiResponse apiResponse = readResponse(httpResponse);
request.releaseConnection();
return apiResponse;
}
use of org.apache.http.client.methods.HttpDelete in project tdi-studio-se by Talend.
the class DynamicsCRMClient method createAndExecuteRequest.
/**
* Created and executes a request
*
* @param uri the request URI
* @param httpEntity the entity to send.
* @param method HTTP method
*
* @return the response to the request.
* @throws ServiceUnavailableException
*/
protected HttpResponse createAndExecuteRequest(URI uri, HttpEntity httpEntity, HttpMethod method) throws ServiceUnavailableException {
boolean hasRetried = false;
while (true) {
try {
httpClient = (DefaultHttpClient) httpClientFactory.create(null, null);
HttpRequestBase request = null;
if (method == HttpMethod.POST) {
request = new HttpPost(uri);
} else if (method == HttpMethod.PATCH) {
request = new HttpPatch(uri);
} else if (method == HttpMethod.DELETE) {
request = new HttpDelete(uri);
} else {
throw new HttpClientException("Unsupported operation:" + method);
}
request.addHeader(HttpHeader.AUTHORIZATION, "Bearer " + authResult.getAccessToken());
if (request instanceof HttpEntityEnclosingRequestBase) {
((HttpEntityEnclosingRequestBase) request).setEntity(httpEntity);
}
HttpResponse response = httpClient.execute(request);
if (isResponseSuccess(response.getStatusLine().getStatusCode())) {
request.releaseConnection();
EntityUtils.consume(response.getEntity());
return response;
} else {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED && !hasRetried) {
refreshToken();
hasRetried = true;
continue;
}
HttpEntity entity = response.getEntity();
String message = null;
if (entity != null) {
message = odataClient.getDeserializer(ContentType.JSON).toError(entity.getContent()).getMessage();
} else {
message = response.getStatusLine().getReasonPhrase();
}
throw new HttpClientException(message);
}
} catch (Exception e) {
throw new HttpClientException(e);
}
}
}
use of org.apache.http.client.methods.HttpDelete in project intellij-community by JetBrains.
the class CCStepicConnector method deleteTask.
public static void deleteTask(@NotNull final Integer task) {
final HttpDelete request = new HttpDelete(EduStepicNames.STEPIC_API_URL + EduStepicNames.STEP_SOURCES + task);
ApplicationManager.getApplication().invokeLater(() -> {
try {
final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
if (client == null)
return;
final CloseableHttpResponse response = client.execute(request);
final HttpEntity responseEntity = response.getEntity();
final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
EntityUtils.consume(responseEntity);
final StatusLine line = response.getStatusLine();
if (line.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
LOG.error("Failed to delete task " + responseString);
}
} catch (IOException e) {
LOG.error(e.getMessage());
}
});
}
use of org.apache.http.client.methods.HttpDelete in project Activiti by Activiti.
the class TaskIdentityLinkResourceTest method testDeleteSingleIdentityLink.
/**
* Test deleting a single identity link for a task.
* DELETE runtime/tasks/{taskId}/identitylinks/{family}/{identityId}/{type}
*/
public void testDeleteSingleIdentityLink() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
taskService.addUserIdentityLink(task.getId(), "kermit", "myType");
HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINK, task.getId(), "users", "kermit", "myType"));
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
// Test with unexisting identitylink
httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINK, task.getId(), RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS, "kermit", "unexistingtype"));
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND));
// Test with unexisting task
httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINK, "unexistingtask", RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS, "kermit", "myType"));
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND));
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
}
}
use of org.apache.http.client.methods.HttpDelete in project Activiti by Activiti.
the class TaskResourceTest method testDeleteTask.
/**
* Test deleting a single task.
* DELETE runtime/tasks/{taskId}
*/
public void testDeleteTask() throws Exception {
try {
// 1. Simple delete
Task task = taskService.newTask();
taskService.saveTask(task);
String taskId = task.getId();
// Execute the request
HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
assertNull(task);
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
// Check that the historic task has not been deleted
assertNotNull(historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult());
}
// 2. Cascade delete
task = taskService.newTask();
taskService.saveTask(task);
taskId = task.getId();
// Execute the request
httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId) + "?cascadeHistory=true");
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
assertNull(task);
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
// Check that the historic task has been deleted
assertNull(historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult());
}
// 3. Delete with reason
task = taskService.newTask();
taskService.saveTask(task);
taskId = task.getId();
// Execute the request
httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId) + "?deleteReason=fortestingpurposes");
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
assertNull(task);
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
// Check that the historic task has been deleted and delete-reason has been set
HistoricTaskInstance instance = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
assertNotNull(instance);
assertEquals("fortestingpurposes", instance.getDeleteReason());
}
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
// Clean historic tasks with no runtime-counterpart
List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().list();
for (HistoricTaskInstance task : historicTasks) {
historyService.deleteHistoricTaskInstance(task.getId());
}
}
}
Aggregations