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 ++++++--------------- .../at/gv/egiz/pdfas/web/servlets/SignServlet.java | 32 +--- .../pdfas/web/servlets/VerifyPreviewServlet.java | 33 ++--- .../gv/egiz/pdfas/web/servlets/VerifyServlet.java | 7 - 4 files changed, 71 insertions(+), 165 deletions(-) (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets') 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); + } } } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java index d07b72e..cd2c38a 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java @@ -27,14 +27,12 @@ package at.gv.egiz.pdfas.web.servlets; import java.io.BufferedInputStream; -import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URL; -import java.util.Enumeration; import java.util.Iterator; import java.util.List; @@ -51,13 +49,12 @@ import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import at.gv.egiz.pdfas.api.commons.Constants; import at.gv.egiz.pdfas.api.exceptions.PdfAsException; import at.gv.egiz.pdfas.api.io.DataSource; -import at.gv.egiz.pdfas.api.io.TextBased; import at.gv.egiz.pdfas.api.sign.pos.SignaturePositioning; import at.gv.egiz.pdfas.exceptions.ErrorCode; import at.gv.egiz.pdfas.exceptions.ErrorCodeHelper; @@ -65,10 +62,8 @@ import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException; import at.gv.egiz.pdfas.web.ExternAppInformation; import at.gv.egiz.pdfas.web.FormFields; import at.gv.egiz.pdfas.web.helper.ApiHelper; -import at.gv.egiz.pdfas.web.helper.SessionHelper; import at.gv.egiz.pdfas.web.helper.SignServletHelper; import at.gv.egiz.pdfas.web.helper.WebSettingsReader; -import at.gv.egiz.pdfas.web.helper.WebUtils; import at.gv.egiz.pdfas.web.io.ByteArrayPdfDataSource; import at.gv.egiz.pdfas.web.itext.IText; import at.gv.egiz.pdfas.web.session.SessionAttributes; @@ -99,7 +94,6 @@ public class SignServlet extends HttpServlet * The log. */ private static Log log = LogFactory.getLog(SignServlet.class); - private static Log statLog = LogFactory.getLog("statistic"); @@ -153,10 +147,7 @@ public class SignServlet extends HttpServlet // for performance measurement - long startTime = 0; - if (statLog.isInfoEnabled()) { - startTime = System.currentTimeMillis(); - } + long startTime = System.currentTimeMillis(); // check if pdf-as has been called by external webapp if (request.getParameter(FormFields.FIELD_PDF_URL) != null) @@ -197,9 +188,9 @@ public class SignServlet extends HttpServlet //end added session = request.getSession(true); - + session.setAttribute(SignServlet.SUBMITFORM_FILENAME_KEY, filename); - + // added by tknall if (sig_pos_y != null && sig_pos_p != null && sig_pos_x != null) { if (sig_pos_w != null) { @@ -227,7 +218,7 @@ public class SignServlet extends HttpServlet } - // fixed by tknall: if we already have parameters "&" must be used instead of "?" + // if we already have parameters "&" must be used instead of "?" String paramSeparator = (pdf_url.indexOf("?") != -1) ? "&" : "?"; String query = pdf_url + "/" + filename + paramSeparator + FormFields.FIELD_PDF_ID + "=" + pdf_id; //query = pdf_url; @@ -345,7 +336,7 @@ public class SignServlet extends HttpServlet // ud.pdfDataSource = PdfAS.applyStrictMode(ud.pdfDataSource); session = request.getSession(true); - + SignSessionInformation si = new SignSessionInformation(); // SessionTable.generateSessionInformationObject(); si.connector = ud.sig_app; @@ -405,17 +396,6 @@ public class SignServlet extends HttpServlet SignServletHelper.finishSign(si, request, response, getServletContext()); - // afitzek: moved to DataURL to provide status information OK - ERROR - // for performance measurement - if (statLog.isInfoEnabled()) { - long endTime = System.currentTimeMillis(); -// String toReport = "SIGN;" + si.mode + ";" + si.filename + ";"+ fileSize + ";" + - String toReport = "SIGN;" + si.mode + ";" + si.connector + ";" + si.pdfDataSource.getLength() + ";" + (endTime - startTime); - - //statLog.info(toReport); - // afitzek: save old statistik into log file - log.info(toReport); - } } catch (PresentableException e) { diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyPreviewServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyPreviewServlet.java index 6e8ff64..83c8602 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyPreviewServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/VerifyPreviewServlet.java @@ -76,7 +76,7 @@ public class VerifyPreviewServlet extends HttpServlet * SVUID. */ private static final long serialVersionUID = 6954343542890239109L; - + public static String[] REQUIRED_SIG_KEYS = new String[] { "SIG_DATE", "SIG_ISSUER", "SIG_VALUE", "SIG_NUMBER", "SIG_ID", "SIG_KZ" }; @@ -94,7 +94,7 @@ public class VerifyPreviewServlet extends HttpServlet RequestDispatcher disp = getServletContext().getRequestDispatcher(resource); disp.forward(request, response); } - + protected void dispatchToPreview(HttpServletRequest request, HttpServletResponse response, String signedText, int verify_which)throws ServletException, IOException { request.setAttribute(FormFields.FIELD_VERIFY_WHICH, new Integer(verify_which)); @@ -117,13 +117,13 @@ public class VerifyPreviewServlet extends HttpServlet return backToListURL; } - + protected static String generateNamePrefix(int num) { return SIG_INPUT_PREFIX + num + "_"; } - public static String renderRequiredKeysJavaScript(ServletContext sc, + public static String renderRequiredKeysJavaScript(ServletContext sc, SignatureInformation signatureInfo, String name_prefix) { StringWriter sw = new StringWriter(); @@ -188,7 +188,6 @@ public class VerifyPreviewServlet extends HttpServlet writer.println(" "); value = value.replaceAll("\\s", " "); - // wuhu! replacing all \" with \" value = value.replaceAll("\\\"", "\\\""); String input_key = name_prefix + key; @@ -214,7 +213,7 @@ public class VerifyPreviewServlet extends HttpServlet // Problem: SignatureTypes.SIG_NAME is defined as Signer-RFC2253Name, but there is not certain // key for friendly name (e.g. SIG_SUBJECT or SIG_FOO), therefore we do not know which key contains // the friendly signer name - + // workaround: include "SIG_SUBJECT" since it is usually used String[] rkeys = { "SIG_NAME", "SIG_SUBJECT", "SIG_DATE", "SIG_ISSUER", "SIG_NUMBER"}; // SignatureTypes.REQUIRED_SIG_KEYS; @@ -268,9 +267,9 @@ public class VerifyPreviewServlet extends HttpServlet try { Object sessionObject = SessionHelper.getSession(request); - + VerifySessionInformation si = (VerifySessionInformation)sessionObject; - + int verify_which = -1; boolean preview = false; @@ -288,7 +287,7 @@ public class VerifyPreviewServlet extends HttpServlet } logger_.debug("verify_which = " + verify_which); } - + { String preview_string = request.getParameter(FormFields.FIELD_PREVIEW); if (preview_string.equals("true")) @@ -305,7 +304,7 @@ public class VerifyPreviewServlet extends HttpServlet { throw new SignatureException(312, "The selected signature to be verified doesn't exist."); } - + SignatureInformation sigInfo = (SignatureInformation) si.analyzeResult.getSignatures().get(verify_which); holders_to_verify = new ArrayList(); holders_to_verify.add(sigInfo); @@ -345,7 +344,7 @@ public class VerifyPreviewServlet extends HttpServlet { String dispatch_to = LocalRequestHelper.processLocalVerify(pdfAsInternal, si, holders_to_verify, request, response); dispatch(request, response, dispatch_to); - + return; } @@ -375,12 +374,12 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) try { Object sessionObject = SessionHelper.getSession(request); - + PdfAsInternal pdfAsInternal = ApiHelper.getPdfAsInternalFromContext(getServletContext()); - + VerifySessionInformation si = (VerifySessionInformation)sessionObject; - - + + String text_to_be_verified = null; int verify_which = -1; @@ -407,7 +406,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) verify_which = Integer.parseInt(which_str); continue; } - + if (item.getFieldName().equals("verify")) { if (item.getString("UTF-8").equals("true")) @@ -425,7 +424,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) } si.analyzeResult = pdfAsInternal.analyzeFromRawText(text_to_be_verified, sigValues); - + if (verify == false) { dispatchToDataOk(request, response); 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 aef7f19..af54ddb 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 @@ -165,13 +165,6 @@ public class VerifyServlet extends HttpServlet dispatchToResults(verifyResults, request, response); - // for performance measurement - if (log.isInfoEnabled()) { - long endTime = System.currentTimeMillis(); - String toReport = "VERIFY;"+ ud.file_name + ";"+ 0 + ";" + (endTime - startTime) + ";" + debugVerifyResults(verifyResults); - log.info(toReport); - } - } } -- cgit v1.2.3