use of play.mvc.Catch in project coprhd-controller by CoprHD.
the class Common method flashExceptionHandler.
/**
* Extremely low priority exception handler that will automatically
* flashException and redirect for action methods decorated with a
* FlashException annotation. Rethrow if the annotation is
* absent.
*/
@Catch(value = Exception.class, priority = Integer.MAX_VALUE)
public static void flashExceptionHandler(Exception e) throws Exception {
FlashException handler = getActionAnnotation(FlashException.class);
if (handler != null) {
flashException(e);
if (handler.keep()) {
params.flash();
Validation.keep();
}
String action = handler.value();
String[] referrer = handler.referrer();
if (!action.isEmpty()) {
if (!action.contains(".")) {
action = getControllerClass().getName() + "." + action;
}
redirect(action);
} else if (referrer != null && referrer.length > 0) {
Http.Header headerReferrer = request.headers.get("referer");
if (headerReferrer != null && StringUtils.isNotBlank(headerReferrer.value())) {
Pattern p = Pattern.compile(StringUtils.join(referrer, "|"), Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(headerReferrer.value());
if (m.find()) {
redirectToReferrer();
} else {
Logger.error(String.format("The redirect page is not valid base on the FlashException referrer restriction: %s", referrer.toString()));
}
} else {
Logger.error("Unable to redirect. No referrer available in request header");
}
} else {
redirectToReferrer();
}
}
}
Aggregations