/** * Immediately stops a request within a filter or route with specified status code and body content * NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise * halt will not work * * @param status The status code * @param body The body content * @return HaltException object with status and body set */ public HaltException halt(int status, String body) { throw new HaltException(status, body); }
/** * Modifies the HTTP response and body based on the provided HaltException. * * @param httpResponse The HTTP servlet response * @param body The body content * @param halt The halt exception object */ public static void modify(HttpServletResponse httpResponse, Body body, HaltException halt) { httpResponse.setStatus(halt.statusCode()); if (halt.body() != null) { body.set(halt.body()); } else { body.set(""); } } }
@Override public boolean matches(Object o) { if (o instanceof HaltException) { HaltException haltException = (HaltException) o; return haltException.statusCode() == HttpStatus.UNAUTHORIZED_401; } return false; }
private boolean bodyHasErrorDetail(Throwable throwable, ErrorResponder.ErrorDetail errorDetail) { HaltException haltException = (HaltException) throwable; DocumentContext jsonPath = JsonPath.parse(haltException.body()); return errorDetail.equals(new ErrorResponder.ErrorDetail( jsonPath.read("$.statusCode"), jsonPath.read("$.type"), jsonPath.read("$.message"), Optional.ofNullable(jsonPath.read("$.details")))); }
httpResponse.setStatus(hEx.getStatusCode()); if(hEx.getBody() != null) { bodyContent = hEx.getBody();
@Override public boolean matches(Object o) { if (o instanceof HaltException) { HaltException haltException = (HaltException) o; return haltException.statusCode() == HttpStatus.UNAUTHORIZED_401; } return false; }
private boolean bodyHasErrorDetail(Throwable throwable, ErrorResponder.ErrorDetail errorDetail) { HaltException haltException = (HaltException) throwable; DocumentContext jsonPath = JsonPath.parse(haltException.body()); return errorDetail.equals(new ErrorResponder.ErrorDetail( jsonPath.read("$.statusCode"), jsonPath.read("$.type"), jsonPath.read("$.message"), Optional.ofNullable(jsonPath.read("$.details")))); }
/** * Immediately stops a request within a filter or route * NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise * halt will not work * * @return HaltException object */ public HaltException halt() { throw new HaltException(); }
/** * Modifies the HTTP response and body based on the provided HaltException. * * @param httpResponse The HTTP servlet response * @param body The body content * @param halt The halt exception object */ public static void modify(HttpServletResponse httpResponse, Body body, HaltException halt) { httpResponse.setStatus(halt.statusCode()); if (halt.body() != null) { body.set(halt.body()); } else { body.set(""); } } }
private boolean hasStatus(Throwable throwable, int status) { HaltException haltException = (HaltException) throwable; return Objects.equals(haltException.statusCode(), status); }
/** * Immediately stops a request within a filter or route with specified status code * NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise * halt will not work * * @param status the status code * @return HaltException object with status code set */ public HaltException halt(int status) { throw new HaltException(status); }
private boolean hasStatus(Throwable throwable, int status) { HaltException haltException = (HaltException) throwable; return Objects.equals(haltException.statusCode(), status); }
/** * Immediately stops a request within a filter or route with specified body content * NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise * halt will not work * * @param body The body content * @return HaltException object with body set */ public HaltException halt(String body) { throw new HaltException(body); }
/** * Immediately stops a request within a filter or route with specified * status code * NOTE: When using this don't catch exceptions of type HaltException, or if * catched, re-throw otherwise * halt will not work * * @param status the status code */ protected static final void halt(int status) { throw new HaltException(status); }
/** * Immediately stops a request within a filter or route with specified body * content * NOTE: When using this don't catch exceptions of type HaltException, or if * catched, re-throw otherwise * halt will not work * * @param body The body content */ protected static final void halt(String body) { throw new HaltException(body); }
/** * Immediately stops a request within a filter or route * NOTE: When using this don't catch exceptions of type HaltException, or if * catched, re-throw otherwise * halt will not work */ protected static final void halt() { throw new HaltException(); }
/** * Immediately stops a request within a filter or route * NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise * halt will not work * * @return HaltException object */ public HaltException halt() { throw new HaltException(); }
/** * Immediately stops a request within a filter or route with specified status code * NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise * halt will not work * * @param status the status code * @return HaltException object with status code set */ public HaltException halt(int status) { throw new HaltException(status); }
/** * Immediately stops a request within a filter or route with specified body content * NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise * halt will not work * * @param body The body content * @return HaltException object with body set */ public HaltException halt(String body) { throw new HaltException(body); }
/** * Immediately stops a request within a filter or route with specified status code and body content * NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise * halt will not work * * @param status The status code * @param body The body content * @return HaltException object with status and body set */ public HaltException halt(int status, String body) { throw new HaltException(status, body); }