Commit bd79cb55 by Riku Silvola

error handling

1 parent 18eb8de1
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<title>Error</title> <title>Error</title>
</h:head> </h:head>
<h:body> <h:body>
<!-- <c:if test="#{sessionHandler.isInDevelopmentMode() eq true}"> --> <!-- <c:if test="#{sessionHandler.isInDevelopmentMode() eq false}"> -->
<h1>#{i18n['error.error']}</h1> <h1>#{i18n['error.error']}</h1>
<p>${i18n['error.contact']} <p>${i18n['error.contact']}
<br/><h:outputText escape="false" style="color: red;" value="#{errorPageView.time}" /><br/><br/> <br/><h:outputText escape="false" style="color: red;" value="#{errorPageView.time}" /><br/><br/>
......
...@@ -18,6 +18,8 @@ import java.io.StringWriter; ...@@ -18,6 +18,8 @@ import java.io.StringWriter;
import java.util.Calendar; import java.util.Calendar;
import java.util.Map; import java.util.Map;
import java.util.zip.CRC32;
@Named @Named
@RequestScoped @RequestScoped
public class ErrorPageView implements Serializable { public class ErrorPageView implements Serializable {
...@@ -34,6 +36,7 @@ public class ErrorPageView implements Serializable { ...@@ -34,6 +36,7 @@ public class ErrorPageView implements Serializable {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(ErrorPageView.class); private static final Logger logger = LoggerFactory.getLogger(ErrorPageView.class);
public String getStackTrace() { public String getStackTrace() {
...@@ -51,14 +54,29 @@ public class ErrorPageView implements Serializable { ...@@ -51,14 +54,29 @@ public class ErrorPageView implements Serializable {
} }
public String getStackTraceHash() {
FacesContext context = FacesContext.getCurrentInstance();
Map requestMap = context.getExternalContext().getRequestMap();
Throwable ex =
(Throwable) requestMap.get("javax.servlet.error.exception");
CRC32 stackHash = new CRC32();
stackHash.update(ex.getStackTrace().toString().getBytes());
return "0x" + Long.toHexString(stackHash.getValue());
}
public String getTime(){ public String getTime(){
return "0x" + Long.toHexString(Calendar.getInstance().getTimeInMillis()); String stamp = "0x" + Long.toHexString(Calendar.getInstance().getTimeInMillis());
logger.error("Error occured at {} trail {}", stamp, getTrail());
return stamp;
} }
public String getTrail() { public String getTrail() {
HttpServletRequest req = (HttpServletRequest) getContext().getExternalContext().getRequest(); HttpServletRequest req = (HttpServletRequest) getContext().getExternalContext().getRequest();
Object trail = req.getSession().getAttribute("trail"); Object trail = req.getSession().getAttribute("trail");
return trail != null ? trail.toString().replace(", ", "\n") : "u gots no trail!"; return trail != null ? trail.toString() : "";
} }
public FacesContext getContext() { public FacesContext getContext() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!