Search in sources :

Example 26 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse 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 27 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project opennms by OpenNMS.

the class HttpRequisitionProvider method getRequisitionFor.

@Override
public Requisition getRequisitionFor(HttpRequisitionRequest request) {
    try (HttpClientWrapper client = HttpClientWrapper.create()) {
        final URI uri = new URI(request.getUrl());
        HttpGet get = new HttpGet(uri);
        if (Boolean.FALSE.equals(request.getStrictSsl())) {
            client.trustSelfSigned(uri.getScheme());
        }
        if (request.getUsername() != null) {
            client.addBasicCredentials(request.getPassword(), request.getPassword());
        }
        try (CloseableHttpResponse response = client.execute(get)) {
            String responseString = new BasicResponseHandler().handleResponse(response);
            return JaxbUtils.unmarshal(Requisition.class, responseString);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpClientWrapper(org.opennms.core.web.HttpClientWrapper) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) URI(java.net.URI)

Example 28 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.

the class TaskIdentityLinkResourceTest method testGetIdentityLinks.

/**
   * Test getting all identity links.
   * GET runtime/tasks/{taskId}/identitylinks
   */
@Deployment
public void testGetIdentityLinks() throws Exception {
    // Test candidate user/groups links + manual added identityLink
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("identityLinkProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.addUserIdentityLink(task.getId(), "john", "customType");
    assertEquals(3, taskService.getIdentityLinksForTask(task.getId()).size());
    // Execute the request
    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINKS_COLLECTION, task.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertTrue(responseNode.isArray());
    assertEquals(3, responseNode.size());
    boolean groupCandidateFound = false;
    boolean userCandidateFound = false;
    boolean customLinkFound = false;
    for (int i = 0; i < responseNode.size(); i++) {
        ObjectNode link = (ObjectNode) responseNode.get(i);
        assertNotNull(link);
        if (!link.get("user").isNull()) {
            if (link.get("user").textValue().equals("john")) {
                assertEquals("customType", link.get("type").textValue());
                assertTrue(link.get("group").isNull());
                assertTrue(link.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINK, task.getId(), "users", "john", "customType")));
                customLinkFound = true;
            } else {
                assertEquals("kermit", link.get("user").textValue());
                assertEquals("candidate", link.get("type").textValue());
                assertTrue(link.get("group").isNull());
                assertTrue(link.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINK, task.getId(), "users", "kermit", "candidate")));
                userCandidateFound = true;
            }
        } else if (!link.get("group").isNull()) {
            assertEquals("sales", link.get("group").textValue());
            assertEquals("candidate", link.get("type").textValue());
            assertTrue(link.get("user").isNull());
            assertTrue(link.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINK, task.getId(), RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS, "sales", "candidate")));
            groupCandidateFound = true;
        }
    }
    assertTrue(groupCandidateFound);
    assertTrue(userCandidateFound);
    assertTrue(customLinkFound);
}
Also used : Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 29 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.

the class ProcessDefinitionResourceTest method testGetUnexistingProcessDefinition.

/**
   * Test getting an unexisting process-definition.
   * GET repository/process-definitions/{processDefinitionId}
   */
public void testGetUnexistingProcessDefinition() throws Exception {
    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, "unexisting"));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 30 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.

the class ProcessDefinitionResourceTest method testSuspendProcessDefinition.

/**
    * Test suspending a process definition.
    * POST repository/process-definitions/{processDefinitionId}
    */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testSuspendProcessDefinition() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertFalse(processDefinition.isSuspended());
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "suspend");
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
    // Check "OK" status
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertTrue(responseNode.get("suspended").booleanValue());
    // Check if process-definitoin is suspended
    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertTrue(processDefinition.isSuspended());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Aggregations

CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1314 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)502 HttpGet (org.apache.http.client.methods.HttpGet)485 Test (org.junit.Test)370 IOException (java.io.IOException)362 HttpPost (org.apache.http.client.methods.HttpPost)286 HttpEntity (org.apache.http.HttpEntity)248 StringEntity (org.apache.http.entity.StringEntity)229 JsonNode (com.fasterxml.jackson.databind.JsonNode)126 StatusLine (org.apache.http.StatusLine)121 URI (java.net.URI)118 InputStream (java.io.InputStream)112 ArrayList (java.util.ArrayList)87 Deployment (org.activiti.engine.test.Deployment)87 RequestConfig (org.apache.http.client.config.RequestConfig)87 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)87 HttpPut (org.apache.http.client.methods.HttpPut)79 Map (java.util.Map)75 Header (org.apache.http.Header)75 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)73