diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2015-02-23 11:27:59 +0100 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2015-02-23 11:27:59 +0100 |
commit | 4973b940cc8ce0885653ed7c0223cbedd3dde3bc (patch) | |
tree | d711ed5b272631c9a24cd346a19e2c0b6426f83e /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets | |
parent | fee3c9a59945a2ee74029dfe63c074c753a51dbf (diff) | |
download | pdf-as-4-4973b940cc8ce0885653ed7c0223cbedd3dde3bc.tar.gz pdf-as-4-4973b940cc8ce0885653ed7c0223cbedd3dde3bc.tar.bz2 pdf-as-4-4973b940cc8ce0885653ed7c0223cbedd3dde3bc.zip |
added Statistics Facilities to PDF-AS Web
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets')
6 files changed, 171 insertions, 11 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/DataURLServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/DataURLServlet.java index 86bef9f3..5b3fe82a 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/DataURLServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/DataURLServlet.java @@ -26,6 +26,7 @@ package at.gv.egiz.pdfas.web.servlets; import java.io.IOException; import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -44,6 +45,7 @@ import at.gv.egiz.sl.util.SLMarschaller; /** * Servlet implementation class DataURL */ +@MultipartConfig public class DataURLServlet extends HttpServlet { private static final long serialVersionUID = 1L; 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 8e59ff1c..4be3d7dd 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 @@ -35,10 +35,14 @@ import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.web.config.WebConfiguration; import at.gv.egiz.pdfas.web.helper.HTMLFormater; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; import at.gv.egiz.pdfas.web.helper.UrlParameterExtractor; +import at.gv.egiz.pdfas.web.stats.StatisticEvent; +import at.gv.egiz.pdfas.web.stats.StatisticFrontend; +import at.gv.egiz.pdfas.web.stats.StatisticEvent.Status; /** * Servlet implementation class ErrorPage @@ -88,6 +92,20 @@ public class ErrorPage extends HttpServlet { 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()); + } + statisticEvent.setEndNow(); + statisticEvent.setTimestampNow(); + StatisticFrontend.getInstance().storeEvent(statisticEvent); + statisticEvent.setLogged(true); + } + String message = PdfAsHelper.getSessionErrMessage(request, response); if (errorURL != null && WebConfiguration.isProvidePdfURLinWhitelist(errorURL)) { diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java index 120b9811..bd0bd935 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java @@ -38,14 +38,21 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter.SignatureVerificationLevel; import at.gv.egiz.pdfas.web.config.WebConfiguration; import at.gv.egiz.pdfas.web.exception.PdfAsWebException; +import at.gv.egiz.pdfas.web.filter.UserAgentFilter; import at.gv.egiz.pdfas.web.helper.DigestHelper; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; import at.gv.egiz.pdfas.web.helper.PdfAsParameterExtractor; import at.gv.egiz.pdfas.web.helper.RemotePDFFetcher; +import at.gv.egiz.pdfas.web.stats.StatisticEvent; +import at.gv.egiz.pdfas.web.stats.StatisticFrontend; +import at.gv.egiz.pdfas.web.stats.StatisticEvent.Operation; +import at.gv.egiz.pdfas.web.stats.StatisticEvent.Source; +import at.gv.egiz.pdfas.web.stats.StatisticEvent.Status; /** * Servlet implementation class Sign @@ -90,6 +97,12 @@ public class ExternSignServlet extends HttpServlet { String errorUrl = PdfAsParameterExtractor.getInvokeErrorURL(request); PdfAsHelper.setErrorURL(request, response, errorUrl); + StatisticEvent statisticEvent = new StatisticEvent(); + statisticEvent.setStartNow(); + statisticEvent.setSource(Source.WEB); + statisticEvent.setOperation(Operation.SIGN); + statisticEvent.setUserAgent(UserAgentFilter.getUserAgent()); + try { // Mandatory Parameters on Get Request: String invokeUrl = PdfAsParameterExtractor.getInvokeURL(request); @@ -106,8 +119,19 @@ public class ExternSignServlet extends HttpServlet { } byte[] pdfData = RemotePDFFetcher.fetchPdfFile(pdfUrl); - doSignature(request, response, pdfData); + doSignature(request, response, pdfData, statisticEvent); } catch (Exception e) { + + 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); + PdfAsHelper.setSessionException(request, response, e.getMessage(), e); PdfAsHelper.gotoError(getServletContext(), request, response); @@ -128,6 +152,12 @@ public class ExternSignServlet extends HttpServlet { String errorUrl = PdfAsParameterExtractor.getInvokeErrorURL(request); PdfAsHelper.setErrorURL(request, response, errorUrl); + StatisticEvent statisticEvent = new StatisticEvent(); + statisticEvent.setStartNow(); + statisticEvent.setSource(Source.WEB); + statisticEvent.setOperation(Operation.SIGN); + statisticEvent.setUserAgent(UserAgentFilter.getUserAgent()); + try { byte[] filecontent = null; @@ -225,14 +255,33 @@ public class ExternSignServlet extends HttpServlet { if(source.equals("internal")) { request.setAttribute("FILEERR", true); request.getRequestDispatcher("index.jsp").forward(request, response); + + statisticEvent.setStatus(Status.ERROR); + statisticEvent.setException(new Exception("No file uploaded")); + statisticEvent.setEndNow(); + statisticEvent.setTimestampNow(); + StatisticFrontend.getInstance().storeEvent(statisticEvent); + statisticEvent.setLogged(true); + return; } } throw new PdfAsException("No Signature data available"); } - doSignature(request, response, filecontent); + doSignature(request, response, filecontent, statisticEvent); } catch (Exception e) { + + 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); + PdfAsHelper.setSessionException(request, response, e.getMessage(), e); PdfAsHelper.gotoError(getServletContext(), request, response); @@ -240,11 +289,15 @@ public class ExternSignServlet extends HttpServlet { } protected void doSignature(HttpServletRequest request, - HttpServletResponse response, byte[] pdfData) throws Exception { + HttpServletResponse response, byte[] pdfData, StatisticEvent statisticEvent) throws Exception { // Get Connector String connector = PdfAsParameterExtractor.getConnector(request); String transactionId = PdfAsParameterExtractor.getTransactionId(request); + + statisticEvent.setFilesize(pdfData.length); + statisticEvent.setProfileId(null); + statisticEvent.setDevice(connector); String invokeUrl = PdfAsParameterExtractor.getInvokeURL(request); PdfAsHelper.setInvokeURL(request, response, invokeUrl); @@ -300,6 +353,8 @@ public class ExternSignServlet extends HttpServlet { } } + PdfAsHelper.setStatisticEvent(request, response, statisticEvent); + PdfAsHelper.startSignature(request, response, getServletContext(), pdfData, connector, PdfAsHelper.buildPosString(request, response), transactionId, PdfAsParameterExtractor .getSigType(request), PdfAsParameterExtractor.getPreProcessorMap(request)); @@ -334,9 +389,18 @@ public class ExternSignServlet extends HttpServlet { } } + + byte[] pdfSignedData = PdfAsHelper.synchornousSignature(request, response, pdfData); PdfAsHelper.setSignedPdf(request, response, pdfSignedData); + + statisticEvent.setStatus(Status.OK); + statisticEvent.setEndNow(); + statisticEvent.setTimestampNow(); + StatisticFrontend.getInstance().storeEvent(statisticEvent); + statisticEvent.setLogged(true); + PdfAsHelper.gotoProvidePdf(getServletContext(), request, response); return; } else { 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 483b9707..64bae47e 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 @@ -37,6 +37,9 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.api.ws.PDFASVerificationResponse; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; import at.gv.egiz.pdfas.web.helper.PdfAsParameterExtractor; +import at.gv.egiz.pdfas.web.stats.StatisticEvent; +import at.gv.egiz.pdfas.web.stats.StatisticEvent.Status; +import at.gv.egiz.pdfas.web.stats.StatisticFrontend; /** * Servlet implementation class PDFData @@ -79,6 +82,8 @@ public class PDFData extends HttpServlet { HttpServletResponse response) throws ServletException, IOException { byte[] signedData = PdfAsHelper.getSignedPdf(request, response); + StatisticEvent statisticEvent = PdfAsHelper.getStatisticEvent(request, response); + String plainPDFDigest = PdfAsParameterExtractor.getOrigDigest(request); if (signedData != null) { @@ -101,6 +106,15 @@ public class PDFData extends HttpServlet { response.setHeader("Signer-Certificate", pdfCert); } + 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())); diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java index 53be36da..7100af3b 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java @@ -43,6 +43,7 @@ import at.gv.egiz.pdfas.web.exception.PdfAsStoreException; import at.gv.egiz.pdfas.web.exception.PdfAsWebException; import at.gv.egiz.pdfas.web.helper.DigestHelper; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; +import at.gv.egiz.pdfas.web.stats.StatisticEvent; import at.gv.egiz.pdfas.web.store.RequestStore; public class UIEntryPointServlet extends HttpServlet { @@ -85,6 +86,11 @@ public class UIEntryPointServlet extends HttpServlet { + " value"); } + StatisticEvent statisticEvent = RequestStore.getInstance() + .fetchStatisticEntry(storeId); + + PdfAsHelper.setStatisticEvent(req, resp, statisticEvent); + Connector connector = pdfAsRequest.getParameters().getConnector(); String invokeUrl = pdfAsRequest.getParameters().getInvokeURL(); @@ -149,16 +155,16 @@ public class UIEntryPointServlet extends HttpServlet { } } Map<String, String> map = null; - if(pdfAsRequest.getParameters().getPreprocessor() != null) { - map = pdfAsRequest.getParameters().getPreprocessor().getMap(); + if (pdfAsRequest.getParameters().getPreprocessor() != null) { + map = pdfAsRequest.getParameters().getPreprocessor() + .getMap(); } - + PdfAsHelper.startSignature(req, resp, getServletContext(), pdfAsRequest.getInputData(), connector.toString(), pdfAsRequest.getParameters().getPosition(), pdfAsRequest.getParameters().getTransactionId(), - pdfAsRequest.getParameters().getProfile(), - map); + pdfAsRequest.getParameters().getProfile(), map); } else { throw new PdfAsWebException("Invalid connector (" + Connector.BKU + " | " + Connector.ONLINEBKU + " | " diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java index 32bb41ac..a8beffeb 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyServlet.java @@ -38,15 +38,22 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter.SignatureVerificationLevel; import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; import at.gv.egiz.pdfas.web.exception.PdfAsWebException; +import at.gv.egiz.pdfas.web.filter.UserAgentFilter; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; import at.gv.egiz.pdfas.web.helper.PdfAsParameterExtractor; import at.gv.egiz.pdfas.web.helper.RemotePDFFetcher; import at.gv.egiz.pdfas.web.helper.VerifyEncoder; import at.gv.egiz.pdfas.web.helper.VerifyResultEncoder; +import at.gv.egiz.pdfas.web.stats.StatisticEvent; +import at.gv.egiz.pdfas.web.stats.StatisticFrontend; +import at.gv.egiz.pdfas.web.stats.StatisticEvent.Operation; +import at.gv.egiz.pdfas.web.stats.StatisticEvent.Source; +import at.gv.egiz.pdfas.web.stats.StatisticEvent.Status; /** * Servlet implementation class VerifyServlet @@ -81,6 +88,13 @@ public class VerifyServlet extends HttpServlet { String errorUrl = PdfAsParameterExtractor.getInvokeErrorURL(request); PdfAsHelper.setErrorURL(request, response, errorUrl); + + StatisticEvent statisticEvent = new StatisticEvent(); + statisticEvent.setStartNow(); + statisticEvent.setSource(Source.WEB); + statisticEvent.setOperation(Operation.VERIFY); + statisticEvent.setUserAgent(UserAgentFilter.getUserAgent()); + try { // Mandatory Parameters on Get Request: String invokeUrl = PdfAsParameterExtractor.getInvokeURL(request); @@ -97,8 +111,19 @@ public class VerifyServlet extends HttpServlet { } byte[] pdfData = RemotePDFFetcher.fetchPdfFile(pdfUrl); - doVerify(request, response, pdfData); + doVerify(request, response, pdfData, statisticEvent); } catch (Throwable e) { + + 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); + logger.warn("Generic Error: ", e); PdfAsHelper.setSessionException(request, response, e.getMessage(), e); @@ -118,6 +143,12 @@ public class VerifyServlet extends HttpServlet { String errorUrl = PdfAsParameterExtractor.getInvokeErrorURL(request); PdfAsHelper.setErrorURL(request, response, errorUrl); + StatisticEvent statisticEvent = new StatisticEvent(); + statisticEvent.setStartNow(); + statisticEvent.setSource(Source.WEB); + statisticEvent.setOperation(Operation.VERIFY); + statisticEvent.setUserAgent(UserAgentFilter.getUserAgent()); + try { byte[] filecontent = null; @@ -225,14 +256,33 @@ public class VerifyServlet extends HttpServlet { request.setAttribute("FILEERR", true); request.getRequestDispatcher("index.jsp").forward( request, response); + + statisticEvent.setStatus(Status.ERROR); + statisticEvent.setException(new Exception("No file uploaded")); + statisticEvent.setEndNow(); + statisticEvent.setTimestampNow(); + StatisticFrontend.getInstance().storeEvent(statisticEvent); + statisticEvent.setLogged(true); + return; } } throw new PdfAsException("No Signature data available"); } - doVerify(request, response, filecontent); + doVerify(request, response, filecontent, statisticEvent); } catch (Throwable e) { + + 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); + logger.warn("Generic Error: ", e); PdfAsHelper.setSessionException(request, response, e.getMessage(), e); @@ -241,7 +291,7 @@ public class VerifyServlet extends HttpServlet { } protected void doVerify(HttpServletRequest request, - HttpServletResponse response, byte[] pdfData) throws Exception { + HttpServletResponse response, byte[] pdfData, StatisticEvent statisticEvent) throws Exception { SignatureVerificationLevel lvl = PdfAsParameterExtractor .getVerificationLevel(request); @@ -270,6 +320,12 @@ public class VerifyServlet extends HttpServlet { encoder = VerifyEncoder.getEncoder(PdfAsParameterExtractor.PARAM_HTML); } + statisticEvent.setStatus(Status.OK); + statisticEvent.setEndNow(); + statisticEvent.setTimestampNow(); + StatisticFrontend.getInstance().storeEvent(statisticEvent); + statisticEvent.setLogged(true); + encoder.produce(request, response, results); } |