mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-09 00:43:23 +01:00
Improve report information.
This commit is contained in:
parent
df52d57a1d
commit
45858f393e
@ -18,16 +18,20 @@
|
|||||||
|
|
||||||
package com.wisemapping.mail;
|
package com.wisemapping.mail;
|
||||||
|
|
||||||
|
import com.wisemapping.filter.UserAgent;
|
||||||
import com.wisemapping.model.Collaboration;
|
import com.wisemapping.model.Collaboration;
|
||||||
import com.wisemapping.model.Mindmap;
|
import com.wisemapping.model.Mindmap;
|
||||||
import com.wisemapping.model.User;
|
import com.wisemapping.model.User;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -150,19 +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) {
|
||||||
|
|
||||||
|
final Map<String, Object> model = new HashMap<String, Object>();
|
||||||
|
model.put("errorMsg", jsErrorMsg);
|
||||||
|
try {
|
||||||
|
model.put("mapXML", StringEscapeUtils.escapeXml(mindmap.getXmlStr()));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
// Ignore ...
|
||||||
|
}
|
||||||
|
model.put("mapId", mindmap.getId());
|
||||||
|
model.put("mapTitle", mindmap.getTitle());
|
||||||
|
|
||||||
|
sendNotification(model, user, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
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("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());
|
||||||
|
|
||||||
try {
|
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("<", "<"));
|
|
||||||
model.put("mapId", mindmap.getId());
|
|
||||||
model.put("mapTitle", mindmap.getTitle());
|
|
||||||
model.put("userAgent", userAgent);
|
|
||||||
model.put("details", "Editor");
|
|
||||||
|
|
||||||
final String errorReporterEmail = mailer.getErrorReporterEmail();
|
final String errorReporterEmail = mailer.getErrorReporterEmail();
|
||||||
if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) {
|
if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) {
|
||||||
mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Bug from '" + (user != null ? user.getEmail() + "'" : "'anonymous'"), model,
|
mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Bug from '" + (user != null ? user.getEmail() + "'" : "'anonymous'"), model,
|
||||||
@ -173,43 +188,19 @@ final public class NotificationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportMindmapExportError(@NotNull String exportContent, @Nullable User user, @Nullable String userAgent, @NotNull Throwable exception) {
|
public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull String content, @NotNull HttpServletRequest request) {
|
||||||
try {
|
final Map<String, Object> model = new HashMap<String, Object>();
|
||||||
final Map<String, Object> model = new HashMap<String, Object>();
|
model.put("errorMsg", stackTraceToString(exception));
|
||||||
model.put("user", user);
|
model.put("mapXML", StringEscapeUtils.escapeXml(content));
|
||||||
model.put("email", (user != null ? user.getEmail() : "'anonymous'"));
|
|
||||||
model.put("errorMsg", stackTraceToString(exception));
|
|
||||||
model.put("mapXML", exportContent.replaceAll("<", "<"));
|
|
||||||
model.put("userAgent", userAgent);
|
|
||||||
model.put("details", "Export");
|
|
||||||
|
|
||||||
final String errorReporterEmail = mailer.getErrorReporterEmail();
|
sendNotification(model, user, request);
|
||||||
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) {
|
public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull HttpServletRequest request) {
|
||||||
try {
|
final Map<String, Object> model = new HashMap<String, Object>();
|
||||||
final Map<String, Object> model = new HashMap<String, Object>();
|
model.put("errorMsg", stackTraceToString(exception));
|
||||||
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();
|
sendNotification(model, user, request);
|
||||||
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 String stackTraceToString(@NotNull Throwable e) {
|
public String stackTraceToString(@NotNull Throwable e) {
|
||||||
|
@ -30,7 +30,7 @@ public class NotifyingExceptionResolver extends SimpleMappingExceptionResolver {
|
|||||||
|
|
||||||
private void sendNotification(@NotNull Exception ex, @NotNull HttpServletRequest request) {
|
private void sendNotification(@NotNull Exception ex, @NotNull HttpServletRequest request) {
|
||||||
final User user = Utils.getUser();
|
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) {
|
public void setExclude(final Set<String> exclude) {
|
||||||
|
@ -26,12 +26,15 @@ import com.wisemapping.security.Utils;
|
|||||||
import com.wisemapping.service.MindmapService;
|
import com.wisemapping.service.MindmapService;
|
||||||
import com.wisemapping.service.UserService;
|
import com.wisemapping.service.UserService;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class AccountController extends BaseController {
|
public class AccountController extends BaseController {
|
||||||
@Qualifier("userService")
|
@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"})
|
@RequestMapping(method = RequestMethod.POST, value = "logger/editor", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
|
||||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
@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 Mindmap mindmap = mindmapService.findMindmapById(item.getMapId());
|
||||||
final User user = Utils.getUser();
|
final User user = Utils.getUser();
|
||||||
logger.error("Unexpected editor error - " + item.getJsErrorMsg());
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,6 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
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.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -62,7 +60,7 @@ public class BaseController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String handleServerErrors(@NotNull Exception ex, @NotNull HttpServletRequest request) {
|
public String handleServerErrors(@NotNull Exception ex, @NotNull HttpServletRequest request) {
|
||||||
final User user = Utils.getUser();
|
final User user = Utils.getUser();
|
||||||
notificationService.reportUnexpectedError(ex, user, request.getHeader(UserAgent.USER_AGENT_HEADER));
|
notificationService.reportJavaException(ex, user, request);
|
||||||
return ex.getMessage();
|
return ex.getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public class TransformView extends AbstractView {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Jaxb2Marshaller jaxbMarshaller;
|
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.contentType = contentType;
|
||||||
this.notificationService = notificationService;
|
this.notificationService = notificationService;
|
||||||
this.exportFormat = ExportFormat.fromContentType(contentType);
|
this.exportFormat = ExportFormat.fromContentType(contentType);
|
||||||
@ -93,7 +93,7 @@ public class TransformView extends AbstractView {
|
|||||||
factory.export(properties, null, outputStream, content);
|
factory.export(properties, null, outputStream, content);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} 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() {
|
public String getContentType() {
|
||||||
return contentType;
|
return contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String IMG_SIZE_PARAMETER = "imgSize";
|
private static final String IMG_SIZE_PARAMETER = "imgSize";
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Details: ${details}</li>
|
<li>User Name: ${fullName}</li>
|
||||||
<li>User Name: ${user.fullName}</li>
|
|
||||||
<li>Email: ${email}</li>
|
<li>Email: ${email}</li>
|
||||||
|
<li>Server: ${server}</li>
|
||||||
|
<li>RequestURI: ${requestURI}</li>
|
||||||
<li>User Agent: ${userAgent}</li>
|
<li>User Agent: ${userAgent}</li>
|
||||||
|
<li>remoteAddress: ${remoteAddress}</li>
|
||||||
|
|
||||||
#if($mapId)
|
#if($mapId)
|
||||||
<li>Mindmap Id: ${mapId}</li>
|
<li>Mindmap Id: ${mapId}</li>
|
||||||
#end
|
#end
|
||||||
|
Loading…
Reference in New Issue
Block a user