aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2015-02-25 09:11:16 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2015-02-25 09:11:16 +0100
commit18a3495d083b8bfd90853c88ffe12c2ff21d0add (patch)
tree40888a1b1da72d901cc29245cc9ee185d7c2e626 /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java
parentb3b6404c36ba320baa27cc6980511f94395d50e9 (diff)
downloadpdf-as-4-18a3495d083b8bfd90853c88ffe12c2ff21d0add.tar.gz
pdf-as-4-18a3495d083b8bfd90853c88ffe12c2ff21d0add.tar.bz2
pdf-as-4-18a3495d083b8bfd90853c88ffe12c2ff21d0add.zip
Nullpointer exception while statistic event processed fixed
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java86
1 files changed, 46 insertions, 40 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java
index 4be3d7dd..670756de 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java
@@ -49,13 +49,13 @@ import at.gv.egiz.pdfas.web.stats.StatisticEvent.Status;
*/
public class ErrorPage extends HttpServlet {
private static final long serialVersionUID = 1L;
-
+
private static final Logger logger = LoggerFactory
.getLogger(ErrorPage.class);
-
+
private static final String ERROR_STACK = "##ERROR_STACK##";
private static final String ERROR_MESSAGE = "##ERROR_MESSAGE##";
-
+
/**
* @see HttpServlet#HttpServlet()
*/
@@ -90,74 +90,80 @@ public class ErrorPage extends HttpServlet {
return;
} else {
String errorURL = PdfAsHelper.getErrorURL(request, response);
- Throwable e = PdfAsHelper
- .getSessionException(request, response);
-
- StatisticEvent statisticEvent = PdfAsHelper.getStatisticEvent(request, response);
- if(!statisticEvent.isLogged()) {
- statisticEvent.setStatus(Status.ERROR);
- statisticEvent.setException(e);
- if(e instanceof PDFASError) {
- statisticEvent.setErrorCode(((PDFASError)e).getCode());
+ Throwable e = PdfAsHelper.getSessionException(request, response);
+
+ StatisticEvent statisticEvent = PdfAsHelper.getStatisticEvent(
+ request, response);
+ if (statisticEvent != null) {
+ if (!statisticEvent.isLogged()) {
+ statisticEvent.setStatus(Status.ERROR);
+ statisticEvent.setException(e);
+ if (e instanceof PDFASError) {
+ statisticEvent.setErrorCode(((PDFASError) e).getCode());
+ }
+ statisticEvent.setEndNow();
+ statisticEvent.setTimestampNow();
+ StatisticFrontend.getInstance().storeEvent(statisticEvent);
+ statisticEvent.setLogged(true);
}
- statisticEvent.setEndNow();
- statisticEvent.setTimestampNow();
- StatisticFrontend.getInstance().storeEvent(statisticEvent);
- statisticEvent.setLogged(true);
}
-
- String message = PdfAsHelper.getSessionErrMessage(request,
- response);
- if (errorURL != null && WebConfiguration.isProvidePdfURLinWhitelist(errorURL)) {
+
+ String message = PdfAsHelper
+ .getSessionErrMessage(request, response);
+ if (errorURL != null
+ && WebConfiguration.isProvidePdfURLinWhitelist(errorURL)) {
String template = PdfAsHelper.getErrorRedirectTemplateSL();
- template = template.replace("##ERROR_URL##",
- errorURL);
-
+ template = template.replace("##ERROR_URL##", errorURL);
+
URL url = new URL(errorURL);
- String extraParams = UrlParameterExtractor.buildParameterFormString(url);
+ String extraParams = UrlParameterExtractor
+ .buildParameterFormString(url);
template = template.replace("##ADD_PARAMS##", extraParams);
-
+
String target = PdfAsHelper.getInvokeTarget(request, response);
-
- if(target == null) {
+
+ if (target == null) {
target = "_self";
}
-
+
template = template.replace("##TARGET##", target);
-
+
if (e != null && WebConfiguration.isShowErrorDetails()) {
template = template.replace("##CAUSE##",
URLEncoder.encode(e.getMessage(), "UTF-8"));
} else {
- template = template.replace("##CAUSE##",
- "");
+ template = template.replace("##CAUSE##", "");
}
if (message != null) {
- template = template.replace("##ERROR##", URLEncoder.encode(message, "UTF-8"));
+ template = template.replace("##ERROR##",
+ URLEncoder.encode(message, "UTF-8"));
} else {
- template = template.replace("##ERROR##", "Unbekannter Fehler");
+ template = template.replace("##ERROR##",
+ "Unbekannter Fehler");
}
response.setContentType("text/html");
response.getWriter().write(template);
response.getWriter().close();
} else {
- if(errorURL != null) {
+ if (errorURL != null) {
logger.warn(errorURL + " is not allowed by whitelist");
}
-
+
String template = PdfAsHelper.getErrorTemplate();
if (message != null) {
template = template.replace(ERROR_MESSAGE, message);
} else {
- template = template.replace(ERROR_MESSAGE, "Unbekannter Fehler");
+ template = template.replace(ERROR_MESSAGE,
+ "Unbekannter Fehler");
}
-
+
if (e != null && WebConfiguration.isShowErrorDetails()) {
- template = template.replace(ERROR_STACK, HTMLFormater.formatStackTrace(e.getStackTrace()));
+ template = template.replace(ERROR_STACK,
+ HTMLFormater.formatStackTrace(e.getStackTrace()));
} else {
- template = template.replace(ERROR_STACK, "");
+ template = template.replace(ERROR_STACK, "");
}
-
+
response.setContentType("text/html");
response.getWriter().write(template);
response.getWriter().close();