-
- public void setErr(ApiError err) {
- this.err = err;
- }
-
-
- // test for presence of a required field
- public void required(String name, Object val, String expr) throws RequiredFieldException {
- err.setCode(0);
- if (val == null) {
- err.setCode(Status.BAD_REQUEST.getStatusCode());
- err.setMessage("missing required field");
- err.setFields(name);
- throw new RequiredFieldException();
- }
- if (expr != null && !expr.isEmpty()) {
- Pattern pattern = Pattern.compile(expr);
- Matcher matcher = pattern.matcher((CharSequence) val);
- if (!matcher.find()) {
- err.setCode(Status.BAD_REQUEST.getStatusCode());
- err.setMessage("value '" + val + "' violates regexp check '" + expr + "'");
- err.setFields(name);
- throw new RequiredFieldException();
- }
- }
- }
-
- // utility to serialize ApiErr object
- public String toString() {
- return String.format("code=%d msg=%s fields=%s", err.getCode(), err.getMessage(), err.getFields());
- }
-
-
- public void setCode(int statusCode) {
- err.setCode(statusCode);
- }
-
-
- public void setMessage(String string) {
- err.setMessage(string);
- }
-
-
- public void setFields(String string) {
- err.setFields(string);
- }
-
- public void checkAuthorization(String auth, String uriPath, String httpMethod)
- throws AuthenticationErrorException, Exception {
- authorization = auth;
- setUriFromPath(uriPath);
- method = httpMethod;
-
- checkAuthorization();
- }
-
-
- public void checkAuthorization() throws AuthenticationErrorException, Exception {