Improve report information.

This commit is contained in:
Paulo Gustavo Veiga 2012-08-30 21:23:10 -03:00
parent df52d57a1d
commit 45858f393e
6 changed files with 50 additions and 54 deletions

View File

@ -18,16 +18,20 @@
package com.wisemapping.mail;
import com.wisemapping.filter.UserAgent;
import com.wisemapping.model.Collaboration;
import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
@ -150,58 +154,30 @@ final public class NotificationService {
// }
}
public void reportMindmapEditorError(@NotNull Mindmap mindmap, @Nullable User user, @NotNull String userAgent, @Nullable String jsErrorMsg) {
public void reportJavascriptException(@NotNull Mindmap mindmap, @Nullable User user, @Nullable String jsErrorMsg, @NotNull HttpServletRequest request) {
try {
final Map<String, Object> model = new HashMap<String, Object>();
model.put("user", user);
model.put("email", (user != null ? user.getEmail() : "'anonymous'"));
model.put("errorMsg", jsErrorMsg);
model.put("mapXML", mindmap.getXmlStr().replaceAll("<", "&lt;"));
try {
model.put("mapXML", StringEscapeUtils.escapeXml(mindmap.getXmlStr()));
} catch (UnsupportedEncodingException e) {
// Ignore ...
}
model.put("mapId", mindmap.getId());
model.put("mapTitle", mindmap.getTitle());
model.put("userAgent", userAgent);
model.put("details", "Editor");
final String errorReporterEmail = mailer.getErrorReporterEmail();
if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) {
mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Bug from '" + (user != null ? user.getEmail() + "'" : "'anonymous'"), model,
"errorNotification.vm");
}
} catch (Exception e) {
handleException(e);
}
sendNotification(model, user, request);
}
public void reportMindmapExportError(@NotNull String exportContent, @Nullable User user, @Nullable String userAgent, @NotNull Throwable exception) {
try {
final Map<String, Object> model = new HashMap<String, Object>();
model.put("user", user);
private void sendNotification(@NotNull Map<String, Object> model, @Nullable User user, @NotNull HttpServletRequest request) {
model.put("fullName", (user != null ? user.getFullName() : "'anonymous'"));
model.put("email", (user != null ? user.getEmail() : "'anonymous'"));
model.put("errorMsg", stackTraceToString(exception));
model.put("mapXML", exportContent.replaceAll("<", "&lt;"));
model.put("userAgent", userAgent);
model.put("details", "Export");
model.put("userAgent", request.getHeader(UserAgent.USER_AGENT_HEADER));
model.put("server", request.getScheme() + "://" + request.getServerName() + "/" + request.getServerPort());
model.put("requestURI", request.getRequestURI());
model.put("remoteAddress", request.getRemoteAddr());
final String errorReporterEmail = mailer.getErrorReporterEmail();
if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) {
mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Bug from '" + (user != null ? user.getEmail() + "'" : "'anonymous'"), model,
"errorNotification.vm");
}
} catch (Exception e) {
handleException(e);
}
}
public void reportUnexpectedError(@NotNull Throwable exception, @Nullable User user, @NotNull String userAgent) {
try {
final Map<String, Object> model = new HashMap<String, Object>();
model.put("user", user);
model.put("email", (user != null ? user.getEmail() : "'anonymous'"));
model.put("errorMsg", stackTraceToString(exception));
model.put("userAgent", userAgent);
model.put("details", "Unexpected");
final String errorReporterEmail = mailer.getErrorReporterEmail();
if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) {
mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Bug from '" + (user != null ? user.getEmail() + "'" : "'anonymous'"), model,
@ -212,6 +188,21 @@ final public class NotificationService {
}
}
public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull String content, @NotNull HttpServletRequest request) {
final Map<String, Object> model = new HashMap<String, Object>();
model.put("errorMsg", stackTraceToString(exception));
model.put("mapXML", StringEscapeUtils.escapeXml(content));
sendNotification(model, user, request);
}
public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull HttpServletRequest request) {
final Map<String, Object> model = new HashMap<String, Object>();
model.put("errorMsg", stackTraceToString(exception));
sendNotification(model, user, request);
}
public String stackTraceToString(@NotNull Throwable e) {
String retValue = null;
StringWriter sw = null;

View File

@ -30,7 +30,7 @@ public class NotifyingExceptionResolver extends SimpleMappingExceptionResolver {
private void sendNotification(@NotNull Exception ex, @NotNull HttpServletRequest request) {
final User user = Utils.getUser();
notificationService.reportUnexpectedError(ex, user, request.getHeader("User-Agent"));
notificationService.reportJavaException(ex, user, request);
}
public void setExclude(final Set<String> exclude) {

View File

@ -26,12 +26,15 @@ import com.wisemapping.security.Utils;
import com.wisemapping.service.MindmapService;
import com.wisemapping.service.UserService;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@Controller
public class AccountController extends BaseController {
@Qualifier("userService")
@ -99,11 +102,11 @@ public class AccountController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = "logger/editor", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void changePassword(@RequestBody RestLogItem item) {
public void changePassword(@RequestBody RestLogItem item, @NotNull HttpServletRequest request) {
final Mindmap mindmap = mindmapService.findMindmapById(item.getMapId());
final User user = Utils.getUser();
logger.error("Unexpected editor error - " + item.getJsErrorMsg());
notificationService.reportMindmapEditorError(mindmap, user, item.getUserAgent(), item.getJsErrorMsg() + "\n" + item.getJsStack());
notificationService.reportJavascriptException(mindmap, user, item.getJsErrorMsg() + "\n" + item.getJsStack(), request);
}
}

View File

@ -31,8 +31,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.support.RequestContextUtils;
import org.springframework.web.util.WebUtils;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@ -62,7 +60,7 @@ public class BaseController {
@ResponseBody
public String handleServerErrors(@NotNull Exception ex, @NotNull HttpServletRequest request) {
final User user = Utils.getUser();
notificationService.reportUnexpectedError(ex, user, request.getHeader(UserAgent.USER_AGENT_HEADER));
notificationService.reportJavaException(ex, user, request);
return ex.getMessage();
}

View File

@ -44,7 +44,7 @@ public class TransformView extends AbstractView {
@Autowired
private Jaxb2Marshaller jaxbMarshaller;
public TransformView(@NotNull final String contentType,@NotNull NotificationService notificationService) {
public TransformView(@NotNull final String contentType, @NotNull NotificationService notificationService) {
this.contentType = contentType;
this.notificationService = notificationService;
this.exportFormat = ExportFormat.fromContentType(contentType);
@ -93,7 +93,7 @@ public class TransformView extends AbstractView {
factory.export(properties, null, outputStream, content);
}
} catch (Throwable e) {
notificationService.reportMindmapExportError(content, Utils.getUser(), request.getHeader("User-Agent"),e);
notificationService.reportJavaException(e, Utils.getUser(), content, request);
}
}
@ -101,5 +101,6 @@ public class TransformView extends AbstractView {
public String getContentType() {
return contentType;
}
private static final String IMG_SIZE_PARAMETER = "imgSize";
}

View File

@ -1,10 +1,13 @@
<html>
<body>
<ul>
<li>Details: ${details}</li>
<li>User Name: ${user.fullName}</li>
<li>User Name: ${fullName}</li>
<li>Email: ${email}</li>
<li>Server: ${server}</li>
<li>RequestURI: ${requestURI}</li>
<li>User Agent: ${userAgent}</li>
<li>remoteAddress: ${remoteAddress}</li>
#if($mapId)
<li>Mindmap Id: ${mapId}</li>
#end