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 +- 3 files changed, 30 insertions(+), 23 deletions(-) (limited to 'pdf-over-gui/src/main/java/at') 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(); -- cgit v1.2.3