use of com.sun.jersey.api.client.ClientHandlerException in project hadoop by apache.
the class TestTimelineClient method mockDomainClientResponse.
private static ClientResponse mockDomainClientResponse(TimelineWriter spyTimelineWriter, ClientResponse.Status status, boolean hasRuntimeError) {
ClientResponse response = mock(ClientResponse.class);
if (hasRuntimeError) {
doThrow(new ClientHandlerException(new ConnectException())).when(spyTimelineWriter).doPostingObject(any(TimelineDomain.class), any(String.class));
return response;
}
doReturn(response).when(spyTimelineWriter).doPostingObject(any(TimelineDomain.class), any(String.class));
when(response.getStatusInfo()).thenReturn(status);
return response;
}
use of com.sun.jersey.api.client.ClientHandlerException in project eureka by Netflix.
the class DynamicGZIPContentEncodingFilter method decompressResponse.
private static void decompressResponse(ClientResponse response) {
InputStream entityInputStream = response.getEntityInputStream();
GZIPInputStream uncompressedIS;
try {
uncompressedIS = new GZIPInputStream(entityInputStream);
} catch (IOException ex) {
try {
entityInputStream.close();
} catch (IOException ignored) {
}
throw new ClientHandlerException(ex);
}
response.setEntityInputStream(uncompressedIS);
}
use of com.sun.jersey.api.client.ClientHandlerException in project ORCID-Source by ORCID.
the class SalesForceDaoImpl method getFreshAccessToken.
private String getFreshAccessToken() {
LOGGER.info("About get SalesForce access token");
WebResource resource = client.resource(tokenEndPointUrl);
Form form = new Form();
form.add("grant_type", "password");
form.add("client_id", clientId);
form.add("client_secret", clientSecret);
form.add("username", username);
form.add("password", password);
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, form);
if (response.getStatus() == 200) {
try {
return response.getEntity(JSONObject.class).getString("access_token");
} catch (ClientHandlerException | UniformInterfaceException | JSONException e) {
throw new RuntimeException("Unable to extract access token from response", e);
}
} else {
throw new RuntimeException("Error getting access token from SalesForce, status code = " + response.getStatus() + ", reason = " + response.getStatusInfo().getReasonPhrase() + ", body = " + response.getEntity(String.class));
}
}
use of com.sun.jersey.api.client.ClientHandlerException in project incubator-atlas by apache.
the class AtlasClientTest method shouldRetryWithSameClientIfSingleAddressIsUsed.
@Test
public void shouldRetryWithSameClientIfSingleAddressIsUsed() throws URISyntaxException, AtlasServiceException {
setupRetryParams();
ResourceCreator resourceCreator = mock(ResourceCreator.class);
WebResource resourceObject = mock(WebResource.class);
when(resourceObject.getURI()).thenReturn(new URI("http://localhost:31000/api/atlas/types"));
WebResource.Builder builder = getBuilder(resourceObject);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
String activeStatus = "{\"Status\":\"ACTIVE\"}";
when(response.getEntity(String.class)).thenReturn(activeStatus);
when(response.getLength()).thenReturn(activeStatus.length());
when(builder.method(AtlasClient.API.LIST_TYPES.getMethod(), ClientResponse.class, null)).thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).thenReturn(response);
when(resourceCreator.createResource()).thenReturn(resourceObject);
when(configuration.getString("atlas.http.authentication.type", "simple")).thenReturn("simple");
AtlasClient atlasClient = getClientForTest("http://localhost:31000");
atlasClient.setService(resourceObject);
atlasClient.setConfiguration(configuration);
atlasClient.callAPIWithRetries(AtlasClient.API.LIST_TYPES, null, resourceCreator);
verify(client).destroy();
verify(client, times(2)).resource(UriBuilder.fromUri("http://localhost:31000").build());
}
use of com.sun.jersey.api.client.ClientHandlerException in project incubator-atlas by apache.
the class AtlasClientTest method shouldRetryAPICallsOnServiceUnavailable.
@Test
public void shouldRetryAPICallsOnServiceUnavailable() throws AtlasServiceException, URISyntaxException {
setupRetryParams();
ResourceCreator resourceCreator = mock(ResourceCreator.class);
WebResource resourceObject = mock(WebResource.class);
when(resourceObject.getURI()).thenReturn(new URI("http://localhost:31000/api/atlas/types")).thenReturn(new URI("http://localhost:41000/api/atlas/types")).thenReturn(new URI("http://localhost:41000/api/atlas/types"));
WebResource.Builder builder = getBuilder(resourceObject);
ClientResponse firstResponse = mock(ClientResponse.class);
when(firstResponse.getStatus()).thenReturn(Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
when(firstResponse.getClientResponseStatus()).thenReturn(ClientResponse.Status.SERVICE_UNAVAILABLE);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
String activeStatus = "{\"Status\":\"ACTIVE\"}";
when(response.getEntity(String.class)).thenReturn(activeStatus);
when(response.getLength()).thenReturn(activeStatus.length());
when(builder.method(AtlasClient.API.LIST_TYPES.getMethod(), ClientResponse.class, null)).thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).thenReturn(firstResponse).thenReturn(response);
when(resourceCreator.createResource()).thenReturn(resourceObject);
AtlasClient atlasClient = getClientForTest("http://localhost:31000", "http://localhost:41000");
atlasClient.setService(resourceObject);
atlasClient.setConfiguration(configuration);
atlasClient.callAPIWithRetries(AtlasClient.API.LIST_TYPES, null, resourceCreator);
verify(client).destroy();
verify(client).resource(UriBuilder.fromUri("http://localhost:31000").build());
verify(client).resource(UriBuilder.fromUri("http://localhost:41000").build());
}
Aggregations