diff options
3 files changed, 22 insertions, 19 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java index 169aefb8..b02ac057 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java @@ -91,16 +91,6 @@ public class SigningState extends State { } if(this.threadException != null) { - // workaround for PDF-AS nullpointerexception intercepting our IllegalStateException - // cf. issue #52 - // this is a bit of a hack... - if (status.getPreviousState() instanceof MobileBKUState) - { - String mobileBkuError = ((MobileBKUState)status.getPreviousState()).status.errorMessage; - if ("cancel".equals(mobileBkuError)) - this.threadException = new SignatureException(new IllegalStateException()); - } - String message = Messages.getString("error.Signatur"); if (this.threadException instanceof SignatureException) { Throwable cause = this.threadException; diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java index 7dd2fedc..1396255a 100644 --- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java @@ -91,8 +91,7 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector { } catch (SignatureException e) { throw new PDFIOException("error.pdf.io.03", e); } catch (UserCancelledException e) { - // TODO: find out how to communicate this out to PDF-AS? - throw new PDFIOException("error.pdf.io.03", e); + throw new SLPdfAsException(6001, "Vorgang durch den Benutzer abgebrochen."); } if (element == null) { @@ -108,12 +107,16 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector { throw new PdfAsException("error.pdf.io.03"); } + /** hack cf. #52 */ + public static Exception originalExceptionSwallowedByPDFASNPE = null; /* (non-Javadoc) * @see at.gv.egiz.sl.util.ISLConnector#sendCMSRequest(at.gv.egiz.sl.util.RequestPackage, at.gv.egiz.pdfas.lib.api.sign.SignParameter) */ @Override public CreateCMSSignatureResponseType sendCMSRequest(RequestPackage pack, SignParameter parameter) throws PdfAsException { + /* outermost try blocks are a hack cf. #52 */ +try { try { JAXBElement<?> element = null; try { @@ -145,8 +148,7 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector { } catch (SignatureException e) { throw new PDFIOException("error.pdf.io.03", e); } catch (UserCancelledException e) { - // TODO: find out how to communicate this out to PDF-AS? - throw new PDFIOException("error.pdf.io.03", e); + throw new SLPdfAsException(6001, "Vorgang durch den Benutzer abgebrochen."); } if (element == null) { @@ -161,9 +163,10 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector { } else if (element.getValue() instanceof ErrorResponseType) { ErrorResponseType errorResponseType = (ErrorResponseType) element .getValue(); - throw new SLPdfAsException(errorResponseType.getErrorCode(), - errorResponseType.getInfo()); + throw new SLPdfAsException(errorResponseType.getErrorCode(), errorResponseType.getInfo()); } throw new PdfAsException("error.pdf.io.03"); +} finally { originalExceptionSwallowedByPDFASNPE = null; } } catch (Exception e) { originalExceptionSwallowedByPDFASNPE = e; throw e; } } + } diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java index 561452a4..7afa4ec5 100644 --- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java @@ -1,6 +1,7 @@ package at.asit.pdfover.signer.pdfas; import java.io.ByteArrayOutputStream; +import java.util.Objects; import java.util.UUID; import javax.activation.DataSource; @@ -155,13 +156,22 @@ public class PdfAs4Signer { result.setSignedDocument(new ByteArrayDocumentSource(state.output.toByteArray())); return result; } - } catch (PdfAsException | PDFASError e) { - { // TODO hack around pdf-as not handling this error code properly cf. #124 + } catch (PdfAsException | PDFASError ex) { + // workaround for PDF-AS nullpointerexception intercepting the actual exception + // cf. issue #52 + // this is a bit of a hack... + Exception e = ex; + { + if ((e instanceof PDFASError) && (e.getCause() instanceof NullPointerException)) + e = Objects.requireNonNullElse(PdfAs4BKUSLConnector.originalExceptionSwallowedByPDFASNPE, e); + } + + { Throwable rootCause = e; while (rootCause.getCause() != null) rootCause = rootCause.getCause(); try { /* error code 60xx is user cancellation */ - int errorCode = Integer.parseInt(((SLPdfAsException)rootCause).getMessage().split(":",2)[0].trim()); + int errorCode = ((SLPdfAsException)rootCause).getCode(); if ((6000 <= errorCode) && (errorCode <= 6099)) throw new UserCancelledException(); } catch (ClassCastException e2) { /* fall through to wrapped throw */} |