diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java | 71 | 
1 files changed, 66 insertions, 5 deletions
| 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.
 | 
