Search in sources :

Example 11 with ClientHandlerException

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);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) WebResource(com.sun.jersey.api.client.WebResource) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 12 with ClientHandlerException

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());
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) WebResource(com.sun.jersey.api.client.WebResource) Test(org.testng.annotations.Test)

Example 13 with ClientHandlerException

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));
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.codehaus.jettison.json.JSONObject) Form(com.sun.jersey.api.representation.Form) WebResource(com.sun.jersey.api.client.WebResource) JSONException(org.codehaus.jettison.json.JSONException)

Example 14 with ClientHandlerException

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);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 15 with ClientHandlerException

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);
    }
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timeline.TimelineEvent) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) IOException(java.io.IOException) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Aggregations

ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)21 ClientResponse (com.sun.jersey.api.client.ClientResponse)12 WebResource (com.sun.jersey.api.client.WebResource)9 IOException (java.io.IOException)6 Test (org.testng.annotations.Test)6 ConnectException (java.net.ConnectException)5 URI (java.net.URI)5 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)5 Matchers.anyString (org.mockito.Matchers.anyString)5 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)4 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)4 TimelineEvent (org.apache.hadoop.yarn.api.records.timeline.TimelineEvent)4 JSONException (org.codehaus.jettison.json.JSONException)4 TimelinePutResponse (org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HttpRequest (com.netflix.client.http.HttpRequest)2 Client (com.sun.jersey.api.client.Client)2 InputStream (java.io.InputStream)2 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)2