@Override public RestResponse sendRequestImpl(RestRequest request) throws IOException { Future<RestResponse> responseFuture = client.restRequest(request); RestResponse response; try { response = responseFuture.get(); } catch (InterruptedException | ExecutionException e) { // The service may choose to throw an exception as a way to report error Throwable t = e.getCause(); if (t != null && t instanceof RestException) { response = ((RestException) t).getResponse(); } else { throw new IOException(e); } } return response; }
private void handleRequestAndResponseException(Exception e) { if(e instanceof ExecutionException) { if(e.getCause() instanceof RestException) { RestException re = (RestException) e.getCause(); if(logger.isDebugEnabled()) { logger.debug("REST Exception Status: " + re.getResponse().getStatus()); } } else { throw new VoldemortException("Unknown HTTP request execution exception: " + e.getMessage(), e); } } else if(e instanceof InterruptedException) { if(logger.isDebugEnabled()) { logger.debug("Operation interrupted : " + e.getMessage(), e); } throw new VoldemortException("Operation interrupted exception: " + e.getMessage(), e); } else if(e instanceof URISyntaxException) { throw new VoldemortException("Illegal HTTP URL " + e.getMessage(), e); } else if(e instanceof UnsupportedEncodingException) { throw new VoldemortException("Illegal Encoding Type " + e.getMessage(), e); } else { throw new VoldemortException("Unknown exception: " + e.getMessage(), e); } }
public String getStoreClientConfigString(List<String> storeNames, String coordinatorUrl) { try { // Create the REST request StringBuilder URIStringBuilder = new StringBuilder().append(coordinatorUrl) .append(URL_SEPARATOR) .append(STORE_CLIENT_CONFIG_OPS) .append(URL_SEPARATOR) .append(Joiner.on(",") .join(storeNames)); RestRequestBuilder requestBuilder = new RestRequestBuilder(new URI(URIStringBuilder.toString())); String timeoutStr = Long.toString(this.config.getTimeoutConfig() .getOperationTimeout(VoldemortOpCode.GET_OP_CODE)); requestBuilder.setMethod(requestType.GET.toString()); requestBuilder.setHeader(RestMessageHeaders.X_VOLD_REQUEST_TIMEOUT_MS, timeoutStr); requestBuilder = setCommonRequestHeader(requestBuilder); RestRequest request = requestBuilder.build(); Future<RestResponse> future = client.restRequest(request); // This will block RestResponse response = future.get(); ByteString entity = response.getEntity(); return entity.asString("UTF-8"); } catch(Exception e) { if(e.getCause() instanceof RestException) { return ((RestException) e.getCause()).getResponse().getEntity().asString("UTF-8"); } handleRequestAndResponseException(e); } return null; }
RestException exception = (RestException) e.getCause(); if(logger.isDebugEnabled()) { logger.debug("REST EXCEPTION STATUS : " + exception.getResponse().getStatus());
RestException exception = (RestException) e.getCause(); if(logger.isDebugEnabled()) { logger.debug("REST EXCEPTION STATUS : " + exception.getResponse().getStatus());
responseMessage = ((RestException) e.getCause()).getResponse() .getEntity() .asString("UTF-8");
RestException exception = (RestException) e.getCause(); if(logger.isDebugEnabled()) { logger.debug("REST EXCEPTION STATUS : " + exception.getResponse().getStatus());
RestException exception = (RestException) e.getCause(); if(logger.isDebugEnabled()) { logger.debug("REST EXCEPTION STATUS : " + exception.getResponse().getStatus());
responseMessage = ((RestException) e.getCause()).getResponse() .getEntity() .asString("UTF-8");
RestException exception = (RestException) e.getCause(); if(logger.isDebugEnabled()) { logger.debug("REST EXCEPTION STATUS : " + exception.getResponse().getStatus()); if(exception.getResponse().getStatus() == NOT_FOUND.getCode()) { return false;
RestException exception = (RestException) e.getCause(); if(logger.isDebugEnabled()) { logger.debug("REST EXCEPTION STATUS : " + exception.getResponse().getStatus()); int httpErrorStatus = exception.getResponse().getStatus(); if(httpErrorStatus == BAD_REQUEST.getCode()) { throw new VoldemortException("Bad request: " + e.getMessage(), e);
private boolean ignoreLog(Throwable ex) { if (ex instanceof StreamException) { StreamException streamException = (StreamException)ex; return streamException.getResponse() != null; } if (ex instanceof RestException) { RestException restException = (RestException)ex; return restException.getResponse() != null; } return false; }
private boolean logFullException(Throwable ex) { if (ex instanceof StreamException) { StreamException streamException = (StreamException)ex; return streamException.getResponse() != null; } if (ex instanceof RestException) { RestException restException = (RestException)ex; return restException.getResponse() != null; } return true; }
@Override public RestResponse sendRequestImpl(RestRequest request) throws IOException { Future<RestResponse> responseFuture = client.restRequest(request); RestResponse response; try { response = responseFuture.get(); } catch (InterruptedException | ExecutionException e) { // The service may choose to throw an exception as a way to report error Throwable t = e.getCause(); if (t != null && t instanceof RestException) { response = ((RestException) t).getResponse(); } else { throw new IOException(e); } } return response; }
@Override public void onRestError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) { if (ex instanceof RestException) { saveResponse(((RestException) ex).getResponse(), requestContext); } nextFilter.onError(ex, requestContext, wireAttrs); }
@Override public void onError(Throwable e) { // It is assumed that the handler always returns RestException. It happens because the original callback passed into // the handler is wrapped into com.linkedin.restli.internal.server.RestLiCallback. // It is possible the callback is not wrapped and other exceptions are returned // (e.g. com.linkedin.restli.server.RestLiServiceException). This is considered either a programmers mistake or a // runtime exception. if (e instanceof RestException) { promise.done(((RestException) e).getResponse()); } else { promise.fail(e); } }
/** * Create a StreamException based on the RestException * @param restException the rest Exception * @return the StreamException that's created based on rest exception */ public static StreamException toStreamException(final RestException restException) { return new StreamException(toStreamResponse(restException.getResponse()), restException.getMessage(), restException.getCause()); }
/** * Returns true if the given throwable indicates a server-side error. */ private boolean isServerError(Throwable throwable) { if (throwable instanceof RestException) { RestException restException = (RestException) throwable; if (restException.getResponse() != null) { return matchErrorStatus(restException.getResponse().getStatus()); } } else if (throwable instanceof StreamException) { StreamException streamException = (StreamException) throwable; if (streamException.getResponse() != null) { return matchErrorStatus(streamException.getResponse().getStatus()); } } // default to false return false; }
if (e instanceof RestException) restResponse = ((RestException) e).getResponse();
@Override public void onResponse(TransportResponse<RestResponse> response) { if (response.hasError()) { final Throwable ex = response.getError(); if (ex instanceof RestException) { callback.onResponse(TransportResponseImpl.success(((RestException) ex).getResponse(), response.getWireAttributes())); return; } } callback.onResponse(response); } };