Search in sources :

Example 76 with HttpResponse

use of org.apache.http.HttpResponse in project Activiti by Activiti.

the class JpaRestTest method testGetJpaVariableViaHistoricProcessCollection.

@Deployment(resources = { "org/activiti/rest/api/jpa/jpa-process.bpmn20.xml" })
public void testGetJpaVariableViaHistoricProcessCollection() throws Exception {
    // Get JPA managed entity through the repository
    Message message = messageRepository.findOne(1L);
    assertNotNull(message);
    assertEquals("Hello World", message.getText());
    // add the entity to the process variables and start the process
    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("message", message);
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("jpa-process", processVariables);
    assertNotNull(processInstance);
    Task task = processEngine.getTaskService().createTaskQuery().singleResult();
    assertEquals("Activiti is awesome!", task.getName());
    // Request all variables (no scope provides) which include global and local
    HttpResponse response = executeHttpRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCES) + "?processInstanceId=" + processInstance.getId() + "&includeProcessVariables=true"), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    // check for message variable of type serializable
    assertNotNull(responseNode);
    JsonNode variablesArrayNode = responseNode.get("data").get(0).get("variables");
    assertEquals(1, variablesArrayNode.size());
    JsonNode variableNode = variablesArrayNode.get(0);
    assertEquals("message", variableNode.get("name").asText());
    assertEquals("serializable", variableNode.get("type").asText());
    assertNotNull(variableNode.get("valueUrl"));
}
Also used : Task(org.activiti.engine.task.Task) Message(org.activiti.rest.api.jpa.model.Message) HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 77 with HttpResponse

use of org.apache.http.HttpResponse in project android_frameworks_base by DirtyUnicorns.

the class TestHttpClient method execute.

public HttpResponse execute(final HttpRequest request, final HttpHost targetHost, final HttpClientConnection conn) throws HttpException, IOException {
    this.context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
    this.context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
    this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
    this.httpexecutor.preProcess(request, this.httpproc, this.context);
    HttpResponse response = this.httpexecutor.execute(request, conn, this.context);
    response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
    this.httpexecutor.postProcess(response, this.httpproc, this.context);
    return response;
}
Also used : HttpResponse(org.apache.http.HttpResponse) DefaultedHttpParams(org.apache.http.params.DefaultedHttpParams)

Example 78 with HttpResponse

use of org.apache.http.HttpResponse in project nhin-d by DirectProject.

the class SecuredServiceRequestBase method call.

/**
     * {@inheritDoc}}
     */
@Override
public T call() throws E, IOException, ServiceException {
    HttpUriRequest request = createRequest();
    assert request != null;
    request = securityManager.createAuthenticatedRequest(request);
    final HttpResponse response = httpClient.execute(request);
    try {
        final int statusCode = response.getStatusLine().getStatusCode();
        return interpretResponse(statusCode, response);
    } finally {
        closeConnection(response);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpResponse(org.apache.http.HttpResponse)

Example 79 with HttpResponse

use of org.apache.http.HttpResponse in project nhin-d by DirectProject.

the class UnsecuredServiceRequestBase_interpretResponseTest method testInterpretResponseTest_404Status_assertServiceMethodException.

@Test
public void testInterpretResponseTest_404Status_assertServiceMethodException() throws Exception {
    MockServiceRequest req = new MockServiceRequest(null, "http://service/svc", "Test");
    HttpResponse resp = mock(HttpResponse.class);
    boolean exceptionOccured = false;
    try {
        req.interpretResponse(404, resp);
    } catch (ServiceMethodException e) {
        assertEquals(404, e.getResponseCode());
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : HttpResponse(org.apache.http.HttpResponse) ServiceMethodException(org.nhindirect.common.rest.exceptions.ServiceMethodException) Test(org.junit.Test)

Example 80 with HttpResponse

use of org.apache.http.HttpResponse in project nhin-d by DirectProject.

the class UnsecureServiceRequestBase_callTest method testCall_callWithNoReturnValue.

@Test
public void testCall_callWithNoReturnValue() throws Exception {
    HttpClient mockClient = mock(HttpClient.class);
    StatusLine statLine = mock(StatusLine.class);
    when(statLine.getStatusCode()).thenReturn(204);
    HttpResponse resp = mock(HttpResponse.class);
    when(resp.getStatusLine()).thenReturn(statLine);
    when(mockClient.execute((HttpUriRequest) any())).thenReturn(resp);
    MockServiceRequest req = new MockServiceRequest(mockClient, "http://service/svc", "Test");
    assertNull(req.call());
}
Also used : StatusLine(org.apache.http.StatusLine) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

HttpResponse (org.apache.http.HttpResponse)4168 Test (org.junit.Test)2110 HttpGet (org.apache.http.client.methods.HttpGet)1770 IOException (java.io.IOException)1000 URI (java.net.URI)817 HttpPost (org.apache.http.client.methods.HttpPost)699 HttpClient (org.apache.http.client.HttpClient)550 HttpEntity (org.apache.http.HttpEntity)496 TestHttpClient (io.undertow.testutils.TestHttpClient)403 InputStream (java.io.InputStream)373 Header (org.apache.http.Header)370 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)333 StringEntity (org.apache.http.entity.StringEntity)332 HttpPut (org.apache.http.client.methods.HttpPut)310 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)307 ArrayList (java.util.ArrayList)296 Identity (org.olat.core.id.Identity)262 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)237 File (java.io.File)192 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)191