Search in sources :

Example 76 with HttpResponse

use of org.graylog.shaded.elasticsearch7.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 77 with HttpResponse

use of org.graylog.shaded.elasticsearch7.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 78 with HttpResponse

use of org.graylog.shaded.elasticsearch7.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)

Example 79 with HttpResponse

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

the class UnsecureServiceRequestBase_callTest method testCall_nullRequest_assertServiceException.

@Test
public void testCall_nullRequest_assertServiceException() 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", "");
    boolean exceptionOccured = false;
    try {
        req.call();
    } catch (ServiceException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : StatusLine(org.apache.http.StatusLine) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 80 with HttpResponse

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

the class UnsecuredServiceRequestBase_handleUnauthorizedTest method testHandleUnauthorized_noHeaders_assertAuthorizationException.

@Test
public void testHandleUnauthorized_noHeaders_assertAuthorizationException() throws Exception {
    MockServiceRequest req = new MockServiceRequest(null, "http://service/svc", "Test");
    HttpResponse resp = mock(HttpResponse.class);
    AuthorizationException ex = req.handleUnauthorized(resp);
    assertEquals("Action not authorized", ex.getMessage());
}
Also used : AuthorizationException(org.nhindirect.common.rest.exceptions.AuthorizationException) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

HttpResponse (org.apache.http.HttpResponse)4366 Test (org.junit.Test)2158 HttpGet (org.apache.http.client.methods.HttpGet)1833 IOException (java.io.IOException)1110 URI (java.net.URI)834 HttpPost (org.apache.http.client.methods.HttpPost)759 HttpClient (org.apache.http.client.HttpClient)600 HttpEntity (org.apache.http.HttpEntity)541 TestHttpClient (io.undertow.testutils.TestHttpClient)403 InputStream (java.io.InputStream)398 Header (org.apache.http.Header)385 StringEntity (org.apache.http.entity.StringEntity)363 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)344 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)338 HttpPut (org.apache.http.client.methods.HttpPut)320 ArrayList (java.util.ArrayList)316 Identity (org.olat.core.id.Identity)262 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)253 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)209 File (java.io.File)196