summaryrefslogtreecommitdiff
path: root/BKUApplet/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'BKUApplet/src/main/java/at/gv/egiz')
-rw-r--r--BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java74
-rw-r--r--BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java57
-rw-r--r--BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java106
3 files changed, 85 insertions, 152 deletions
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
index 6ac892ec..388f045f 100644
--- 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
@@ -22,7 +22,6 @@ 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.translator.STALTranslator;
import at.gv.egiz.stal.service.translator.TranslationException;
import at.gv.egiz.stal.service.types.ErrorResponseType;
@@ -31,13 +30,10 @@ 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 java.applet.AppletContext;
import java.net.MalformedURLException;
-import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
-import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceException;
/**
@@ -46,29 +42,19 @@ import javax.xml.ws.WebServiceException;
*/
public class AppletBKUWorker extends AbstractBKUWorker implements Runnable {
- protected AppletContext ctx;
- protected AppletParameterProvider params;
+ protected BKUApplet applet;
protected String sessionId;
- protected STALPortType stalPort;
+
private ObjectFactory stalObjFactory = new ObjectFactory();
- private STALTranslator translator = new STALTranslator();
- public AppletBKUWorker(BKUGUIFacade gui, AppletContext ctx,
- AppletParameterProvider paramProvider) {
+ public AppletBKUWorker(BKUApplet applet, BKUGUIFacade gui) {
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);
+ this.applet = applet;
+
+ sessionId = applet.getParameter(BKUApplet.SESSION_ID);
if (sessionId == null) {
sessionId = "TestSession";
- log.info("using dummy sessionId " + sessionId);
+ log.warn("using dummy sessionId " + sessionId);
}
}
@@ -77,9 +63,11 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable {
gui.showWelcomeDialog();
try {
- stalPort = getSTALPort();
+ STALPortType stalPort = applet.getSTALPort();
+ STALTranslator stalTranslator = applet.getSTALTranslator();
- registerSignRequestHandler(stalPort, sessionId);
+ addRequestHandler(SignRequest.class,
+ new AppletHashDataDisplay(stalPort, sessionId));
GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId);
@@ -111,7 +99,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable {
List<STALRequest> stalRequests = new ArrayList<STALRequest>();
for (JAXBElement<? extends RequestType> req : requests) {
try {
- stalRequests.add(translator.translate(req));
+ stalRequests.add(stalTranslator.translate(req));
} catch (TranslationException ex) {
log.error("Received unknown request from server STAL: " + ex.getMessage());
throw new RuntimeException(ex);
@@ -123,7 +111,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable {
List<STALResponse> stalResponses = handleRequest(stalRequests);
for (STALResponse stalResponse : stalResponses) {
try {
- responses.add(translator.translate(stalResponse));
+ responses.add(stalTranslator.translate(stalResponse));
} catch (TranslationException ex) {
log.error("Received unknown response from STAL: " + ex.getMessage());
throw new RuntimeException(ex);
@@ -184,7 +172,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable {
}
}
- sendRedirect();
+ applet.sendRedirect(sessionId);
}
/**
@@ -218,38 +206,4 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable {
log.error(e);
}
}
-
- 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(STALPortType stalPort, String sessionId) {
- log.debug("register SignRequestHandler (resolve hashdata via STAL Webservice)");
- AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort,
- sessionId);
- addRequestHandler(SignRequest.class, handler);
- }
}
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
deleted file mode 100644
index 42e2d6ff..00000000
--- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java
+++ /dev/null
@@ -1,57 +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.net.MalformedURLException;
-import java.net.URL;
-
-/**
- *
- * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
- */
-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 5e60ed3e..d4b2018d 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,8 +16,10 @@
*/
package at.gv.egiz.bku.online.applet;
+import at.gv.egiz.bku.gui.BKUGUIFacade.Style;
import at.gv.egiz.bku.gui.DefaultHelpListener;
import at.gv.egiz.bku.gui.AbstractHelpListener;
+import at.gv.egiz.stal.service.translator.STALTranslator;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
@@ -30,15 +32,18 @@ import org.apache.commons.logging.LogFactory;
import at.gv.egiz.bku.gui.BKUGUIFacade;
import at.gv.egiz.bku.gui.BKUGUIFactory;
+import at.gv.egiz.stal.service.STALPortType;
+import at.gv.egiz.stal.service.STALService;
+import java.awt.Container;
+import javax.xml.namespace.QName;
/**
* Note: all swing code is executed by the event dispatch thread (see
* BKUGUIFacade)
*/
-public class BKUApplet extends JApplet implements AppletParameterProvider {
+public class BKUApplet extends JApplet {
private static Log log = LogFactory.getLog(BKUApplet.class);
-
/**
* Applet parameter keys
*/
@@ -55,18 +60,15 @@ public class BKUApplet extends JApplet implements AppletParameterProvider {
// public static final String HASHDATA_DISPLAY_INTERNAL = "internal";
// public static final String HASHDATA_DISPLAY_BROWSER = "browser";
public static final String HASHDATA_DISPLAY_FRAME = "frame";
-
/**
* 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
*/
@@ -81,17 +83,17 @@ public class BKUApplet extends JApplet implements AppletParameterProvider {
public void init() {
log.info("Welcome to MOCCA");
log.debug("Called init()");
-
+
HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance());
- String locale = getAppletParameter(LOCALE);
+ String locale = getParameter(LOCALE);
if (locale != null) {
this.setLocale(new Locale(locale));
}
- log.debug("setting locale to " + getLocale());
+ log.debug("setting locale: " + getLocale());
BKUGUIFacade.Style guiStyle;
- String guiStyleParam = getAppletParameter(GUI_STYLE);
+ String guiStyleParam = getParameter(GUI_STYLE);
if ("advanced".equals(guiStyleParam)) {
guiStyle = BKUGUIFacade.Style.advanced;
} else if ("tiny".equals(guiStyleParam)) {
@@ -99,30 +101,33 @@ public class BKUApplet extends JApplet implements AppletParameterProvider {
} else {
guiStyle = BKUGUIFacade.Style.simple;
}
-
+ log.debug("setting gui-style: " + guiStyle);
+
URL backgroundImgURL = null;
try {
- backgroundImgURL = getURLParameter(BACKGROUND_IMG);
+ backgroundImgURL = getURLParameter(BACKGROUND_IMG, null);
+ log.debug("setting background: " + backgroundImgURL);
} catch (MalformedURLException ex) {
log.warn("failed to load applet background image: " + ex.getMessage() + ", using default");
}
-
+
AbstractHelpListener helpListener = null;
try {
- URL helpURL = getURLParameter(HELP_URL);
-// helpListener = new BrowserHelpListener(getAppletContext(), helpURL, getLocale());
- helpListener = new DefaultHelpListener(getAppletContext(), helpURL, getLocale());
+ helpListener = new DefaultHelpListener(getAppletContext(),
+ getURLParameter(HELP_URL, null), getLocale());
+ if (log.isDebugEnabled()) {
+ log.debug("setting helpURL: " + getURLParameter(HELP_URL, null));
+ }
} catch (MalformedURLException ex) {
log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help");
}
-
- BKUGUIFacade gui = BKUGUIFactory.createGUI(getContentPane(),
- getLocale(),
- guiStyle,
- backgroundImgURL,
+
+ BKUGUIFacade gui = createGUI(getContentPane(), getLocale(),
+ guiStyle,
+ backgroundImgURL,
helpListener);
- worker = new AppletBKUWorker(gui, getAppletContext(), this);
+ worker = new AppletBKUWorker(this, gui);
}
@Override
@@ -145,15 +150,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider {
log.debug("Called destroy()");
}
- @Override
- public String getAppletParameter(String paramKey) {
- String param = getParameter(paramKey);
- log.info("applet parameter: " + paramKey + ": " + param);
- return param;
- }
-
- @Override
- public URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException {
+ protected URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException {
String urlParam = getParameter(paramKey);
if (urlParam != null) {
URL codebase = getCodeBase();
@@ -173,15 +170,54 @@ public class BKUApplet extends JApplet implements AppletParameterProvider {
} catch (MalformedURLException ex) {
log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage());
throw ex;
- }
+ }
} else {
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);
+
+ /**
+ * provides a means to for subclasses to inject a different GUI
+ */
+ protected BKUGUIFacade createGUI(Container contentPane,
+ Locale locale,
+ Style guiStyle,
+ URL backgroundImgURL,
+ AbstractHelpListener helpListener) {
+ return BKUGUIFactory.createGUI(contentPane,
+ locale,
+ guiStyle,
+ backgroundImgURL,
+ helpListener);
+ }
+
+ protected STALPortType getSTALPort() throws MalformedURLException {
+ URL wsdlURL = getURLParameter(WSDL_URL, null);
+ log.debug("setting STAL WSDL: " + wsdlURL);
+ QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE);
+ STALService stal = new STALService(wsdlURL, endpointName);
+ return stal.getSTALPort();
+ }
+
+ protected STALTranslator getSTALTranslator() {
+ return new STALTranslator();
+ }
+
+ protected void sendRedirect(String sessionId) {
+ try {
+ URL redirectURL = getURLParameter(REDIRECT_URL, sessionId);
+ String redirectTarget = getParameter(REDIRECT_TARGET);
+ if (redirectTarget == null) {
+ log.info("Done. Redirecting to " + redirectURL + " ...");
+ getAppletContext().showDocument(redirectURL);
+ } else {
+ log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ...");
+ getAppletContext().showDocument(redirectURL, redirectTarget);
+ }
+ } catch (MalformedURLException ex) {
+ log.warn("Failed to redirect: " + ex.getMessage(), ex);
+ // gui.showErrorDialog(errorMsg, okListener, actionCommand)
+ }
}
}