From 9c5e6971b00f3b8e0313b9350169ad322e1b5f30 Mon Sep 17 00:00:00 2001 From: Andreas Abraham Date: Mon, 1 Apr 2019 10:51:39 +0200 Subject: error handling implemented in case an error occurs when connecting to atrust --- .../asit/pdfover/gui/bku/mobile/ATrustHandler.java | 47 +++++++++++++--------- .../pdfover/gui/bku/mobile/MobileBKUHandler.java | 3 +- .../gui/workflow/states/MobileBKUState.java | 3 +- .../at/asit/pdfover/gui/messages.properties | 1 + .../at/asit/pdfover/gui/messages_de.properties | 1 + 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java index a11f8c26..b2e5ec8c 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java @@ -46,6 +46,7 @@ import com.google.gson.JsonParser; import at.asit.pdfover.gui.controls.Dialog; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.Dialog.ICON; +import at.asit.pdfover.gui.exceptions.ATrustConnectionException; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.states.MobileBKUState; import at.asit.pdfover.signator.SLResponse; @@ -454,20 +455,20 @@ public class ATrustHandler extends MobileBKUHandler { public boolean useBase64Request() { return this.useBase64; } - - - /* (non-Javadoc) + + /* + * (non-Javadoc) * */ @Override - public void handlePolling(String responseData) { - + public void handlePolling(String responseData) throws ATrustConnectionException { + ATrustStatus status = getStatus(); URLConnection urlconnection = null; - String isReady = null; - Status serverStatus = null; - int waits = 0; - final String ERROR = "Error: Server is not responding"; //$NON-NLS-1$ + String isReady = null; + Status serverStatus = null; + int waits = 0; + final String ERROR = "Error: Server is not responding"; //$NON-NLS-1$ try { do { @@ -477,30 +478,29 @@ public class ATrustHandler extends MobileBKUHandler { isReady = IOUtils.toString(in, "utf-8"); //$NON-NLS-1$ serverStatus = new Status(isReady); - if (serverStatus.isWait()) waits++; + if (serverStatus.isWait()) + waits++; if (waits > 4) { - status.setErrorMessage(ERROR); - log.error(ERROR); - throw new Exception(ERROR); + status.setErrorMessage(ERROR); + log.error(ERROR); + throw new ATrustConnectionException(); } - + } while (serverStatus.isWait()); if (serverStatus.isFin()) { String response = getSignaturePage(); handleCredentialsResponse(response); - } - else { + } else { status.setErrorMessage("Server reponded ERROR during polling"); //$NON-NLS-1$ - log.error("Server reponded ERROR during polling"); //$NON-NLS-1$ - return; + log.error("Server reponded ERROR during polling"); //$NON-NLS-1$ + throw new ATrustConnectionException(); } - } catch (Exception e) { log.error("handle polling failed" + e.getMessage()); //$NON-NLS-1$ + throw new ATrustConnectionException(); } - } private class Status { @@ -515,6 +515,12 @@ public class ATrustHandler extends MobileBKUHandler { this.error = jobject.get("error").getAsBoolean(); //$NON-NLS-1$ this.wait = jobject.get("wait").getAsBoolean(); //$NON-NLS-1$ } + + public Status(boolean error) { + this.error = error; + this.fin = false; + this.wait = false; + } public boolean isFin() { return fin; @@ -530,6 +536,7 @@ public class ATrustHandler extends MobileBKUHandler { + } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java index 4cf84223..3ab47941 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java @@ -34,6 +34,7 @@ import org.apache.commons.httpclient.methods.multipart.StringPart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.exceptions.ATrustConnectionException; import at.asit.pdfover.gui.utils.FileUploadSource; import at.asit.pdfover.gui.workflow.states.LocalBKUState; import at.asit.pdfover.gui.workflow.states.MobileBKUState; @@ -355,5 +356,5 @@ public abstract class MobileBKUHandler { /** * @param responseData */ - public abstract void handlePolling(String responseData); + public abstract void handlePolling(String responseData) throws ATrustConnectionException; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 98dfaad5..f086f3cd 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -463,8 +463,7 @@ public class MobileBKUState extends State { if (handler.handleQRResponse(resp)) { log.debug("Signature page response: " + resp); //$NON-NLS-1$ getMobileBKUFingerprintComposite().setDone(true); - Display display = getStateMachine().getGUIProvider(). - getMainShell().getDisplay(); + Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay(); display.wake(); } Display.getDefault().wake(); diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties index dcfa8506..81e85c8a 100644 --- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties +++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties @@ -149,6 +149,7 @@ error.TanTooLong=Entered TAN too long error.Title=Error error.TitleFatal=Fatal Error error.Unexpected=Unexpected Error +error.ATrustConnection=Connection to A-Trust could not be established exception.InvalidEmblemFile=%s is an invalid signature logo file\! exception.InvalidPort=%s is invalid\: has to be a number between %d and %d exception.PasswordTooLong=Given password is too long\! diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties index 158af59a..50c75e6e 100644 --- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties +++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties @@ -147,6 +147,7 @@ error.TanTooLong=Eingegebene TAN zu lange error.Title=Fehler error.TitleFatal=Fataler Fehler error.Unexpected=Unerwarteter Fehler +error.ATrustConnection=Verbindung zu A-Trust konnte nicht aufgebaut werden exception.InvalidEmblemFile=%s ist eine ung\u00FCltige Bildmarken-Datei\! exception.InvalidPort=%s ist ung\u00FCltig\: muss eine Nummer zwischen %d und %d sein. exception.PasswordTooLong=Eingegebenes Passwort ist zu lange\! -- cgit v1.2.3