From 3f54d90a546fd84af1b27ed8db51d59eaa33906b Mon Sep 17 00:00:00 2001 From: knowcenter Date: Mon, 3 Sep 2007 08:17:32 +0000 Subject: =?UTF-8?q?R=C3=BCckbau=20auf=20LocRef-Connector=20f=C3=BCr=20Webs?= =?UTF-8?q?ervice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@205 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../knowcenter/wag/egov/egiz/commandline/Main.java | 71 ++++++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java index e2f8196..b0c7c30 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java @@ -24,6 +24,7 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; +import java.util.Date; import java.util.Iterator; import java.util.List; @@ -454,12 +455,22 @@ public abstract class Main PrintWriter messageOutput) throws PresentableException { messageOutput.println("Signing..."); + + // for performance measurement + long startTime = 0; + long fileSize = 0; + if (logger_.isInfoEnabled()) { + startTime = System.currentTimeMillis(); + } PdfDataSource pdfDataSource; try { File file = new File(input); pdfDataSource = new FileBasedPdfDataSourceImpl(file, (int)file.length()); + if (logger_.isDebugEnabled()) + fileSize = file.length(); + } catch (IOException e) { @@ -470,6 +481,7 @@ public abstract class Main try { File outputFile = new File(output); + dataSink = new FileBasedDataSink(outputFile); } catch (IOException e) @@ -479,23 +491,39 @@ public abstract class Main processSign(pdfDataSource, connector, signature_mode, signature_type, pos_string, dataSink); + // for performance measurement + if (logger_.isInfoEnabled()) { + long endTime = System.currentTimeMillis(); + String toReport = "SIGN;" + signature_mode + ";" + input + ";"+ fileSize + ";" + (endTime - startTime); + logger_.info(toReport); + } + messageOutput.println("Signing was successful."); } public static void carryOutVerify(String input, String connector, int verify_which, PrintWriter messageOutput) throws PresentableException { messageOutput.println("Verifying..."); - + + // for performance measurement + long startTime = 0; + long fileSize = 0; + if (logger_.isInfoEnabled()) { + startTime = System.currentTimeMillis(); + } + DataSource dataSource = null; try { File file = new File(input); + if (logger_.isDebugEnabled()) + fileSize = file.length(); String extension = VerifyServlet.extractExtension(input); if (extension != null && extension.equals("txt")) { try { - FileInputStream fis = new FileInputStream(file); + FileInputStream fis = new FileInputStream(file); byte[] input_bytes = new byte[(int) file.length()]; fis.read(input_bytes); fis.close(); @@ -522,6 +550,15 @@ public abstract class Main messageOutput.println("Verification results:"); formatVerifyResults(results, messageOutput); + + // for performance measurement + if (logger_.isInfoEnabled()) { + long endTime = System.currentTimeMillis(); + String toReport = "VERIFY;"+ input + ";"+ fileSize + ";" + (endTime - startTime) + ";" + debugVerifyResults(results); + logger_.info(toReport); + } + + } public static void processSign(PdfDataSource pdfDataSource, String connector, String signature_mode, String signature_type, String pos_string, DataSink dataSink) throws PresentableException @@ -546,7 +583,7 @@ public abstract class Main PdfASID signatorId = translateSignatureModeToPdfASID(signature_mode); // TODO MOA detached signing is not allowed at the commandline - logger_.debug("Suggested sign algorithm = " + signatorId); +// logger_.debug("Suggested sign algorithm = " + signatorId); if (connector.equals("moa")) { // TODO: possible new implementation of moa where is commandline call @@ -566,7 +603,7 @@ public abstract class Main // signatorId = TextualSignator_1_0_0.MY_ID; // } } - logger_.debug("Finally used sign algorithm = " + signatorId); +// logger_.debug("Finally used sign algorithm = " + signatorId); String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(connector); @@ -766,7 +803,7 @@ public abstract class Main System.err.println("Externer Fehlergrund: " + eee.getExternalErrorCode() + ": " + eee.getExternalErrorMessage()); } - logger_.debug(e); + logger_.error(e); } /** @@ -988,6 +1025,30 @@ public abstract class Main } } } + + /** + * Formats the verification results for debugging. Returns 0 if no error occurs or the sum of all error-codes. + * + * @param results + * + * @param writer + * The output sink to write the formatted text to. + * @throws SettingNotFoundException + * Forwarded exception. + */ + protected static int debugVerifyResults(List results) throws SettingNotFoundException + { + int toreturn = 0; + Iterator it = results.iterator(); + while (it.hasNext()) + { + SignatureResponse result = (SignatureResponse) it.next(); + + toreturn += Integer.valueOf(result.getSignatureCheckCode()).intValue(); + } + return toreturn; + } + /** * Formats the SignatureResponse. -- cgit v1.2.3