Search in sources :

Example 1 with HttpDelete

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;
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse)

Example 2 with HttpDelete

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);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) HttpClientException(org.apache.olingo.client.api.http.HttpClientException) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) HttpPatch(org.apache.olingo.client.core.http.HttpPatch) URISyntaxException(java.net.URISyntaxException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) ODataClientErrorException(org.apache.olingo.client.api.communication.ODataClientErrorException) HttpClientException(org.apache.olingo.client.api.http.HttpClientException)

Example 3 with HttpDelete

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());
        }
    });
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpEntity(org.apache.http.HttpEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException)

Example 4 with HttpDelete

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);
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) HttpDelete(org.apache.http.client.methods.HttpDelete)

Example 5 with HttpDelete

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());
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HttpDelete(org.apache.http.client.methods.HttpDelete)

Aggregations

HttpDelete (org.apache.http.client.methods.HttpDelete)309 HttpResponse (org.apache.http.HttpResponse)146 Test (org.junit.Test)115 URI (java.net.URI)84 HttpGet (org.apache.http.client.methods.HttpGet)48 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)47 IOException (java.io.IOException)46 HttpPost (org.apache.http.client.methods.HttpPost)43 HttpPut (org.apache.http.client.methods.HttpPut)43 Identity (org.olat.core.id.Identity)38 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)35 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)30 RepositoryEntry (org.olat.repository.RepositoryEntry)24 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)23 HttpEntity (org.apache.http.HttpEntity)22 HttpClient (org.apache.http.client.HttpClient)19 StringEntity (org.apache.http.entity.StringEntity)19 URISyntaxException (java.net.URISyntaxException)13 Header (org.apache.http.Header)12 ArrayList (java.util.ArrayList)11