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 --- .../framework/logging/CsvStatisticLogger.java | 105 +++++++ .../pdfas/framework/logging/StatisticData.java | 314 +++++++++++++++++++++ .../framework/logging/StatisticLogFactory.java | 63 +++++ .../pdfas/framework/logging/StatisticLogger.java | 47 +++ 4 files changed, 529 insertions(+) create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/CsvStatisticLogger.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticData.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticLogFactory.java create mode 100644 pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticLogger.java (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/CsvStatisticLogger.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/CsvStatisticLogger.java new file mode 100644 index 0000000..a295a7b --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/CsvStatisticLogger.java @@ -0,0 +1,105 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.gv.egiz.pdfas.framework.logging; + +import org.apache.commons.logging.Log; + +import at.gv.egiz.pdfas.api.exceptions.PdfAsException; +import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException; +import at.gv.egiz.pdfas.utils.CsvUtils; + +/** + * A statistic logger implementation that prodoces csv based logging entries. + * + * @author Datentechnik Innovation GmbH + */ +public class CsvStatisticLogger implements StatisticLogger { + + /** + * The underlying logging implementation. + */ + private Log log; + + /** + * A csv value indication error conditions. + */ + private static final String VALUE_ERROR = "ERROR"; + + /** + * A csv value indication success conditions. + */ + private static final String VALUE_OK = "OK"; + + /** + * Creates a new instance. + * + * @param log + * The underlying logger. + */ + CsvStatisticLogger(Log log) { + this.log = log; + } + + public void log(StatisticData data) { + if (isEnabled()) { + StringBuffer msg = new StringBuffer(); + + // add escapted fields + msg.append(CsvUtils.escapeCsvValue(data.operation)).append(CsvUtils.DEFAULT_DELIMITER); + msg.append(CsvUtils.escapeCsvValue(data.signatureMode)).append(CsvUtils.DEFAULT_DELIMITER); + msg.append(CsvUtils.escapeCsvValue(data.connector)).append(CsvUtils.DEFAULT_DELIMITER); + msg.append(CsvUtils.escapeCsvValue(data.signatureProfileId)).append(CsvUtils.DEFAULT_DELIMITER); + msg.append(CsvUtils.escapeCsvValue(data.fileSize)).append(CsvUtils.DEFAULT_DELIMITER); + msg.append(CsvUtils.escapeCsvValue(data.userAgent)).append(CsvUtils.DEFAULT_DELIMITER); + + // handle error conditions + Integer errorCode = null; + String externalErrorCode = null; + if (data.exception != null) { + msg.append(VALUE_ERROR).append(CsvUtils.DEFAULT_DELIMITER); + if (data.exception instanceof PdfAsException) { + PdfAsException pdfAsException = (PdfAsException) data.exception; + errorCode = pdfAsException.getErrorCode(); + if (pdfAsException instanceof ExternalErrorException) { + externalErrorCode = ((ExternalErrorException) pdfAsException).getExternalErrorCode(); + } + } + msg.append(CsvUtils.escapeCsvValue(data.exception.getClass().getName())).append(CsvUtils.DEFAULT_DELIMITER); + } else { + msg.append(VALUE_OK).append(CsvUtils.DEFAULT_DELIMITER).append(CsvUtils.DEFAULT_DELIMITER); + } + msg.append(CsvUtils.escapeCsvValue(errorCode)).append(CsvUtils.DEFAULT_DELIMITER); + msg.append(CsvUtils.escapeCsvValue(externalErrorCode)).append(CsvUtils.DEFAULT_DELIMITER); + + msg.append(CsvUtils.escapeCsvValue(data.duration)); + + log.info(msg); + } + } + + public boolean isEnabled() { + return log.isInfoEnabled(); + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticData.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticData.java new file mode 100644 index 0000000..3cb1c66 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticData.java @@ -0,0 +1,314 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.gv.egiz.pdfas.framework.logging; + +import at.gv.egiz.pdfas.api.analyze.AnalyzeParameters; +import at.gv.egiz.pdfas.api.commons.Constants; +import at.gv.egiz.pdfas.api.sign.SignParameters; +import at.gv.egiz.pdfas.api.verify.VerifyAfterAnalysisParameters; +import at.gv.egiz.pdfas.api.verify.VerifyAfterReconstructXMLDsigParameters; +import at.gv.egiz.pdfas.api.verify.VerifyParameters; +import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigAfterAnalysisParameters; +import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigParameters; + +public class StatisticData { + + String operation; + String connector; + String signatureMode; + String signatureProfileId; + Integer fileSize; + Long duration; + String userAgent; + Exception exception; + + /** + * Creates new data for statistical logging purposes. + */ + public StatisticData() { + } + + /** + * Creates new data for statistical logging purposes. + * + * @param operation + * The operation (one of 'SIGN' and 'VERIFY'). + * @param connector + * The connector being used for the certain operation (one of {@link Constants#SIGNATURE_DEVICE_BKU}, + * {@link Constants#SIGNATURE_DEVICE_MOA}, {@link Constants#SIGNATURE_DEVICE_MOC}, + * {@link Constants#SIGNATURE_DEVICE_MOBILE}...) + * @param fileSize + * The size of the file being processed. + * @param signatureMode + * The signature mode (one of {@link Constants#SIGNATURE_TYPE_BINARY}, + * {@link Constants#SIGNATURE_TYPE_BINARY} or {@code null} in case of verification. + * @param duration + * The duration the certain operation took (in ms). + * @param userAgent + * The user agent String. + * @param errorCode + * The error code resulting from the current operation (0 means no error). + */ + public StatisticData(String operation, String connector, Integer fileSize, String signatureMode, Long duration, + String userAgent, Integer errorCode) { + this(); + this.operation = operation; + this.connector = connector; + this.signatureMode = signatureMode; + this.fileSize = fileSize; + this.duration = duration; + this.userAgent = userAgent; + } + + /** + * Creates new data for statistical logging purposes. + * + * @param operation + * The operation (one of 'SIGN' and 'VERIFY'). + * @param connector + * The connector being used for the certain operation (one of {@link Constants#SIGNATURE_DEVICE_BKU}, + * {@link Constants#SIGNATURE_DEVICE_MOA}, {@link Constants#SIGNATURE_DEVICE_MOC}, + * {@link Constants#SIGNATURE_DEVICE_MOBILE}...) + * @param fileSize + * The size of the file being processed. + */ + public StatisticData(String operation, String connector, Integer fileSize) { + this(); + this.operation = operation; + this.connector = connector; + this.fileSize = fileSize; + } + + /** + * Creates new data for statistical logging purposes. + * + * @param operation + * The operation (one of 'SIGN' and 'VERIFY'). + * @param connector + * The connector being used for the certain operation (one of {@link Constants#SIGNATURE_DEVICE_BKU}, + * {@link Constants#SIGNATURE_DEVICE_MOA}, {@link Constants#SIGNATURE_DEVICE_MOC}, + * {@link Constants#SIGNATURE_DEVICE_MOBILE}...) + * @param fileSize + * The size of the file being processed. + * @param signatureMode + * The signature mode (one of {@link Constants#SIGNATURE_TYPE_BINARY}, + * {@link Constants#SIGNATURE_TYPE_BINARY} or {@code null} in case of verification. + * @param duration + * The duration the certain operation took (in ms). + * @param userAgent + * The user agent String. + */ + public StatisticData(String operation, String connector, Integer fileSize, String signatureMode, Long duration, + String userAgent) { + this(operation, connector, fileSize, signatureMode, duration, userAgent, null); + } + + /** + * Creates statistical data based on given sign parameters. + * + * @param signParameters + * The given sign parameters. + */ + public StatisticData(SignParameters signParameters) { + this(); + operation = "SIGN"; + connector = signParameters.getSignatureDevice(); + signatureMode = signParameters.getSignatureType(); + fileSize = signParameters.getDocument().getLength(); + signatureProfileId = signParameters.getSignatureProfileId(); + } + + /** + * Creates statistical data based on given verify parameters. + * + * @param verifyParameters + * The given verify parameters. + */ + public StatisticData(VerifyParameters verifyParameters) { + this(); + operation = "VERIFY"; + connector = verifyParameters.getSignatureDevice(); + fileSize = verifyParameters.getDocument().getLength(); + } + + /** + * Creates statistical data based on given analyze parameters. + * + * @param varxdp + * The given analyze parameters. + */ + public StatisticData(AnalyzeParameters analyzeParameters) { + this(); + operation = "ANALYZE"; + fileSize = analyzeParameters.getDocument().getLength(); + } + + /** + * Creates statistical data based on given reconstruction parameters. + * + * @param rxdaap + * The given reconstruction parameters. + */ + public StatisticData(ReconstructXMLDsigAfterAnalysisParameters rxdaap) { + this(); + operation = "RECONSTRUCT"; + connector = rxdaap.getSignatureDevice(); + } + + /** + * Creates statistical data based on given reconstruction parameters. + * + * @param reconstructParameters + * The given reconstruction parameters. + */ + public StatisticData(ReconstructXMLDsigParameters reconstructParameters) { + this(); + operation = "RECONSTRUCT"; + fileSize = reconstructParameters.getDocument().getLength(); + connector = reconstructParameters.getSignatureDevice(); + } + + /** + * Creates statistical data based on given parameters. + * + * @param vaaParameters + * The given verify parameters after analysis. + */ + public StatisticData(VerifyAfterAnalysisParameters vaaParameters) { + this(); + operation = "VERIFY"; + connector = vaaParameters.getSignatureDevice(); + } + + /** + * Creates statistical data based on given verify parameters after reconstruction. + * + * @param varxdp + * The given verify parameters after reconstruction. + */ + public StatisticData(VerifyAfterReconstructXMLDsigParameters varxdp) { + this(); + operation = "VERIFY"; + connector = varxdp.getSignatureDevice(); + } + + /** + * Sets the current operation name. + * + * @param operation + * The operation name. + */ + public StatisticData setOperation(String operation) { + this.operation = operation; + return this; + } + + /** + * Sets the connector. + * + * @param connector + * The connector. + */ + public StatisticData setConnector(String connector) { + this.connector = connector; + return this; + } + + /** + * Sets the file size of the processed document. + * + * @param fileSize + * The file size in bytes. + */ + public StatisticData setFileSize(Integer fileSize) { + this.fileSize = fileSize; + return this; + } + + /** + * Sets the duration of the performed operation. + * + * @param duration + * The duration in ms. + */ + public StatisticData setDuration(Long duration) { + this.duration = duration; + return this; + } + + /** + * Sets the user agent identifier. + * + * @param userAgent + * The user agent identifier. + */ + public StatisticData setUserAgent(String userAgent) { + this.userAgent = userAgent; + return this; + } + + /** + * Sets the signature mode. + * + * @param signatureMode + * The signature mode (one of {@link Constants#SIGNATURE_TYPE_TEXTUAL} and + * {@link Constants#SIGNATURE_TYPE_BINARY}). + */ + public StatisticData setSignatureMode(String signatureMode) { + this.signatureMode = signatureMode; + return this; + } + + /** + * Sets the profile id. + * + * @param profileId + * The profile id. + */ + public StatisticData setSignatureProfileId(String signatureProfileId) { + this.signatureProfileId = signatureProfileId; + return this; + } + + /** + * Sets the exception that has been thrown. + * + * @param exception + * The exception. + */ + public StatisticData setException(Exception exception) { + this.exception = exception; + return this; + } + + /** + * Returns {@code true} if an error condition has been set, {@code false} otherwise. + * + * @return {@code true} in case of an error, {@code false} if not. + */ + public boolean isError() { + return exception != null; + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticLogFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticLogFactory.java new file mode 100644 index 0000000..2b6671c --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticLogFactory.java @@ -0,0 +1,63 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.gv.egiz.pdfas.framework.logging; + +import org.apache.commons.logging.LogFactory; + +/** + * This factory creates statistic logger implementations.
+ * Note that it exclusively creates {@link CsvStatisticLogger} implementations at the moment. It should just be regarded + * as template for further factory implementations. Strictly speaking this factory does not fulfil the respective GoF + * pattern. + * + * @see StatisticLogger + * @author Datentechnik Innovation GmbH + */ +public class StatisticLogFactory { + + /** + * Returns a statistic logger implementation. + * + * @param clazz + * The class. + * @return A statistic logger implementation. + */ + public static StatisticLogger getLog(Class clazz) { + return getLog(clazz.getName()); + } + + /** + * Returns a statistic logger implementation. + * + * @param name + * The name of the logger. + * @return A statistic logger implementation. + */ + public static StatisticLogger getLog(String name) { + + // to be changed some day, producing various logger implementations + return new CsvStatisticLogger(LogFactory.getLog(name)); + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticLogger.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticLogger.java new file mode 100644 index 0000000..6e2c587 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/framework/logging/StatisticLogger.java @@ -0,0 +1,47 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.gv.egiz.pdfas.framework.logging; + +/** + * + * @author Datentechnik Innovation GmbH + */ +public interface StatisticLogger { + + /** + * Creates a log entry with the given statistical data. + * + * @param statisticData + * The statistical data. + */ + public void log(StatisticData statisticData); + + /** + * Returns {@code true} in case the logger is enabled, {@code false} if not. + * + * @return {@code true} in case the logger is enabled, {@code false} if not. + */ + public boolean isEnabled(); + +} -- cgit v1.2.3