From db52e4d66d60184d53a27ba4d6772461daacc03d Mon Sep 17 00:00:00 2001 From: tknall Date: Fri, 22 Mar 2013 08:57:51 +0000 Subject: Maintenance update (bugfixes, new features, cleanup...) Refer to /dok/RELEASE_NOTES-3.3.txt for further information. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/pdf-as/trunk@931 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../gv/egiz/pdfas/web/servlets/DataURLServlet.java | 164 ++++++--------------- 1 file changed, 49 insertions(+), 115 deletions(-) (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/DataURLServlet.java') 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 1f3d7ed..8afae1f 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 @@ -28,7 +28,6 @@ import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.net.URL; import java.util.ArrayList; -import java.util.Enumeration; import java.util.Iterator; import java.util.List; @@ -52,12 +51,15 @@ import at.gv.egiz.pdfas.api.PdfAs; import at.gv.egiz.pdfas.api.commons.Constants; import at.gv.egiz.pdfas.api.commons.SignatureInformation; import at.gv.egiz.pdfas.api.exceptions.PdfAsException; -import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException; -import at.gv.egiz.pdfas.exceptions.web.SessionExpiredException; import at.gv.egiz.pdfas.api.internal.LocalBKUParams; import at.gv.egiz.pdfas.api.internal.PdfAsInternal; import at.gv.egiz.pdfas.api.verify.VerifyResult; import at.gv.egiz.pdfas.api.verify.VerifyResults; +import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException; +import at.gv.egiz.pdfas.exceptions.web.SessionExpiredException; +import at.gv.egiz.pdfas.framework.logging.StatisticData; +import at.gv.egiz.pdfas.framework.logging.StatisticLogFactory; +import at.gv.egiz.pdfas.framework.logging.StatisticLogger; import at.gv.egiz.pdfas.web.LocalRequest; import at.gv.egiz.pdfas.web.helper.ApiHelper; import at.gv.egiz.pdfas.web.helper.LocalRequestHelper; @@ -67,10 +69,8 @@ import at.gv.egiz.pdfas.web.helper.SigningTimeHelper; import at.gv.egiz.pdfas.web.session.SessionAttributes; import at.gv.egiz.pdfas.web.session.SignSessionInformation; import at.gv.egiz.pdfas.web.session.VerifySessionInformation; -import at.gv.egiz.pdfas.web.servlets.SignServlet; import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; -import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException; import at.knowcenter.wag.egov.egiz.exceptions.SignatureException; /** @@ -90,7 +90,7 @@ public class DataURLServlet extends HttpServlet { private static Log log = LogFactory.getLog(DataURLServlet.class); // stat Log - private static Log statLog = LogFactory.getLog("statistic"); + private static StatisticLogger statLog = StatisticLogFactory.getLog(Constants.STATISTIC_LOGGER_NAME); protected void dispatch(HttpServletRequest request, HttpServletResponse response, String resource) @@ -145,7 +145,7 @@ public class DataURLServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("Data URL is accessed."); //$NON-NLS-1$ - + Object sessionObject = null; try { sessionObject = SessionHelper.getSession(request); @@ -161,86 +161,37 @@ public class DataURLServlet extends HttpServlet { VerifySessionInformation si = (VerifySessionInformation) sessionObject; processVerify(request, response, si); } - } catch (ExternalErrorException f) { - - if (statLog.isInfoEnabled()) { - + } catch (PdfAsException e) { + if (statLog.isEnabled()) { String ua = request.getHeader("User-Agent"); - long endTime = System.currentTimeMillis(); - // String toReport = "SIGN;" + si.mode + ";" + si.filename + - // ";"+ fileSize + ";" + - - String toReport = null; + StatisticData statisticData = new StatisticData(); + statisticData.setException(new SessionExpiredException("Session lost?")); + statisticData.setUserAgent(ua); if (sessionObject != null) { + statisticData.setException(e); if (sessionObject instanceof SignSessionInformation) { SignSessionInformation si = (SignSessionInformation) sessionObject; - toReport = "SIGN;" + si.mode + ";" + si.connector + ";" - + si.pdfDataSource.getLength() + ";" - + (endTime - si.startTime) + ";ERROR;" + ua; + statisticData.setOperation("SIGN").setSignatureMode(si.mode).setConnector(si.connector) + .setFileSize(si.pdfDataSource.getLength()).setDuration(endTime - si.startTime) + .setSignatureProfileId(si.type); } else { VerifySessionInformation si = (VerifySessionInformation) sessionObject; - try { - toReport = "VERIFY;"+ si.file_name + ";"+ 0 + ";" + (endTime - si.startTime) + ";" + VerifyServlet.debugVerifyResults(si.verifyResults) + ";ERROR;" + ua; - } catch (SettingNotFoundException e1) { - toReport = "VERIFY;"+ si.file_name + ";"+ 0 + ";" + (endTime - si.startTime) + ";ERROR-debug-verify" + ";ERROR;" + ua; - } + statisticData.setOperation("VERIFY").setSignatureMode(si.mode).setConnector(si.connector) + .setFileSize(si.inputDataSource.getLength()).setDuration(endTime - si.startTime) + .setSignatureProfileId(si.type); } } - - if(toReport != null) - { - statLog.info(toReport); - } - else - { - statLog.info(";;;;;session-ERROR"); - } + statLog.log(statisticData); } - log.error(f.getMessage(), f); - HttpSession session = request.getSession(true); - session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, "false"); - log.debug("Attribute ERROR_WITHIN_IFRAME: " - + session.getAttribute(SignServlet.ERROR_WITHIN_IFRAME)); - SignServlet.prepareDispatchToErrorPage(f, request); - dispatch(request, response, "/jsp/error.jsp"); - - } catch (PdfAsException e) { - - if (statLog.isInfoEnabled()) { - long endTime = System.currentTimeMillis(); - // String toReport = "SIGN;" + si.mode + ";" + si.filename + - // ";"+ fileSize + ";" + - - String toReport = null; - if (sessionObject != null) { - if (sessionObject instanceof SignSessionInformation) { - SignSessionInformation si = (SignSessionInformation) sessionObject; - toReport = "SIGN;" + si.mode + ";" + si.connector + ";" - + si.pdfDataSource.getLength() + ";" - + (endTime - si.startTime) + ";ERROR"; - } else { - VerifySessionInformation si = (VerifySessionInformation) sessionObject; - try { - toReport = "VERIFY;"+ si.file_name + ";"+ 0 + ";" + (endTime - si.startTime) + ";" + VerifyServlet.debugVerifyResults(si.verifyResults) + ";ERROR"; - } catch (SettingNotFoundException e1) { - toReport = "VERIFY;"+ si.file_name + ";"+ 0 + ";" + (endTime - si.startTime) + ";ERROR-debug-verify" + ";ERROR"; - } - } - } + log.error(e); - if(toReport != null) - { - statLog.info(toReport); - } - else - { - statLog.info(";;;;;session-ERROR"); - } + if (e instanceof ExternalErrorException) { + HttpSession session = request.getSession(true); + session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, "false"); + log.debug("Attribute ERROR_WITHIN_IFRAME: " + session.getAttribute(SignServlet.ERROR_WITHIN_IFRAME)); } - - log.error(e.getMessage(), e); SignServlet.prepareDispatchToErrorPage(e, request); dispatch(request, response, "/jsp/error.jsp"); } @@ -404,16 +355,12 @@ public class DataURLServlet extends HttpServlet { "Das detached XML kann nicht direkt durch die BKU geschliffen werden, weil diese es als Request interpretieren w\u00FCrde. Daher das XML als Text:"); response.getWriter().println( new String(si.signedPdf, "UTF-8")); - if (statLog.isInfoEnabled()) { + if (statLog.isEnabled()) { long endTime = System.currentTimeMillis(); - // String toReport = "SIGN;" + si.mode + ";" + - // si.filename + ";"+ fileSize + ";" + - String toReport = "SIGN;" + si.mode + ";" - + si.connector + ";" - + si.pdfDataSource.getLength() + ";" - + (endTime - si.startTime) + ";OK;" + userAgent; - - statLog.info(toReport); + StatisticData statisticData = new StatisticData("SIGN", si.connector, + si.pdfDataSource.getLength(), si.mode, endTime - si.startTime, userAgent); + statisticData.setSignatureProfileId(si.type); + statLog.log(statisticData); } } else { // tzefferer: If PDF-AS has been called by an external @@ -423,16 +370,12 @@ public class DataURLServlet extends HttpServlet { if (si.exappinf != null) { log.debug("Entering external application interface mode. Skipping redirection to download page."); // afitzek - if (statLog.isInfoEnabled()) { + if (statLog.isEnabled()) { long endTime = System.currentTimeMillis(); - // String toReport = "SIGN;" + si.mode + ";" + - // si.filename + ";"+ fileSize + ";" + - String toReport = "SIGN;" + si.mode + ";" - + si.connector + ";" - + si.pdfDataSource.getLength() + ";" - + (endTime - si.startTime) + ";OK;" + userAgent; - - statLog.info(toReport); + StatisticData statisticData = new StatisticData("SIGN EXTERNAL", si.connector, + si.pdfDataSource.getLength(), si.mode, endTime - si.startTime, userAgent); + statisticData.setSignatureProfileId(si.type); + statLog.log(statisticData); } SignServletHelper.returnSignResponse(si, request, response); @@ -463,17 +406,12 @@ public class DataURLServlet extends HttpServlet { SessionAttributes.DOWNLOAD_URL_FOR_SIGNED_PDF_DOCUMENT, downloadURL); // afitzek - if (statLog.isInfoEnabled()) { + if (statLog.isEnabled()) { long endTime = System.currentTimeMillis(); - String timeDiff = "----"; - // String toReport = "SIGN;" + si.mode + ";" + - // si.filename + ";"+ fileSize + ";" + - String toReport = "SIGN;" + si.mode + ";" - + si.connector + ";" - + si.pdfDataSource.getLength() + ";" - + (endTime - si.startTime) + ";OK;" + userAgent; - - statLog.info(toReport); + StatisticData statisticData = new StatisticData("SIGN", si.connector, + si.pdfDataSource.getLength(), si.mode, endTime - si.startTime, userAgent); + statisticData.setSignatureProfileId(si.type); + statLog.log(statisticData); } temporaryRedirect( response.encodeRedirectURL(LocalRequestHelper @@ -503,7 +441,7 @@ public class DataURLServlet extends HttpServlet { log.trace("processVerify"); String userAgent = request.getHeader("user-agent"); - + String xml_response = request.getParameter("XMLResponse"); //$NON-NLS-1$ log.debug("xml_response = " + xml_response); //$NON-NLS-1$ @@ -555,21 +493,17 @@ public class DataURLServlet extends HttpServlet { return resList; } }; - dispatchToResults(results, request, response, backToListURL); - if (statLog.isInfoEnabled()) { + if (statLog.isEnabled()) { long endTime = System.currentTimeMillis(); - // String toReport = "SIGN;" + si.mode + ";" + si.filename + - // ";"+ fileSize + ";" + - String toReport = null; - try { - toReport = "VERIFY;"+ si.file_name + ";"+ 0 + ";" + (endTime - si.startTime) + ";" + VerifyServlet.debugVerifyResults(si.verifyResults) + ";OK;" + userAgent; - } catch (SettingNotFoundException e1) { - toReport = "VERIFY;"+ si.file_name + ";"+ 0 + ";" + (endTime - si.startTime) + ";ERROR-debug-verify" + ";OK;" + userAgent; - } - - statLog.info(toReport); + StatisticData statisticData = new StatisticData("VERIFY", si.connector, si.inputDataSource.getLength()); + statisticData.setDuration(endTime - si.startTime); + statisticData.setUserAgent(request.getHeader("User-Agent")); + statLog.log(statisticData); } + + dispatchToResults(results, request, response, backToListURL); + } } } -- cgit v1.2.3