@Override public void onMatch(RestCall rc, Matcher m) throws RestCallException { throw new RestCallException("Failure pattern detected."); } }
/** * Constructor. * * @param cause The cause of this exception. * @param message The {@link MessageFormat}-style message. * @param args Optional {@link MessageFormat}-style arguments. */ public RestCallException(Throwable cause, String message, Object...args) { this(getMessage(cause, message, null), args); initCause(cause); }
/** * Constructor. * * @param e The inner cause of the exception. */ public RestCallException(Exception e) { super(e.getLocalizedMessage(), e); if (e instanceof FileNotFoundException) { responseCode = 404; } else if (e.getMessage() != null) { Pattern p = Pattern.compile("[^\\d](\\d{3})[^\\d]"); Matcher m = p.matcher(e.getMessage()); if (m.find()) responseCode = Integer.parseInt(m.group(1)); } setStackTrace(e.getStackTrace()); }
public static final void checkErrorResponse(boolean debug, RestCallException e, int status, String...contains) throws AssertionFailedError { String r = e.getResponseMessage(); if (debug) { System.err.println(r); // NOT DEBUG e.printStackTrace(); } if (status != e.getResponseCode()) { dumpResponse(r, "Response status code was not correct. Expected: ''{0}''. Actual: ''{1}''", status, e.getResponseCode()); throw new AssertionFailedError(format("Response status code was not correct. Expected: ''{0}''. Actual: ''{1}''", status, e.getResponseCode())); } for (String s : contains) { if (r == null || ! r.contains(s)) { if (! debug) dumpResponse(r, "Response did not have the following expected text: ''{0}''", s); throw new AssertionFailedError(format("Response did not have the following expected text: ''{0}''", s)); } } } }
throw new RestCallException("Both input and form data found on same request."); throw new RestCallException(0, "Method does not support content entity.", request.getMethod(), request.getURI(), null); throw new RestCallException("Rest call set to retryable, but entity is not repeatable."); rci.onConnect(this, sc, request, response); if (response == null) throw new RestCallException("HttpClient returned a null response"); StatusLine sl = response.getStatusLine(); String method = request.getMethod(); throw new RestCallException(sc, sl.getReasonPhrase(), method, request.getURI(), getResponseAsString()) .setServerException(response.getFirstHeader("Exception-Name"), response.getFirstHeader("Exception-Message"), response.getFirstHeader("Exception-Trace")) .setHttpResponse(response); throw new RestCallException(sc, "Maximum number of redirects occurred. Location header: " + response.getFirstHeader("Location"), method, request.getURI(), getResponseAsString()); Header h = response.getFirstHeader("Location"); if (h != null) { isFailed = true; close(); throw new RestCallException(e).setHttpResponse(response);
int sc = status.getStatusCode(); if (sc >= 400 && ! ignoreErrors) throw new RestCallException(sc, status.getReasonPhrase(), request.getMethod(), request.getURI(), getResponseAsString()).setHttpResponse(response); if (outputStreams.size() > 0 || writers.size() > 0) getReader(); } catch (IOException e) { isFailed = true; throw new RestCallException(e).setHttpResponse(response); } finally { close();
if (rt == Boolean.class || rt == boolean.class) return returnCode < 400; throw new RestCallException("Invalid return type on method annotated with @RemoteMethod(returns=HTTP_STATUS). Only integer and booleans types are valid."); } else if (rmr.getReturnValue() == RemoteReturn.BEAN) { return rc.getResponse(rmr.getResponseBeanMeta()); e.throwServerException(interfaceClass.getClassLoader(), rmm.getExceptions()); throw new RuntimeException(e); } catch (Exception e) {
@Override /* InvocationHandler */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { RemoteInterfaceMethod rim = rm.getMethodMeta(method); if (rim == null) throw new RuntimeException("Method is not exposed as a remote method."); String url = rim.getUrl(); try (RestCall rc = doCall("POST", url, true)) { rc.serializer(serializer).parser(parser).body(args); Object v = rc.getResponse(method.getGenericReturnType()); if (v == null && method.getReturnType().isPrimitive()) v = ClassUtils.getPrimitiveDefault(method.getReturnType()); return v; } catch (RestCallException e) { // Try to throw original exception if possible. e.throwServerException(interfaceClass.getClassLoader(), method.getExceptionTypes()); throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } } });
for (Class<?> t : throwables) if (t.getName().endsWith(serverExceptionName)) doThrow(t, serverExceptionMessage); try { Class<?> t = cl.loadClass(serverExceptionName); if (isParentClass(RuntimeException.class, t) || isParentClass(Error.class, t)) doThrow(t, serverExceptionMessage); } catch (ClassNotFoundException e2) { /* Ignore */ }
throw new RestCallException("Both input and form data found on same request."); throw new RestCallException(0, "Method does not support content entity.", request.getMethod(), request.getURI(), null); throw new RestCallException("Rest call set to retryable, but entity is not repeatable."); rci.onConnect(this, sc, request, response); if (response == null) throw new RestCallException("HttpClient returned a null response"); StatusLine sl = response.getStatusLine(); String method = request.getMethod(); throw new RestCallException(sc, sl.getReasonPhrase(), method, request.getURI(), getResponseAsString()) .setServerException(response.getFirstHeader("Exception-Name"), response.getFirstHeader("Exception-Message"), response.getFirstHeader("Exception-Trace")) .setHttpResponse(response); throw new RestCallException(sc, "Maximum number of redirects occurred. Location header: " + response.getFirstHeader("Location"), method, request.getURI(), getResponseAsString()); Header h = response.getFirstHeader("Location"); if (h != null) { isFailed = true; close(); throw new RestCallException(e).setHttpResponse(response);
int sc = status.getStatusCode(); if (sc >= 400 && ! ignoreErrors) throw new RestCallException(sc, status.getReasonPhrase(), request.getMethod(), request.getURI(), getResponseAsString()).setHttpResponse(response); if (outputStreams.size() > 0 || writers.size() > 0) getReader(); } catch (IOException e) { isFailed = true; throw new RestCallException(e).setHttpResponse(response); } finally { close();
if (rt == Boolean.class || rt == boolean.class) return returnCode < 400; throw new RestCallException("Invalid return type on method annotated with @RemoteMethod(returns=HTTP_STATUS). Only integer and booleans types are valid."); } else if (rmr.getReturnValue() == RemoteReturn.BEAN) { return rc.getResponse(rmr.getResponseBeanMeta()); e.throwServerException(interfaceClass.getClassLoader(), rmm.getExceptions()); throw new RuntimeException(e); } catch (Exception e) {
@Override /* InvocationHandler */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { RemoteInterfaceMethod rim = rm.getMethodMeta(method); if (rim == null) throw new RuntimeException("Method is not exposed as a remote method."); String url = rim.getUrl(); try (RestCall rc = doCall("POST", url, true)) { rc.serializer(serializer).parser(parser).body(args); Object v = rc.getResponse(method.getGenericReturnType()); if (v == null && method.getReturnType().isPrimitive()) v = ClassUtils.getPrimitiveDefault(method.getReturnType()); return v; } catch (RestCallException e) { // Try to throw original exception if possible. e.throwServerException(interfaceClass.getClassLoader(), method.getExceptionTypes()); throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } } });
for (Class<?> t : throwables) if (t.getName().endsWith(serverExceptionName)) doThrow(t, serverExceptionMessage); try { Class<?> t = cl.loadClass(serverExceptionName); if (isParentClass(RuntimeException.class, t) || isParentClass(Error.class, t)) doThrow(t, serverExceptionMessage); } catch (ClassNotFoundException e2) { /* Ignore */ }
@Override public void onNoMatch(RestCall rc) throws RestCallException { throw new RestCallException("Success pattern not detected."); } }
throw new RestCallException("Both input and form data found on same request."); throw new RestCallException(0, "Method does not support content entity.", request.getMethod(), request.getURI(), null); throw new RestCallException("Rest call set to retryable, but entity is not repeatable."); rci.onConnect(this, sc, request, response); if (response == null) throw new RestCallException("HttpClient returned a null response"); StatusLine sl = response.getStatusLine(); String method = request.getMethod(); throw new RestCallException(sc, sl.getReasonPhrase(), method, request.getURI(), getResponseAsString()) .setServerException(response.getFirstHeader("Exception-Name"), response.getFirstHeader("Exception-Message"), response.getFirstHeader("Exception-Trace")) .setHttpResponse(response); throw new RestCallException(sc, "Maximum number of redirects occurred. Location header: " + response.getFirstHeader("Location"), method, request.getURI(), getResponseAsString()); Header h = response.getFirstHeader("Location"); if (h != null) { isFailed = true; close(); throw new RestCallException(e).setHttpResponse(response);
/** * Constructor. * * @param cause The cause of this exception. * @param message The {@link MessageFormat}-style message. * @param args Optional {@link MessageFormat}-style arguments. */ public RestCallException(Throwable cause, String message, Object...args) { this(getMessage(cause, message, null), args); initCause(cause); }
int sc = status.getStatusCode(); if (sc >= 400 && ! ignoreErrors) throw new RestCallException(sc, status.getReasonPhrase(), request.getMethod(), request.getURI(), getResponseAsString()).setHttpResponse(response); if (outputStreams.size() > 0 || writers.size() > 0) getReader(); } catch (IOException e) { isFailed = true; throw new RestCallException(e).setHttpResponse(response); } finally { close();
if (rt == Boolean.class || rt == boolean.class) return returnCode < 400; throw new RestCallException("Invalid return type on method annotated with @RemoteMethod(returns=HTTP_STATUS). Only integer and booleans types are valid."); } else if (rmr.getReturnValue() == RemoteReturn.BEAN) { return rc.getResponse(rmr.getResponseBeanMeta()); e.throwServerException(interfaceClass.getClassLoader(), rmm.getExceptions()); throw new RuntimeException(e); } catch (Exception e) {
/** * Constructor. * * @param e The inner cause of the exception. */ public RestCallException(Exception e) { super(e.getLocalizedMessage(), e); if (e instanceof FileNotFoundException) { responseCode = 404; } else if (e.getMessage() != null) { Pattern p = Pattern.compile("[^\\d](\\d{3})[^\\d]"); Matcher m = p.matcher(e.getMessage()); if (m.find()) responseCode = Integer.parseInt(m.group(1)); } setStackTrace(e.getStackTrace()); }