use of com.sun.jersey.api.client.ClientHandlerException in project incubator-atlas by apache.
the class AtlasClientTest method shouldThrowExceptionIfActiveServerIsNotFound.
@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldThrowExceptionIfActiveServerIsNotFound() {
setupRetryParams();
when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).thenThrow(new ClientHandlerException("Simulating connection exception")).thenReturn(response).thenReturn(response);
AtlasClient atlasClient = new AtlasClient(service, configuration);
String serviceURL = atlasClient.determineActiveServiceURL(new String[] { "http://localhost:31000", "http://localhost:41000" }, client);
assertNull(serviceURL);
}
use of com.sun.jersey.api.client.ClientHandlerException in project incubator-atlas by apache.
the class AtlasClientTest method shouldReturnFalseIfServerIsNotReady.
@Test
public void shouldReturnFalseIfServerIsNotReady() throws AtlasServiceException {
setupRetryParams();
AtlasClient atlasClient = new AtlasClient(service, configuration);
WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service);
when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenThrow(new ClientHandlerException());
assertFalse(atlasClient.isServerReady());
}
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 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 hadoop by apache.
the class ApplicationMaster method publishApplicationAttemptEvent.
private void publishApplicationAttemptEvent(final TimelineClient timelineClient, String appAttemptId, DSEvent appEvent, String domainId, UserGroupInformation ugi) {
final TimelineEntity entity = new TimelineEntity();
entity.setEntityId(appAttemptId);
entity.setEntityType(DSEntity.DS_APP_ATTEMPT.toString());
entity.setDomainId(domainId);
entity.addPrimaryFilter(USER_TIMELINE_FILTER_NAME, ugi.getShortUserName());
TimelineEvent event = new TimelineEvent();
event.setEventType(appEvent.toString());
event.setTimestamp(System.currentTimeMillis());
entity.addEvent(event);
try {
TimelinePutResponse response = timelineClient.putEntities(entity);
processTimelineResponseErrors(response);
} catch (YarnException | IOException | ClientHandlerException e) {
LOG.error("App Attempt " + (appEvent.equals(DSEvent.DS_APP_ATTEMPT_START) ? "start" : "end") + " event could not be published for " + appAttemptID, e);
}
}
Aggregations