From 18a3495d083b8bfd90853c88ffe12c2ff21d0add Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Wed, 25 Feb 2015 09:11:16 +0100 Subject: Nullpointer exception while statistic event processed fixed --- .../at/gv/egiz/pdfas/web/servlets/ErrorPage.java | 86 ++++++++++++---------- .../at/gv/egiz/pdfas/web/servlets/PDFData.java | 66 +++++++++-------- 2 files changed, 82 insertions(+), 70 deletions(-) (limited to 'pdf-as-web/src/main') 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(); diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java index 64bae47e..4fce6860 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java @@ -45,14 +45,11 @@ import at.gv.egiz.pdfas.web.stats.StatisticFrontend; * Servlet implementation class PDFData */ public class PDFData extends HttpServlet { - + private static final long serialVersionUID = 1L; - private static final Logger logger = LoggerFactory - .getLogger(PDFData.class); - - - + private static final Logger logger = LoggerFactory.getLogger(PDFData.class); + /** * @see HttpServlet#HttpServlet() */ @@ -82,49 +79,58 @@ public class PDFData extends HttpServlet { HttpServletResponse response) throws ServletException, IOException { byte[] signedData = PdfAsHelper.getSignedPdf(request, response); - StatisticEvent statisticEvent = PdfAsHelper.getStatisticEvent(request, response); - + StatisticEvent statisticEvent = PdfAsHelper.getStatisticEvent(request, + response); + String plainPDFDigest = PdfAsParameterExtractor.getOrigDigest(request); - + if (signedData != null) { - if(plainPDFDigest != null) { - String signatureDataHash = PdfAsHelper.getSignatureDataHash(request); - if(!plainPDFDigest.equalsIgnoreCase(signatureDataHash)) { + if (plainPDFDigest != null) { + String signatureDataHash = PdfAsHelper + .getSignatureDataHash(request); + if (!plainPDFDigest.equalsIgnoreCase(signatureDataHash)) { logger.warn("Digest Hash mismatch!"); logger.warn("Requested digest: " + plainPDFDigest); logger.warn("Saved digest: " + signatureDataHash); - + PdfAsHelper.setSessionException(request, response, "Signature Data digest do not match!", null); - PdfAsHelper.gotoError(getServletContext(), request, response); + PdfAsHelper.gotoError(getServletContext(), request, + response); return; } } - response.setHeader("Content-Disposition", "inline;filename=" + PdfAsHelper.getPDFFileName(request)); + response.setHeader("Content-Disposition", "inline;filename=" + + PdfAsHelper.getPDFFileName(request)); String pdfCert = PdfAsHelper.getSignerCertificate(request); - if(pdfCert != null) { + if (pdfCert != null) { response.setHeader("Signer-Certificate", pdfCert); } - - if(!statisticEvent.isLogged()) { - statisticEvent.setStatus(Status.OK); - - statisticEvent.setEndNow(); - statisticEvent.setTimestampNow(); - StatisticFrontend.getInstance().storeEvent(statisticEvent); - statisticEvent.setLogged(true); + + if (statisticEvent != null) { + if (!statisticEvent.isLogged()) { + statisticEvent.setStatus(Status.OK); + + statisticEvent.setEndNow(); + statisticEvent.setTimestampNow(); + StatisticFrontend.getInstance().storeEvent(statisticEvent); + statisticEvent.setLogged(true); + } } - - PDFASVerificationResponse resp = PdfAsHelper.getPDFASVerificationResponse(request); - if(resp != null) { - response.setHeader("CertificateCheckCode", String.valueOf(resp.getCertificateCode())); - response.setHeader("ValueCheckCode", String.valueOf(resp.getValueCode())); + + PDFASVerificationResponse resp = PdfAsHelper + .getPDFASVerificationResponse(request); + if (resp != null) { + response.setHeader("CertificateCheckCode", + String.valueOf(resp.getCertificateCode())); + response.setHeader("ValueCheckCode", + String.valueOf(resp.getValueCode())); } response.setContentType("application/pdf"); OutputStream os = response.getOutputStream(); os.write(signedData); os.close(); - + // When data is collected destroy session! request.getSession().invalidate(); } else { -- cgit v1.2.3