diff options
author | Andreas Abraham <andreas.abraham@egiz.gv.at> | 2021-01-26 16:17:43 +0100 |
---|---|---|
committer | Andreas Abraham <andreas.abraham@egiz.gv.at> | 2021-01-26 16:17:43 +0100 |
commit | 5caa941790750bba85a8f830abf04a50d3b049b0 (patch) | |
tree | 78f3eb3de8cfde322b565026c8c3673a11564ab1 /pdf-over-gui | |
parent | 66a53df1563d85de5e3c2b8ea3344cc94a08d9ca (diff) | |
download | pdf-over-5caa941790750bba85a8f830abf04a50d3b049b0.tar.gz pdf-over-5caa941790750bba85a8f830abf04a50d3b049b0.tar.bz2 pdf-over-5caa941790750bba85a8f830abf04a50d3b049b0.zip |
New Thread for polling implemented
Diffstat (limited to 'pdf-over-gui')
-rw-r--r-- | pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java | 98 |
1 files changed, 49 insertions, 49 deletions
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 8a416676..6485c270 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 @@ -15,11 +15,13 @@ */
package at.asit.pdfover.gui.workflow.states;
+import java.io.IOException;
import java.io.InputStream;
import java.util.Timer;
import java.util.TimerTask;
// Imports
+import at.asit.pdfover.gui.exceptions.ATrustConnectionException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.slf4j.Logger;
@@ -451,67 +453,65 @@ public class MobileBKUState extends State { public void showOpenAppMessageWithSMSandCancel() {
final ATrustStatus status = (ATrustStatus) this.getStatus();
- final ATrustHandler handler = (ATrustHandler) this.getHandler();
- final Timer checkDone = new Timer(true);
- checkDone.scheduleAtFixedRate(new TimerTask() {
+ Display.getDefault().syncExec(() -> {
+ WaitingForAppComposite waitingForAppcomposite = MobileBKUState.this.getWaitingForAppComposite();
+ getStateMachine().getGUIProvider().display(waitingForAppcomposite);
- @Override
- public void run() {
- // ping signature page
- try {
- String resp = handler.getSignaturePage();
- if (handler.handleWaitforAppResponse(resp) || handler.handlePolling()) {
- log.debug("Signature page response: " + resp); //$NON-NLS-1$
- getWaitingForAppComposite().setIsDone(true);
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
- display.wake();
- }
- Display.getDefault().wake();
- } catch (Exception e) {
- log.error("Error getting signature page", e); //$NON-NLS-1$
+ Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ undecidedPolling();
+
+ while (!waitingForAppcomposite.getUserCancel() && !waitingForAppcomposite.getUserSMS()
+ && !waitingForAppcomposite.getIsDone()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
}
}
- }, 0, 5000);
-
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- WaitingForAppComposite waitingForAppcomposite = MobileBKUState.this.getWaitingForAppComposite();// getWaitingForAppComposite();
- getStateMachine().getGUIProvider().display(waitingForAppcomposite);
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
- while (!waitingForAppcomposite.getUserCancel() && !waitingForAppcomposite.getUserSMS()
- && !waitingForAppcomposite.getIsDone()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
+ if (waitingForAppcomposite.getUserCancel()) {
+ waitingForAppcomposite.setUserCancel(false);
+ status.setErrorMessage("cancel"); //$NON-NLS-1$
+ return;
+ }
- if (waitingForAppcomposite.getUserCancel()) {
- waitingForAppcomposite.setUserCancel(false);
- status.setErrorMessage("cancel"); //$NON-NLS-1$
- return;
- }
+ if (waitingForAppcomposite.getUserSMS()) {
+ status.setQRCode(null);
+ waitingForAppcomposite.setUserSMS(false);
+ status.setErrorMessage("sms"); //$NON-NLS-1$
+ status.setSmsTan(true);
+ // show waiting composite
+ getStateMachine().getGUIProvider().display(MobileBKUState.this.getWaitingComposite());
+ return;
- if (waitingForAppcomposite.getUserSMS()) {
- status.setQRCode(null);
- waitingForAppcomposite.setUserSMS(false);
- status.setErrorMessage("sms"); //$NON-NLS-1$
- status.setSmsTan(true);
- // show waiting composite
- getStateMachine().getGUIProvider().display(MobileBKUState.this.getWaitingComposite());
- return;
+ }
- }
+ if (waitingForAppcomposite.getIsDone())
+ waitingForAppcomposite.setIsDone(false);
+ });
+ }
- if (waitingForAppcomposite.getIsDone())
- waitingForAppcomposite.setIsDone(false);
+ private void undecidedPolling(){
+ final ATrustHandler handler = (ATrustHandler) this.getHandler();
- // show waiting composite
- //getStateMachine().getGUIProvider().display(MobileBKUState.this.getWaitingComposite());
+ Thread pollingThread = new Thread(() -> {
+ try {
+ if (handler.handlePolling()){
+ String response = handler.getSignaturePage();
+ handler.handleCredentialsResponse(response);
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ getWaitingForAppComposite().setIsDone(true);
+ }
+ });
+ }
+ } catch (ATrustConnectionException e) {
+ log.error("Error when calling polling endpoint");
+ } catch (Exception e) {
+ log.error("Exception occurred during calling polling endpoint");
}
});
+ pollingThread.start();
}
/**
|