diff --git a/core-js/src/main/javascript/Functions.js b/core-js/src/main/javascript/Functions.js index 9bf8ce96..f72b8f83 100644 --- a/core-js/src/main/javascript/Functions.js +++ b/core-js/src/main/javascript/Functions.js @@ -6,17 +6,17 @@ obj - object to inspect */ -$defined = function(obj) { +$defined = function (obj) { return (obj != undefined); }; -$assert = function(assert, message) { +$assert = function (assert, message) { if (!$defined(assert) || !assert) { var stack; try { null.eval(); - } catch(e) { + } catch (e) { stack = e; } console.log(message + "," + stack); @@ -25,7 +25,7 @@ $assert = function(assert, message) { } }; -Math.sign = function(value) { +Math.sign = function (value) { return (value >= 0) ? 1 : -1; }; @@ -34,7 +34,7 @@ function stackTrace() { var isCallstackPopulated = false; try { null.eval(); - } catch(e) { + } catch (e) { if (e.stack) { //Firefox and Chrome... result = e.stack; isCallstackPopulated = true; @@ -60,7 +60,7 @@ function stackTrace() { /*! @source https://gist.github.com/1129031 */ /*global document, DOMParser*/ -(function(DOMParser) { +(function (DOMParser) { "use strict"; var DOMParser_proto = DOMParser.prototype , real_parseFromString = DOMParser_proto.parseFromString; @@ -75,7 +75,7 @@ function stackTrace() { } catch (ex) { } - DOMParser_proto.parseFromString = function(markup, type) { + DOMParser_proto.parseFromString = function (markup, type) { if (/^\s*text\/html\s*(?:;|$)/i.test(type)) { var doc = document.implementation.createHTMLDocument("") @@ -101,9 +101,9 @@ function stackTrace() { }(DOMParser)); // Support for Windows ... -if(!window.console){ +if (!window.console) { console = { - log: function(e){ + log:function (e) { } }; diff --git a/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java b/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java index 8040ec71..1f057a84 100644 --- a/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java +++ b/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java @@ -165,7 +165,7 @@ final public class NotificationService { final String errorReporterEmail = mailer.getErrorReporterEmail(); if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) { mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Editor error from " + user.getEmail(), model, - "editorErrorReport.vm"); + "errorNotification.vm"); } } catch (Exception e) { handleException(e); @@ -183,7 +183,24 @@ final public class NotificationService { final String errorReporterEmail = mailer.getErrorReporterEmail(); if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) { mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Export error from " + user.getEmail(), model, - "editorErrorReport.vm"); + "errorNotification.vm"); + } + } catch (Exception e) { + handleException(e); + } + } + + public void reportUnexpectedError(@NotNull Throwable exception, @Nullable User user, @NotNull String userAgent) { + try { + final Map model = new HashMap(); + model.put("user", user); + model.put("errorMsg", stackTraceToString(exception)); + model.put("userAgent", userAgent); + + final String errorReporterEmail = mailer.getErrorReporterEmail(); + if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) { + mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Unexpected error from " + (user != null ? user.getEmail() : "anonymous"), model, + "errorNotification.vm"); } } catch (Exception e) { handleException(e); diff --git a/wise-webapp/src/main/java/com/wisemapping/mail/NotifyingExceptionResolver.java b/wise-webapp/src/main/java/com/wisemapping/mail/NotifyingExceptionResolver.java new file mode 100644 index 00000000..2abeb15b --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/mail/NotifyingExceptionResolver.java @@ -0,0 +1,43 @@ +package com.wisemapping.mail; + +import com.wisemapping.model.User; +import com.wisemapping.security.Utils; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashSet; +import java.util.Set; + +public class NotifyingExceptionResolver extends SimpleMappingExceptionResolver { + + final private Logger logger = Logger.getLogger("com.wisemapping"); + private Set exclude = new HashSet(); + private NotificationService notificationService; + + @Override + protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { + if (!exclude.contains(ex.getClass().getName())) { + logger.error("An Exception has occurred in the application", ex); + sendNotification(ex, request); + } + + return super.doResolveException(request, response, handler, ex); + } + + private void sendNotification(@NotNull Exception ex, @NotNull HttpServletRequest request) { + final User user = Utils.getUser(); + notificationService.reportUnexpectedError(ex, user, request.getHeader("User-Agent")); + } + + public void setExclude(final Set exclude) { + this.exclude = exclude; + } + + public void setNotificationService(NotificationService notificationService) { + this.notificationService = notificationService; + } +} diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java b/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java index 684f0450..4096738f 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java @@ -18,7 +18,10 @@ package com.wisemapping.rest; +import com.wisemapping.mail.NotificationService; +import com.wisemapping.model.User; import com.wisemapping.rest.model.RestErrors; +import com.wisemapping.security.Utils; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -34,6 +37,9 @@ public class BaseController { @Autowired private ResourceBundleMessageSource messageSource; + @Autowired + private NotificationService notificationService; + @ExceptionHandler(IllegalArgumentException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody @@ -46,14 +52,15 @@ public class BaseController { @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody public String handleServerErrors(@NotNull Exception ex) { - ex.printStackTrace(); + final User user = Utils.getUser(); + notificationService.reportUnexpectedError(ex, user, "unknown browser"); return ex.getMessage(); } @ExceptionHandler(ValidationException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public RestErrors handleValidationErrors(@NotNull ValidationException ex) { - return new RestErrors(ex.getErrors(),messageSource); + return new RestErrors(ex.getErrors(), messageSource); } diff --git a/wise-webapp/src/main/resources/mail/editorErrorReport.vm b/wise-webapp/src/main/resources/mail/errorNotification.vm similarity index 64% rename from wise-webapp/src/main/resources/mail/editorErrorReport.vm rename to wise-webapp/src/main/resources/mail/errorNotification.vm index 672e8a49..30cad499 100644 --- a/wise-webapp/src/main/resources/mail/editorErrorReport.vm +++ b/wise-webapp/src/main/resources/mail/errorNotification.vm @@ -4,16 +4,23 @@
  • User Name: ${user.fullName}
  • Email: ${user.email}
  • User Agent: ${userAgent}
  • -
  • Mindmap Id: ${mapId}
  • -
  • Mindmap Title: ${mapTitle}
  • + #if($mapId) +
  • Mindmap Id: ${mapId}
  • + #end + #if($mapTitle) +
  • Mindmap Title: ${mapTitle}
  • + #end +
         ${errorMsg}
     
    +#if($mapXML)
         ${mapXML}
     
    +#end \ No newline at end of file diff --git a/wise-webapp/src/main/webapp/WEB-INF/app.properties b/wise-webapp/src/main/webapp/WEB-INF/app.properties index 6f23fc28..01fe8dfc 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/app.properties +++ b/wise-webapp/src/main/webapp/WEB-INF/app.properties @@ -58,7 +58,7 @@ mail.serverSendEmail=root@localhost mail.supportEmail=root@localhost # Optional: Unexpected errors will be reported to this address. -mail.errorReporterEmail= +mail.errorReporterEmail=support@wisemapping.com ################################################################################## # Users Registration Configuration diff --git a/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml b/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml index f2df344f..858ccfef 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml @@ -50,11 +50,25 @@ + + + + + + + + + + + + + + @@ -68,16 +82,6 @@ - - - - - - - - - - diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml index 9b55b5a3..f2fe9516 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml @@ -54,7 +54,7 @@ + class="com.wisemapping.mail.NotifyingExceptionResolver"> @@ -65,6 +65,14 @@ securityError + + + java.lang.reflect.UndeclaredThrowableException + com.wisemapping.exceptions.GoogleChromeFrameRequiredException + com.wisemapping.exceptions.UnsupportedBrowserException + + + diff --git a/wise-webapp/src/main/webapp/jsp/errorTemplate.jsp b/wise-webapp/src/main/webapp/jsp/errorTemplate.jsp index 09b478a9..c8075e94 100644 --- a/wise-webapp/src/main/webapp/jsp/errorTemplate.jsp +++ b/wise-webapp/src/main/webapp/jsp/errorTemplate.jsp @@ -1,14 +1,8 @@ -<%@ page import="org.apache.log4j.Logger" %> -<%@ page import="com.wisemapping.security.Utils" %> -<%@ page import="com.wisemapping.model.User" %> <%@ page autoFlush="true" buffer="none" %> <%@ include file="/jsp/init.jsp" %> -<%! - final Logger logger = Logger.getLogger("com.wisemapping"); -%>

    @@ -16,21 +10,4 @@ -