From 0708bf4d1e1a9046c82c221170b3dd3709e71141 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 18:57:50 +0000 Subject: Removed Error State and replaced it with ErrorDialog To get a stable user experience in case of an error. ErrorDialog was improved to let the user decide if he wants to retry an action. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@58 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../pdfover/gui/workflow/states/ErrorState.java | 122 --------------------- .../pdfover/gui/workflow/states/LocalBKUState.java | 81 +++++++------- .../gui/workflow/states/MobileBKUState.java | 11 +- .../pdfover/gui/workflow/states/OutputState.java | 2 +- .../workflow/states/PrepareConfigurationState.java | 12 +- .../gui/workflow/states/PrepareSigningState.java | 13 ++- .../pdfover/gui/workflow/states/SigningState.java | 13 ++- 7 files changed, 81 insertions(+), 173 deletions(-) delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java deleted file mode 100644 index dd240616..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * 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://joinup.ec.europa.eu/software/page/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. - */ -package at.asit.pdfover.gui.workflow.states; - -// Imports -import org.eclipse.swt.SWT; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.composites.ErrorComposite; -import at.asit.pdfover.gui.workflow.StateMachine; - -/** - * - */ -public class ErrorState extends State { - /** - * @param stateMachine - */ - public ErrorState(StateMachine stateMachine) { - super(stateMachine); - } - - private Exception exception; - - private State recoverState = null; - - /** - * @param recoverState the recoverState to set - */ - public void setRecoverState(State recoverState) { - this.recoverState = recoverState; - } - - /** - * SLF4J Logger instance - **/ - static final Logger log = LoggerFactory.getLogger(ErrorState.class); - - private ErrorComposite errorComposite = null; - - private ErrorComposite getComposite() { - if (this.errorComposite == null) { - this.errorComposite = - this.stateMachine.getGUIProvider().createComposite(ErrorComposite.class, SWT.RESIZE, this); - } - - return this.errorComposite; - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.State#run() - */ - @Override - public void run() { - ErrorComposite errorComposite = this.getComposite(); - - if(this.exception != null && !errorComposite.isUserOk()) { - // Display Exception .... - this.errorComposite.setException(this.exception); - - this.stateMachine.getGUIProvider().display(errorComposite); - return; - } - - // User was informed! - if(this.recoverState != null) { - // see if we can recover! - this.setNextState(this.recoverState); - } else { - // we cannot recover exit! - this.stateMachine.exit(); - } - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.State#cleanUp() - */ - @Override - public void cleanUp() { - if (this.errorComposite != null) - this.errorComposite.dispose(); - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.states.State#updateMainWindowBehavior() - */ - @Override - public void updateMainWindowBehavior() { - // Stay in previous state behavior - } - - /** - * Gets the Exception - * @return the exception - */ - public Exception getException() { - return this.exception; - } - - /** - * Sets the Exception - * @param exception the exception to set - */ - public void setException(Exception exception) { - this.exception = exception; - } - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java index 9962d968..58e957b9 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java @@ -37,32 +37,32 @@ import at.asit.pdfover.signator.SLResponse; * Logical state for performing the BKU Request to a local BKU */ public class LocalBKUState extends State { - + /** * HTTP Response server HEADER */ public final static String BKU_REPSONE_HEADER_SERVER = "server"; //$NON-NLS-1$ - + /** * HTTP Response user-agent HEADER */ public final static String BKU_REPSONE_HEADER_USERAGENT = "user-agent"; //$NON-NLS-1$ - + /** * HTTP Response SignatureLayout HEADER */ public final static String BKU_REPSONE_HEADER_SIGNATURE_LAYOUT = "SignatureLayout"; //$NON-NLS-1$ - + /** * TODO: move to a better location ... */ public static final String PDF_OVER_USER_AGENT_STRING = "PDF-Over 4.0"; //$NON-NLS-1$ - + /** * */ private final class SignLocalBKUThread implements Runnable { - + private LocalBKUState state; /** @@ -81,44 +81,45 @@ public class LocalBKUState extends State { String sl_request = request.getBase64Request(); HttpClient client = new HttpClient(); - PostMethod method = new PostMethod( "http://127.0.0.1:3495/http-security-layer-request"); //$NON-NLS-1$ - + log.debug("SL REQUEST: " + sl_request); //$NON-NLS-1$ - + method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$ - + int returnCode = client.executeMethod(method); - - if(returnCode == HttpStatus.SC_OK) - { + + if (returnCode == HttpStatus.SC_OK) { String server = ""; //$NON-NLS-1$ String userAgent = ""; //$NON-NLS-1$ String signatureLayout = ""; //$NON-NLS-1$ - - if(method.getResponseHeader(BKU_REPSONE_HEADER_SERVER) != null) - { - server = method.getResponseHeader(BKU_REPSONE_HEADER_SERVER).getValue(); + + if (method.getResponseHeader(BKU_REPSONE_HEADER_SERVER) != null) { + server = method.getResponseHeader( + BKU_REPSONE_HEADER_SERVER).getValue(); } - - if(method.getResponseHeader(BKU_REPSONE_HEADER_USERAGENT) != null) - { - userAgent = method.getResponseHeader(BKU_REPSONE_HEADER_USERAGENT).getValue(); + + if (method.getResponseHeader(BKU_REPSONE_HEADER_USERAGENT) != null) { + userAgent = method.getResponseHeader( + BKU_REPSONE_HEADER_USERAGENT).getValue(); } - - if(method.getResponseHeader(BKU_REPSONE_HEADER_SIGNATURE_LAYOUT) != null) - { - signatureLayout = method.getResponseHeader(BKU_REPSONE_HEADER_SIGNATURE_LAYOUT).getValue(); + + if (method + .getResponseHeader(BKU_REPSONE_HEADER_SIGNATURE_LAYOUT) != null) { + signatureLayout = method.getResponseHeader( + BKU_REPSONE_HEADER_SIGNATURE_LAYOUT).getValue(); } - + String response = method.getResponseBodyAsString(); log.debug("SL Response: " + response); //$NON-NLS-1$ - SLResponse slResponse = new SLResponse(response, server, userAgent, signatureLayout); + SLResponse slResponse = new SLResponse(response, server, + userAgent, signatureLayout); this.state.signingState.setSignatureResponse(slResponse); } else { - this.state.threadException = new HttpException(method.getResponseBodyAsString()); + this.state.threadException = new HttpException( + method.getResponseBodyAsString()); } } catch (Exception e) { @@ -141,13 +142,12 @@ public class LocalBKUState extends State { /** * SLF4J Logger instance **/ - static final Logger log = LoggerFactory - .getLogger(LocalBKUState.class); + static final Logger log = LoggerFactory.getLogger(LocalBKUState.class); at.asit.pdfover.signator.SigningState signingState; Exception threadException = null; - + /* * (non-Javadoc) * @@ -161,22 +161,27 @@ public class LocalBKUState extends State { this.signingState = status.getSigningState(); - if (!this.signingState.hasSignatureResponse() && - this.threadException == null - ) { + if (!this.signingState.hasSignatureResponse() + && this.threadException == null) { Thread t = new Thread(new SignLocalBKUThread(this)); t.start(); return; } - if(this.threadException != null) { - ErrorDialog dialog = new ErrorDialog(Display.getCurrent().getActiveShell(), SWT.NONE, "Please check if a local BKU is running", this.threadException); - dialog.open(); + if (this.threadException != null) { + ErrorDialog dialog = new ErrorDialog( + this.stateMachine.getGUIProvider().getMainShell(), SWT.NONE, + "Please check if a local BKU is running", + this.threadException, true); + if (!dialog.open()) { + this.stateMachine.exit(); + return; + } this.threadException = null; this.run(); return; } - + // OK this.setNextState(new SigningState(this.stateMachine)); } 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 f39deada..ed6d675f 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 @@ -25,6 +25,7 @@ import at.asit.pdfover.gui.MainWindowBehavior; import at.asit.pdfover.gui.composites.MobileBKUEnterNumberComposite; import at.asit.pdfover.gui.composites.MobileBKUEnterTANComposite; import at.asit.pdfover.gui.composites.WaitingComposite; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUCommunicationState; import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus; @@ -148,9 +149,13 @@ public class MobileBKUState extends State { MobileBKUStatus mobileStatus = this.getStatus(); if (this.threadException != null) { - ErrorState error = new ErrorState(this.stateMachine); - error.setException(this.threadException); - this.setNextState(error); + ErrorDialog error = new ErrorDialog(this.stateMachine.getGUIProvider().getMainShell(), + SWT.NONE, + "Unexpected Error", this.threadException, false); + //error.setException(this.threadException); + //this.setNextState(error); + error.open(); + this.stateMachine.exit(); return; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java index a1748287..5a42d3cc 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java @@ -89,7 +89,7 @@ public class OutputState extends State { output.close(); } catch (IOException e) { log.error("Failed to save signed document to configured output folder.", e); //$NON-NLS-1$ - ErrorDialog dialog = new ErrorDialog(outputComposite.getShell(), SWT.NONE, "Failed to save signed document to configured output folder.", e); + ErrorDialog dialog = new ErrorDialog(outputComposite.getShell(), SWT.NONE, "Failed to save signed document to configured output folder.", e, false); dialog.open(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java index a1de09d0..3cf0861f 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java @@ -21,6 +21,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,6 +30,7 @@ import at.asit.pdfover.gui.cliarguments.BKUArgument; import at.asit.pdfover.gui.cliarguments.ConfigFileArgument; import at.asit.pdfover.gui.cliarguments.HelpArgument; import at.asit.pdfover.gui.cliarguments.PhoneNumberArgument; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.StateMachine; @@ -143,9 +145,13 @@ public class PrepareConfigurationState extends State { } catch (InitializationException e) { log.error("Failed to initialize: ", e); //$NON-NLS-1$ - ErrorState error = new ErrorState(this.stateMachine); - error.setException(e); - this.setNextState(error); + ErrorDialog error = new ErrorDialog(this.stateMachine.getGUIProvider().getMainShell(), + SWT.NONE, "Initialization failed. Please check your configuration.", + e, false); + //error.setException(e); + //this.setNextState(error); + error.open(); + this.stateMachine.exit(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java index af6cc3bd..4ed59e5a 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java @@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.MainWindowBehavior; import at.asit.pdfover.gui.composites.WaitingComposite; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.workflow.ConfigProvider; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; @@ -137,9 +138,15 @@ public class PrepareSigningState extends State { } if(this.threadException != null) { - ErrorState error = new ErrorState(this.stateMachine); - error.setException(this.threadException); - this.setNextState(error); + ErrorDialog error = new ErrorDialog(this.stateMachine.getGUIProvider().getMainShell(), + SWT.NONE, "Failed to prepare document for signature.", this.threadException, + true); + this.threadException = null; + if(error.open()) { + this.stateMachine.update(); + } else { + this.stateMachine.exit(); + } return; } 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 413f125c..37877f12 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 @@ -16,9 +16,11 @@ package at.asit.pdfover.gui.workflow.states; //Imports +import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; import at.asit.pdfover.signator.Signer; @@ -84,9 +86,14 @@ public class SigningState extends State { } if(this.threadException != null) { - ErrorState error = new ErrorState(this.stateMachine); - error.setException(this.threadException); - this.setNextState(error); + ErrorDialog error = new ErrorDialog(this.stateMachine.getGUIProvider().getMainShell(), + SWT.NONE, "Signature error", this.threadException, true); + this.threadException = null; + if(error.open()) { + this.stateMachine.update(); + } else { + this.stateMachine.exit(); + } return; } -- cgit v1.2.3