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