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