diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-20 12:16:04 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-20 12:16:04 +0200 |
commit | c68914663440c9f7c0808d965b901acf5df0194d (patch) | |
tree | 37142d0bb35bed733ae9a85ee6e2d0282f9631e7 /pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib | |
parent | 670d8312a1459db518140f0dfcfe6434dda2ebec (diff) | |
download | pdf-as-4-c68914663440c9f7c0808d965b901acf5df0194d.tar.gz pdf-as-4-c68914663440c9f7c0808d965b901acf5df0194d.tar.bz2 pdf-as-4-c68914663440c9f7c0808d965b901acf5df0194d.zip |
Extract MOA error codes, log generic error message
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib')
-rw-r--r-- | pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/ErrorExtractor.java | 31 | ||||
-rw-r--r-- | pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java | 6 |
2 files changed, 30 insertions, 7 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/ErrorExtractor.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/ErrorExtractor.java index 90a4e9e8..8c2451e3 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/ErrorExtractor.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/ErrorExtractor.java @@ -1,11 +1,18 @@ package at.gv.egiz.pdfas.lib.impl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import at.gv.egiz.pdfas.common.exceptions.ErrorConstants; import at.gv.egiz.pdfas.common.exceptions.PDFASError; +import at.gv.egiz.pdfas.common.exceptions.PdfAsMOAException; import at.gv.egiz.pdfas.common.exceptions.SLPdfAsException; public class ErrorExtractor implements ErrorConstants { + private static final Logger logger = LoggerFactory + .getLogger(ErrorExtractor.class); + private static final int MAX_CAUSE_DEPTH = 30; private static PDFASError convertPdfAsError(Throwable e) { @@ -16,7 +23,27 @@ public class ErrorExtractor implements ErrorConstants { } else { return new PDFASError(ex.getCode(), e); } - } // TODO: Handle more exceptions + } else if(e instanceof PdfAsMOAException) { + PdfAsMOAException ex = (PdfAsMOAException) e; + int code = -1; + String errorInfo = ex.getErrorResponse(); + + if(ex.getErrorCode() != null && !ex.getErrorCode().isEmpty()) { + try { + code = Integer.parseInt(ex.getErrorCode()); + } catch(NumberFormatException numfo) { + logger.warn("Failed to convert MOA ErrorCode: " + ex.getErrorCode(), e); + } + } + + if (errorInfo != null) { + return new PDFASError(code, errorInfo, e); + } else { + return new PDFASError(code, e); + } + } + + // TODO: Handle more exceptions return null; } @@ -60,6 +87,8 @@ public class ErrorExtractor implements ErrorConstants { return err; } + logger.info("Cannot extract correct failure code from: ", e); + return new PDFASError(ERROR_GENERIC, e); } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java index 3d9725a7..387a6c31 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java @@ -27,15 +27,12 @@ import iaik.x509.X509Certificate; import java.awt.Image; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Calendar; import java.util.Iterator; import java.util.List; -import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,9 +61,6 @@ import at.gv.egiz.pdfas.lib.impl.signing.IPdfSigner; import at.gv.egiz.pdfas.lib.impl.signing.PDFASSignatureExtractor; import at.gv.egiz.pdfas.lib.impl.status.OperationStatus; import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature; -import at.gv.egiz.pdfas.lib.impl.verify.IVerifier; -import at.gv.egiz.pdfas.lib.impl.verify.IVerifyFilter; -import at.gv.egiz.pdfas.lib.impl.verify.VerifierDispatcher; import at.gv.egiz.pdfas.lib.util.SignatureUtils; public class PdfAsImpl implements PdfAs, IConfigurationConstants, |