use of org.eclipse.kapua.app.console.shared.GwtKapuaException in project kapua by eclipse.
the class FailureHandler method handle.
public static void handle(Throwable caught) {
if (caught instanceof GwtKapuaException) {
GwtKapuaException gee = (GwtKapuaException) caught;
GwtKapuaErrorCode code = gee.getCode();
switch(code) {
case UNAUTHENTICATED:
ConsoleInfo.display(CMSGS.loggedOut(), caught.getLocalizedMessage());
Window.Location.reload();
break;
default:
ConsoleInfo.display(CMSGS.error(), caught.getLocalizedMessage());
Log.error("RPC Error", caught);
break;
}
} else if (caught instanceof StatusCodeException && ((StatusCodeException) caught).getStatusCode() == 0) {
// the current operation was interrupted as the user started a new one
// or navigated away from the page.
// we can ignore this error and do nothing.
} else {
ConsoleInfo.display(CMSGS.error(), caught.getLocalizedMessage());
caught.printStackTrace();
}
}
use of org.eclipse.kapua.app.console.shared.GwtKapuaException in project kapua by eclipse.
the class FailureHandler method handleFormException.
@SuppressWarnings("unchecked")
public static boolean handleFormException(FormPanel form, Throwable caught) {
boolean isWarning = false;
if (caught instanceof GwtKapuaException) {
List<Field<?>> fields = form.getFields();
GwtKapuaException gee = (GwtKapuaException) caught;
GwtKapuaErrorCode code = gee.getCode();
switch(code) {
case INVALID_XSRF_TOKEN:
ConsoleInfo.display(CMSGS.error(), CMSGS.securityInvalidXSRFToken());
Window.Location.reload();
break;
case UNAUTHENTICATED:
ConsoleInfo.display(CMSGS.loggedOut(), caught.getLocalizedMessage());
Window.Location.reload();
break;
case DUPLICATE_NAME:
boolean fieldFound = false;
String duplicateFieldName = gee.getArguments()[0];
for (Field<?> field : fields) {
if (duplicateFieldName.equals(field.getName())) {
TextField<String> textField = (TextField<String>) field;
textField.markInvalid(MSGS.duplicateValue());
fieldFound = true;
break;
}
}
if (!fieldFound) {
ConsoleInfo.display(CMSGS.error(), caught.getLocalizedMessage());
}
break;
case ILLEGAL_NULL_ARGUMENT:
String invalidFieldName = gee.getArguments()[0];
for (Field<?> field : fields) {
if (invalidFieldName.equals(field.getName())) {
TextField<String> textField = (TextField<String>) field;
textField.markInvalid(MSGS.invalidNullValue());
break;
}
}
break;
case ILLEGAL_ARGUMENT:
String invalidFieldName1 = gee.getArguments()[0];
for (Field<?> field : fields) {
if (invalidFieldName1.equals(field.getName())) {
TextField<String> textField = (TextField<String>) field;
textField.markInvalid(gee.getCause().getMessage());
break;
}
}
break;
case CANNOT_REMOVE_LAST_ADMIN:
String adminFieldName = gee.getArguments()[0];
for (Field<?> field : fields) {
if (adminFieldName.equals(field.getName())) {
CheckBoxGroup adminCheckBoxGroup = (CheckBoxGroup) field;
adminCheckBoxGroup.markInvalid(MSGS.lastAdministrator());
break;
}
}
break;
case INVALID_RULE_QUERY:
for (Field<?> field : fields) {
if ("query".equals(field.getName())) {
TextArea statement = (TextArea) field;
statement.markInvalid(caught.getLocalizedMessage());
break;
}
}
break;
case WARNING:
isWarning = true;
ConsoleInfo.display(CMSGS.warning(), caught.getLocalizedMessage());
break;
default:
ConsoleInfo.display(CMSGS.error(), caught.getLocalizedMessage());
caught.printStackTrace();
break;
}
} else {
ConsoleInfo.display(CMSGS.error(), caught.getLocalizedMessage());
caught.printStackTrace();
}
return isWarning;
}
use of org.eclipse.kapua.app.console.shared.GwtKapuaException in project kapua by eclipse.
the class KapuaRemoteServiceServlet method performXSRFTokenValidation.
/**
* This method perform a XSRF validation on the given request and for the specific userToken.
* This is a private method to support both, standard class validation or multipart Servlet validation.
*
* @param req
* @param userToken
*/
private static void performXSRFTokenValidation(HttpServletRequest req, GwtXSRFToken userToken) throws GwtKapuaException {
HttpSession session = req.getSession();
if (!isValidXSRFToken(session, userToken)) {
if (session != null) {
s_logger.info("XSRF token is NOT VALID - Token={}", userToken.getToken());
s_logger.debug("\tSender IP: {}", req.getRemoteAddr());
s_logger.debug("\tSender Host: {}", req.getRemoteHost());
s_logger.debug("\tSender Port: {}", req.getRemotePort());
s_logger.debug("\tFull Request URL\n {}?{}\n\n", req.getRequestURL().toString(), req.getQueryString());
}
// forcing the console log out
session.invalidate();
s_logger.debug("Session invalidated.");
throw new GwtKapuaException(GwtKapuaErrorCode.XSRF_INVALID_TOKEN, null, "Invalid XSRF token");
}
}
Aggregations