From c7c00fbb89717c2a3a51f64908ad78a61ae70da0 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 5 Nov 2008 10:05:54 +0000 Subject: BKUWorker refactoring jssessionId git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@148 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 205 +++++++++++ .../bku/online/applet/AppletParameterProvider.java | 57 ++++ .../at/gv/egiz/bku/online/applet/BKUApplet.java | 125 ++++--- .../at/gv/egiz/bku/online/applet/BKUWorker.java | 374 --------------------- .../applet/WebServiceSignRequestHandler.java | 2 +- 5 files changed, 343 insertions(+), 420 deletions(-) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java (limited to 'BKUApplet') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java new file mode 100644 index 00000000..2141165b --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -0,0 +1,205 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.smccstal.AbstractBKUWorker; +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.SignRequest; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.STALService; +import at.gv.egiz.stal.service.types.ErrorResponseType; +import at.gv.egiz.stal.service.types.GetNextRequestResponseType; +import at.gv.egiz.stal.service.types.GetNextRequestType; +import at.gv.egiz.stal.service.types.ObjectFactory; +import at.gv.egiz.stal.service.types.RequestType; +import at.gv.egiz.stal.service.types.ResponseType; +import at.gv.egiz.stal.util.STALTranslator; +import java.applet.AppletContext; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import javax.xml.namespace.QName; + +/** + * + * @author Clemens Orthacker + */ +public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { + + protected AppletContext ctx; + protected AppletParameterProvider params; + protected String sessionId; + protected STALPortType stalPort; + + public AppletBKUWorker(BKUGUIFacade gui, AppletContext ctx, AppletParameterProvider paramProvider) { + super(gui); + if (ctx == null) { + throw new NullPointerException("Applet context not provided"); + } + if (paramProvider == null) { + throw new NullPointerException("No applet parameters provided"); + } + this.ctx = ctx; + this.params = paramProvider; + + sessionId = params.getAppletParameter(BKUApplet.SESSION_ID); + if (sessionId == null) { + sessionId = "TestSession"; + log.info("using dummy sessionId " + sessionId); + } + } + + @Override + public void run() { + gui.showWelcomeDialog(); + try { + stalPort = getSTALPort(); + } catch (Exception e) { + log.fatal("Failed to get STAL web-service port: " + e.getMessage(), e); + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, + new Object[]{e.getMessage()}); + try { + waitForAction(); + } catch (InterruptedException e1) { + log.error(e1); + } + return; + } + + try { + registerSignRequestHandler(); + + ObjectFactory of = new ObjectFactory(); + + GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); + do { + List requests = nextRequestResp.getInfoboxReadRequestOrSignRequestOrQuitRequest(); + List stalRequests = STALTranslator.translateRequests(requests); + + if (log.isInfoEnabled()) { + StringBuilder sb = new StringBuilder("Received "); + sb.append(stalRequests.size()); + sb.append(" STAL requests: "); + for (STALRequest r : stalRequests) { + sb.append(r.getClass()); + sb.append(' '); + } + log.info(sb.toString()); + } + + boolean handle = true; + for (STALRequest request : stalRequests) { + if (request instanceof at.gv.egiz.stal.InfoboxReadRequest) { + at.gv.egiz.stal.InfoboxReadRequest r = (at.gv.egiz.stal.InfoboxReadRequest) request; + String infoboxId = r.getInfoboxIdentifier(); + String domainId = r.getDomainIdentifier(); + if ("IdentityLink".equals(infoboxId) && domainId == null) { + if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { + handle = false; + } + } + } + } + + List responses; + if (handle) { + List stalResponses = handleRequest(stalRequests); + if (log.isInfoEnabled()) { + StringBuilder sb = new StringBuilder(stalResponses.size()); + sb.append(" STAL responses: "); + for (STALResponse r : stalResponses) { + sb.append(r.getClass()); + sb.append(' '); + } + log.info(sb.toString()); + } + responses = STALTranslator.fromSTAL(stalResponses); + } else { + responses = new ArrayList(1); + ErrorResponseType err = of.createErrorResponseType(); + err.setErrorCode(6002); + // err.setErrorMessage(); + responses.add(err); + } + + if (!finished) { + log.info("Not finished yet (BKUWorker: " + this + "), sending responses"); + GetNextRequestType nextRequest = of.createGetNextRequestType(); + nextRequest.setSessionId(sessionId); + nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse().addAll(responses); + nextRequestResp = stalPort.getNextRequest(nextRequest); + } + } while (!finished); + log.info("Done " + Thread.currentThread().getName()); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[]{ex.getMessage()}); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + } + if (signatureCard != null) { + signatureCard.disconnect(false); + } + sendRedirect(); + } + + protected void sendRedirect() { + try { + URL redirectURL = params.getURLParameter(BKUApplet.REDIRECT_URL, sessionId); + String redirectTarget = params.getAppletParameter(BKUApplet.REDIRECT_TARGET); + if (redirectTarget == null) { + log.info("Done. Redirecting to " + redirectURL + " ..."); + ctx.showDocument(redirectURL); + } else { + log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); + ctx.showDocument(redirectURL, redirectTarget); + } + } catch (MalformedURLException ex) { + log.warn("Failed to redirect: " + ex.getMessage(), ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) + } + } + + private STALPortType getSTALPort() throws MalformedURLException { + URL wsdlURL = params.getURLParameter(BKUApplet.WSDL_URL); + log.debug("STAL WSDL at " + wsdlURL); + QName endpointName = new QName(BKUApplet.STAL_WSDL_NS, BKUApplet.STAL_SERVICE); + STALService stal = new STALService(wsdlURL, endpointName); + return stal.getSTALPort(); + } + + private void registerSignRequestHandler() throws MalformedURLException { + String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); + if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { + log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); + addRequestHandler(SignRequest.class, new WebServiceSignRequestHandler(stalPort, sessionId)); + } else { + //if (HASHDATADISPLAY_EXTERNAL.equals(displayStyle)) { + URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, sessionId); + log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); + addRequestHandler(SignRequest.class, new ExternalDisplaySignRequestHandler(ctx, hashDataURL)); + } + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java new file mode 100644 index 00000000..42e2d6ff --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java @@ -0,0 +1,57 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.online.applet; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * + * @author Clemens Orthacker + */ +public interface AppletParameterProvider { + + /** + * Applet configuration parameters + * + * @param paramKey + * @return null if no parameter is provided for the given key + */ + String getAppletParameter(String paramKey); + + /** + * Get applet configuration parameter as (absolute) URL + * + * @param paramKey + * @return a URL + * @throws MalformedURLException if configured URL is invalid + * or no parameter is provided for the given key + */ + URL getURLParameter(String paramKey) throws MalformedURLException; + + /** + * Get applet configuration parameter as (absolute) URL + * + * @param paramKey + * @param sessionId adds the jsessionid to the URL + * @return a URL + * @throws MalformedURLException if configured URL is invalid + * or no parameter is provided for the given key + */ + URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException; +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index bde055ec..f3eecdf9 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.smccstal.AbstractBKUWorker; import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; @@ -36,9 +37,13 @@ import at.gv.egiz.bku.gui.BKUGUIFactory; * Note: all swing code is executed by the event dispatch thread (see * BKUGUIFacade) */ -public class BKUApplet extends JApplet { +public class BKUApplet extends JApplet implements AppletParameterProvider { private static Log log = LogFactory.getLog(BKUApplet.class); + + /** + * Applet parameter keys + */ public static final String GUI_STYLE = "GuiStyle"; public final static String LOCALE_PARAM_KEY = "Locale"; public final static String LOGO_URL_KEY = "LogoURL"; @@ -51,42 +56,59 @@ public class BKUApplet extends JApplet { public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; - protected BKUWorker worker; + + /** + * STAL WSDL namespace and service name + */ + public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal"; + public static final String STAL_SERVICE = "STALService"; + + /** + * Dummy session id, used if no sessionId parameter is provided + */ + protected static final String TEST_SESSION_ID = "TestSession"; + + /** + * STAL + */ + protected AppletBKUWorker worker; protected Thread workerThread; - public BKUApplet() { - } - + /** + * Factory method to create and wire HelpListener, GUI and BKUWorker. + */ @Override public void init() { - log.info("Welcome to MOCCA\n"); + log.info("Welcome to MOCCA"); log.debug("Called init()"); + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); - String locale = getMyAppletParameter(LOCALE_PARAM_KEY); - if (locale != null) { - this.setLocale(new Locale(locale)); - } - String backgroundString = getMyAppletParameter(BACKGROUND_PARAM); - URL background = null; - if (backgroundString != null) { - try { - background = new URL(backgroundString); - } catch (MalformedURLException ex) { - log.warn(ex.getMessage() + ", using default background"); - } + + String locale = getAppletParameter(LOCALE_PARAM_KEY); + String guiStyle = getAppletParameter(GUI_STYLE); + URL backgroundImgURL = null; + URL helpURL = null; + try { + helpURL = getURLParameter(HELP_URL, getAppletParameter(SESSION_ID)); + } catch (MalformedURLException ex) { + log.warn("failed to load help URL, disabling help: " + ex.getMessage()); } - String guiStyle = getMyAppletParameter(GUI_STYLE); - BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); - log.debug("setting GUI locale to " + getLocale()); - AppletHelpListener helpListener = null; try { - URL helpURL = getMyAppletParameterURL(HELP_URL); - helpListener = new AppletHelpListener(getAppletContext(), helpURL, getLocale()); + backgroundImgURL = getURLParameter(BACKGROUND_PARAM); } catch (MalformedURLException ex) { - log.error("invalid help URL: " + ex.getMessage()); + log.info("failed to load applet background image, using default: " + ex.getMessage()); } - gui.init(getContentPane(), getLocale(), background, helpListener); - worker = new BKUWorker(gui, this); + + if (locale != null) { + this.setLocale(new Locale(locale)); + } + log.debug("setting locale to " + getLocale()); + + BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); + AppletHelpListener helpListener = new AppletHelpListener(getAppletContext(), helpURL, getLocale()); + gui.init(getContentPane(), getLocale(), backgroundImgURL, helpListener); + + worker = new AppletBKUWorker(gui, getAppletContext(), this); } @Override @@ -109,30 +131,43 @@ public class BKUApplet extends JApplet { log.debug("Called destroy()"); } - /** - * Applet configuration parameters - * - * @param paramKey - * @return - */ - String getMyAppletParameter(String paramKey) { - log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); - return getParameter(paramKey); + @Override + public String getAppletParameter(String paramKey) { + String param = getParameter(paramKey); + log.info("applet parameter: " + paramKey + ": " + param); + return param; } - URL getMyAppletParameterURL(String param) throws MalformedURLException { - String hashDataParam = getMyAppletParameter(param); //BKUApplet.HASHDATA_URL); - if (hashDataParam != null) { + @Override + public URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { + String urlParam = getParameter(paramKey); + if (urlParam != null) { URL codebase = getCodeBase(); try { - return new URL(codebase, hashDataParam); + URL url; + if (codebase.getProtocol().equalsIgnoreCase("file")) { + // for debugging in appletrunner + url = new URL(urlParam); + } else { + if (sessionId != null) { + urlParam = urlParam + ";jsessionid=" + sessionId; + } + url = new URL(codebase, urlParam); + } + log.info("applet parameter " + url); + return url; } catch (MalformedURLException ex) { - log.error("Paremeter " + param + " is not a valid URL.", ex); - throw new MalformedURLException(ex.getMessage()); - } + log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); + throw ex; + } } else { - log.error("Paremeter " + param + " not set"); - throw new MalformedURLException(param + " not set"); + log.error("applet paremeter " + urlParam + " not set"); + throw new MalformedURLException(urlParam + " not set"); } } + + @Override + public URL getURLParameter(String paramKey) throws MalformedURLException { + return getURLParameter(paramKey, null); + } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java deleted file mode 100644 index 843f6c4c..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package at.gv.egiz.bku.online.applet; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.ResourceBundle; - -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.xml.namespace.QName; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; -import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.smcc.util.SMCCHelper; -import at.gv.egiz.stal.QuitRequest; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.STALService; -import at.gv.egiz.stal.service.types.ErrorResponseType; -import at.gv.egiz.stal.service.types.GetNextRequestResponseType; -import at.gv.egiz.stal.service.types.GetNextRequestType; -import at.gv.egiz.stal.service.types.ObjectFactory; -import at.gv.egiz.stal.service.types.RequestType; -import at.gv.egiz.stal.service.types.ResponseType; -import at.gv.egiz.stal.util.STALTranslator; - -public class BKUWorker extends AbstractSMCCSTAL implements Runnable, - ActionListener, SMCCSTALRequestHandler { - - private static Log log = LogFactory.getLog(BKUWorker.class); - protected BKUGUIFacade gui; - protected BKUApplet parent; - private STALPortType stalPort; - protected List actionCommandList = new ArrayList(); - protected Boolean actionPerformed = false; - protected boolean finished = false; - - /** - * - * @param gui - * must not be null - */ - public BKUWorker(BKUGUIFacade gui, BKUApplet parent) { - if (gui == null || parent == null) { - throw new NullPointerException("Parameter must not be set to null"); - } - this.gui = gui; - this.locale = gui.getLocale(); - this.parent = parent; - addRequestHandler(QuitRequest.class, this); - // register SignRequestHandler once we have a webservice port - } - - /** - * Used for non applet variants - * - * @param gui - * @param errorMessageBundle - */ - protected BKUWorker(BKUGUIFacade gui) { - this.gui = gui; - this.locale = gui.getLocale(); - addRequestHandler(QuitRequest.class, this); - } - - private STALPortType getSTALPort() throws MalformedURLException { - URL wsdlURL = null; - String wsdlLocation = parent.getMyAppletParameter(BKUApplet.WSDL_URL); - URL codebase = parent.getCodeBase(); - log.debug("Connecting to webservice: " + wsdlLocation); - if (wsdlLocation != null) { - try { - if (codebase.getProtocol().equalsIgnoreCase("file")) { - // for debugging in appletrunner - wsdlURL = new URL(wsdlLocation); - } else { - wsdlURL = new URL(codebase, wsdlLocation); - } - } catch (MalformedURLException ex) { - log.fatal("Paremeter 'wsdlLocation' is not a vailid URL.", ex); - throw new MalformedURLException(ex.getMessage()); - } - } else { - log.fatal("Paremeter 'wsdlLocation' is not set."); - throw new MalformedURLException("Null WSDL url"); - } - log.debug("Found WSDL url: " + wsdlURL); - QName endpointName = new QName("http://www.egiz.gv.at/wsdl/stal", - "STALService"); - STALService stal = new STALService(wsdlURL, endpointName); - return stal.getSTALPort(); - } - - @Override - public void run() { - gui.showWelcomeDialog(); - try { - stalPort = getSTALPort(); - } catch (Exception e) { - log.fatal("Failed to call STAL service.", e); - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, - new Object[] { e.getMessage() }); - try { - waitForAction(); - } catch (InterruptedException e1) { - log.error(e1); - } - return; - } - - try { - String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); - if (sessionId == null) { - // use the testsession for testing - sessionId = "TestSession"; - } - - String hashDataDisplayStyle = parent.getMyAppletParameter(BKUApplet.HASHDATA_DISPLAY); - if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { - log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WebServiceSignRequestHandler(sessionId, stalPort)); - } else { //if (HASHDATADISPLAY_EXTERNAL.equals(displayStyle)) { - URL hashDataURL = parent.getMyAppletParameterURL(BKUApplet.HASHDATA_URL); - log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); - addRequestHandler(at.gv.egiz.stal.SignRequest.class, new ExternalDisplaySignRequestHandler(parent.getAppletContext(), hashDataURL)); - } - -// log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); -// addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WebServiceSignRequestHandler(sessionId, stalPort)); - - ObjectFactory of = new ObjectFactory(); - GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); - do { - List requests = nextRequestResp - .getInfoboxReadRequestOrSignRequestOrQuitRequest(); - List stalRequests = STALTranslator - .translateRequests(requests); - - if (log.isInfoEnabled()) { - StringBuilder sb = new StringBuilder("Received "); - sb.append(stalRequests.size()); - sb.append(" STAL requests: "); - for (STALRequest r : stalRequests) { - sb.append(r.getClass()); - sb.append(' '); - } - log.info(sb.toString()); - } - - boolean handle = true; - for (STALRequest request : stalRequests) { - if (request instanceof at.gv.egiz.stal.InfoboxReadRequest) { - at.gv.egiz.stal.InfoboxReadRequest r = (at.gv.egiz.stal.InfoboxReadRequest) request; - String infoboxId = r.getInfoboxIdentifier(); - String domainId = r.getDomainIdentifier(); - if ("IdentityLink".equals(infoboxId) && domainId == null) { - if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { - handle = false; - } - } - } - } - - List responses; - if (handle) { - List stalResponses = handleRequest(stalRequests); - if (log.isInfoEnabled()) { - StringBuilder sb = new StringBuilder(stalResponses.size()); - sb.append(" STAL responses: "); - for (STALResponse r : stalResponses) { - sb.append(r.getClass()); - sb.append(' '); - } - log.info(sb.toString()); - } - responses = STALTranslator.fromSTAL(stalResponses); - } else { - responses = new ArrayList(1); - ErrorResponseType err = new ErrorResponseType(); - err.setErrorCode(6002); - // err.setErrorMessage(); - responses.add(err); - } - - if (!finished) { - log.info("Not finished yet (BKUWorker: " + this - + "), sending responses"); - GetNextRequestType nextRequest = of.createGetNextRequestType(); - nextRequest.setSessionId(sessionId); - nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse() - .addAll(responses); - nextRequestResp = stalPort.getNextRequest(nextRequest); - } - } while (!finished); - log.info("Done " + Thread.currentThread().getName()); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] { ex - .getMessage() }); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - } - if (signatureCard != null) { - signatureCard.disconnect(false); - } - sendRedirect(); - } - - protected void sendRedirect() { - log.info("Done, sending redirect to get BKU response"); - String redirectURL = parent.getMyAppletParameter(BKUApplet.REDIRECT_URL); - String redirectTarget = parent.getMyAppletParameter(BKUApplet.REDIRECT_TARGET); - log.info("Redirecting to: " + redirectURL + " target: " + redirectTarget); - URL url = null; - if (redirectURL != null) { - try { - url = new URL(parent.getCodeBase(), redirectURL + ";jsessionid=" - + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); - } catch (MalformedURLException ex) { - log.warn("Parameter 'redirectURL': " + redirectURL - + " not a valid URL.", ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) - } - if (url != null) { - if (redirectTarget == null) { - log.info("Done. Trying to redirect to " + url + " ..."); - parent.getAppletContext().showDocument(url); - } else { - log.info("Done. Trying to redirect to " + url + " (target=" - + redirectTarget + ") ..."); - parent.getAppletContext().showDocument(url, redirectTarget); - } - } - } else { - log.error("No redirect URL set"); - } - } - - protected synchronized void waitForAction() throws InterruptedException { - log.info("Waiting for Action"); - while (!actionPerformed) { - wait(); - } - actionPerformed = false; - } - - protected synchronized void actionOccured() { - log.info("Received Action"); - actionPerformed = true; - notifyAll(); - } - - @Override - public void actionPerformed(ActionEvent e) { - log.info("Action: " + e); - if (actionCommandList != null) { - if (actionCommandList.contains(e.getActionCommand())) { - actionOccured(); - } - } else { - actionOccured(); - } - } - - @Override - protected boolean waitForCard() { - SMCCHelper smccHelper = new SMCCHelper(); - actionCommandList.clear(); - actionCommandList.add("cancel"); - // while no sigcard found or cancel button pressed - int oldValue = SMCCHelper.PC_SC_NOT_SUPPORTED; // this is a save default - while ((signatureCard == null) && (!actionPerformed)) { - switch (smccHelper.getResultCode()) { - case SMCCHelper.PC_SC_NOT_SUPPORTED: - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, this, "ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.TERMINAL_NOT_PRESENT: - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_NO_CARDTERMINAL, null, this, "ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.CARD_NOT_SUPPORTED: - if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { - actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showCardNotSupportedDialog(this, "cancel"); - oldValue = SMCCHelper.CARD_NOT_SUPPORTED; - } - break; - case SMCCHelper.NO_CARD: - if (oldValue != SMCCHelper.NO_CARD) { - actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showInsertCardDialog(this, "cancel"); - oldValue = SMCCHelper.NO_CARD; - } - break; - case SMCCHelper.CARD_FOUND: - signatureCard = smccHelper.getSignatureCard(locale); - return false; - } - smccHelper.update(3000); - } - return signatureCard == null; - } - - @Override - public STALResponse handleRequest(STALRequest request) { - if (request instanceof QuitRequest) { - log.info("Setting state to: finished for BKUWorker " + this); - finished = true; - } else { - log.error("Unexpected request to handle: " + request); - } - return null; - } - - @Override - public void init(SignatureCard sc, BKUGUIFacade gui) { - } - - @Override - public boolean requireCard() { - return false; - } - - @Override - protected BKUGUIFacade getGUI() { - return gui; - } - -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java index ddbe76bf..014065f2 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java @@ -45,7 +45,7 @@ public class WebServiceSignRequestHandler extends SignRequestHandler { STALPortType stalPort; String sessId; - public WebServiceSignRequestHandler(String sessId, STALPortType stalPort) { + public WebServiceSignRequestHandler(STALPortType stalPort, String sessId) { if (stalPort == null || sessId == null) { throw new NullPointerException("STAL port must not be null"); } -- cgit v1.2.3