/** * Performs a GET HTTP operation against the /status endpoint. * * @param runner the runner to perform the status operation on * * @return the result of the operation */ public static Result status( Runner runner ) { preparations( runner ); try { return newStatusOp( runner ).execute( Result.class ); } catch ( ClientHandlerException e ) { if ( e.getCause() instanceof SSLHandshakeException && e.getCause().toString().contains( "PKIX path building failed" ) ) { /* * Oddly this fails the first time but works the second time. Until * I get to the bottom of this and figure it out this is the work * around we will use to make sure this does not fail. We retry once * on the failure. */ return newStatusOp( runner ).execute( Result.class ); } } throw new RuntimeException( "If we got here then the retry also failed." ); }
/** * Handle a client-side Jersey exception. * <p> * If there's an inner IOException, return that. * <p> * Otherwise: create a new wrapper IOE including verb and target details * @param verb HTTP Verb used * @param targetURL URL being targeted * @param exception original exception * @return an exception to throw */ public static IOException convertJerseyException(String verb, String targetURL, ClientHandlerException exception) { if (exception.getCause() instanceof IOException) { return (IOException)exception.getCause(); } else { IOException ioe = new IOException( verb + " " + targetURL + " failed: " + exception); ioe.initCause(exception); return ioe; } }
/** * Handle a client-side Jersey exception. * <p> * If there's an inner IOException, return that. * <p> * Otherwise: create a new wrapper IOE including verb and target details * @param verb HTTP Verb used * @param targetURL URL being targeted * @param exception original exception * @return an exception to throw */ public static IOException convertJerseyException(String verb, String targetURL, ClientHandlerException exception) { if (exception.getCause() instanceof IOException) { return (IOException)exception.getCause(); } else { IOException ioe = new IOException( verb + " " + targetURL + " failed: " + exception); ioe.initCause(exception); return ioe; } }
private void processClientHandlerException(ClientHandlerException e) { if (e.getCause() instanceof java.net.SocketTimeoutException || e.getCause() instanceof java.net.ConnectException) { LOG.error("Connection to {} failed: {}", client.getHost(), e.getMessage()); this.isInitialized = false; throw e; } else { throw e; } }
/** * Verify if the DAS is running or not. */ public boolean isDASRunning() { try { getClientUtil().GETRequest(""); } catch (ClientHandlerException clientEx) { if (clientEx.getCause().getClass().equals(ConnectException.class)) { // We were unable to connect to the DAS through Jersey return false; } } return true; }
@Override public void run() { try { resource = c.resource(uri); bean = resource.accept(MediaType.APPLICATION_JSON_TYPE).get( String.class); byte[] data = bean.getBytes(Charset.forName("UTF-8")); sendOffset += data.length; ChunkImpl c = new ChunkImpl(type, "REST", sendOffset, data, adaptor); long rightNow = Calendar.getInstance(TimeZone.getTimeZone("UTC")) .getTimeInMillis(); c.addTag("timeStamp=\"" + rightNow + "\""); receiver.add(c); } catch (com.sun.jersey.api.client.ClientHandlerException e) { Throwable t = e.getCause(); if (t instanceof java.net.ConnectException) { log.warn("Connect exception trying to connect to " + uri + ". Make sure the service is running"); } else { log.error("RestAdaptor: Interrupted exception"); log.error(ExceptionUtil.getStackTrace(e)); } } catch (Exception e) { log.error("RestAdaptor: Interrupted exception"); log.error(ExceptionUtil.getStackTrace(e)); } } }
@VisibleForTesting ObjectNode callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException { for (int i = 0; i < getNumberOfRetries(); i++) { WebResource resource = resourceCreator.createResource(); try { LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1); return callAPIWithResource(api, resource, requestObject, ObjectNode.class); } catch (ClientHandlerException che) { if (i == (getNumberOfRetries() - 1)) { throw che; } LOG.warn("Handled exception in calling api {}", api.getNormalizedPath(), che); LOG.warn("Exception's cause: {}", che.getCause().getClass()); handleClientHandlerException(che); } } throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries.")); }
@VisibleForTesting ObjectNode callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException { for (int i = 0; i < getNumberOfRetries(); i++) { WebResource resource = resourceCreator.createResource(); try { LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1); return callAPIWithResource(api, resource, requestObject, ObjectNode.class); } catch (ClientHandlerException che) { if (i == (getNumberOfRetries() - 1)) { throw che; } LOG.warn("Handled exception in calling api {}", api.getNormalizedPath(), che); LOG.warn("Exception's cause: {}", che.getCause().getClass()); handleClientHandlerException(che); } } throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries.")); }
@VisibleForTesting JSONObject callAPIWithRetries(APIInfo api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException { for (int i = 0; i < getNumberOfRetries(); i++) { WebResource resource = resourceCreator.createResource(); try { LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1); return callAPIWithResource(api, resource, requestObject, JSONObject.class); } catch (ClientHandlerException che) { if (i == (getNumberOfRetries() - 1)) { throw che; } LOG.warn("Handled exception in calling api {}", api.getPath(), che); LOG.warn("Exception's cause: {}", che.getCause().getClass()); handleClientHandlerException(che); } } throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries.")); }
public static String getResponseAsString(String URI) { if (URI == null) { throw new IllegalStateException("URI cannot be blank"); } String response = null; webClient = Client.create(); try { webResource = webClient.resource(URI); response = webResource.accept(MediaType.APPLICATION_JSON_TYPE).get( String.class); } catch (ClientHandlerException e) { Throwable t = e.getCause(); if (t instanceof java.net.ConnectException) { log.warn("Connect exception trying to connect to [" + URI + "]. Make sure the service is running"); } else { log.error(ExceptionUtil.getStackTrace(e)); } } finally { if (webClient != null) { webClient.destroy(); } } return response; }
if (e.getCause() instanceof ConnectException) { LOG.error("Failed to communicate with REST Server: {} ", this.url); } else { LOG.error("REST Server error. Message: {}", e.getMessage()); } catch (ClientHandlerException e) { if (e.getCause() instanceof ConnectException) { LOG.error("Failed to communicate with REST Server: {} ", this.url); } else { LOG.error("REST Server error. Message: {}", e.getMessage()); } catch (ClientHandlerException e) { if (e.getCause() instanceof ConnectException) { LOG.error("Failed to communicate with REST Server: {} ", this.url); } else {
} catch (ClientHandlerException ch) { message = "Could not connect to DAS on: " + getDASUrl() + " | " + ch.getCause().getMessage(); throw new GlassFishClientException(message);