summaryrefslogtreecommitdiff
path: root/BKUOnline/src/main/java/at/gv/egiz/bku
diff options
context:
space:
mode:
Diffstat (limited to 'BKUOnline/src/main/java/at/gv/egiz/bku')
-rw-r--r--BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java93
-rw-r--r--BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/HashDataInputServlet.java144
-rw-r--r--BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/ResultServlet.java23
3 files changed, 85 insertions, 175 deletions
diff --git a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java
index 660fee78..d9be0981 100644
--- a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java
+++ b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -32,6 +33,7 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import at.gv.egiz.bku.binding.BindingProcessor;
import at.gv.egiz.bku.binding.HTTPBindingProcessor;
import at.gv.egiz.bku.binding.HttpUtil;
import at.gv.egiz.bku.binding.IdFactory;
@@ -43,14 +45,16 @@ import at.gv.egiz.org.apache.tomcat.util.http.AcceptLanguage;
*
*/
public class BKURequestHandler extends SpringBKUServlet {
+ public static final String BKU_APPLET_JSP = "BKUApplet";
private static final long serialVersionUID = 1L;
- public final static String REDIRECT_URL = "appletPage.jsp";
+ public final static String REDIRECT_URL_SESSION_ATTRIBUTE="redirectUrl";
protected Log log = LogFactory.getLog(BKURequestHandler.class);
- private static String getStringFromStream(InputStream is, String encoding) throws IOException {
+ private static String getStringFromStream(InputStream is, String encoding)
+ throws IOException {
if (is == null) {
return null;
}
@@ -61,28 +65,41 @@ public class BKURequestHandler extends SpringBKUServlet {
StreamUtil.copyStream(is, os);
return new String(os.toByteArray(), encoding);
}
-
-
+
+ @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, java.io.IOException {
- log.debug("Got new request");
- HttpSession session = req.getSession();
- String lang = req.getHeader("Accept-Language");
- Locale locale = AcceptLanguage.getLocale(lang);
- log.debug("Using locale: " + locale);
-
+ log.debug("Received new request");
+
+ HttpSession session = req.getSession(false);
if (session != null) {
log.warn("Already a session with id: " + session.getId()
- + " active, deleting this one");
- getBindingProcessorManager().removeBindingProcessor(
+ + " active, trying to get Bindingprocessor");
+ BindingProcessor bp = getBindingProcessorManager().getBindingProcessor(
IdFactory.getInstance().createId(session.getId()));
+ if (bp != null) {
+ log.debug("Found binding processor, using this one");
+ RequestDispatcher dispatcher = getServletContext().getNamedDispatcher(
+ BKU_APPLET_JSP);
+ log.debug("forward to applet");
+ dispatcher.forward(req, resp);
+ return;
+ }
+ log.debug("Did not find a binding processor, creating new ...");
}
- String id = req.getSession(true).getId();
- log.debug("Using session id: " + id);
- HTTPBindingProcessor bindingProcessor;
+ session = req.getSession(true);
+ if (log.isDebugEnabled()) {
+ log.debug("Using session id: " + session.getId());
+ }
+
+ String acceptLanguage = req.getHeader("Accept-Language");
+ Locale locale = AcceptLanguage.getLocale(acceptLanguage);
+ log.debug("Accept-Language locale: " + locale);
+ HTTPBindingProcessor bindingProcessor;
bindingProcessor = (HTTPBindingProcessor) getBindingProcessorManager()
- .createBindingProcessor(req.getRequestURL().toString(), id, locale);
+ .createBindingProcessor(req.getRequestURL().toString(),
+ session.getId(), locale);
Map<String, String> headerMap = new HashMap<String, String>();
for (Enumeration<String> headerName = req.getHeaderNames(); headerName
@@ -102,13 +119,20 @@ public class BKURequestHandler extends SpringBKUServlet {
bindingProcessor.consumeRequestStream(req.getInputStream());
req.getInputStream().close();
getBindingProcessorManager().process(bindingProcessor);
-
+
log.trace("Trying to find applet parameters in request");
- String width = getStringFromStream(bindingProcessor.getFormData("appletWidth"), charset);
- String height = getStringFromStream(bindingProcessor.getFormData("appletHeight"), charset);
- String background = getStringFromStream(bindingProcessor.getFormData("appletBackground"), charset);
- String guiStyle = getStringFromStream(bindingProcessor.getFormData("appletGuiStyle"), charset);
- String hashDataDisplay = getStringFromStream(bindingProcessor.getFormData("appletHashDataDisplay"), charset);
+ String width = getStringFromStream(bindingProcessor
+ .getFormData("appletWidth"), charset);
+ String height = getStringFromStream(bindingProcessor
+ .getFormData("appletHeight"), charset);
+ String background = getStringFromStream(bindingProcessor
+ .getFormData("appletBackground"), charset);
+ String guiStyle = getStringFromStream(bindingProcessor
+ .getFormData("appletGuiStyle"), charset);
+ String hashDataDisplay = getStringFromStream(bindingProcessor
+ .getFormData("appletHashDataDisplay"), charset);
+ String localeFormParam = getStringFromStream(bindingProcessor
+ .getFormData("locale"), charset);
if (width != null) {
try {
log.trace("Found applet width parameter: " + width);
@@ -139,11 +163,30 @@ public class BKURequestHandler extends SpringBKUServlet {
log.trace("Found applet hash data display parameter: " + hashDataDisplay);
session.setAttribute("appletHashDataDisplay", hashDataDisplay);
}
- String redirectUrl = REDIRECT_URL+";jsessionid="+session.getId();
- log.debug("Redirecting to: "+redirectUrl);
- resp.sendRedirect(redirectUrl);
+ if (localeFormParam != null) {
+ log.debug("overrule accept-language locale " + locale
+ + " with form param " + localeFormParam);
+ locale = new Locale(localeFormParam);
+ }
+ if (locale != null) {
+ log.debug("Using locale " + locale);
+ session.setAttribute("locale", locale.toString());
+ }
+
+ // handle server side redirect url after processing
+ String redirectUrl = bindingProcessor.getRedirectURL();
+ if ( redirectUrl != null) {
+ log.debug("Got redirect URL "+redirectUrl+". Deferring browser redirect.");
+ session.setAttribute(REDIRECT_URL_SESSION_ATTRIBUTE, redirectUrl);
+ }
+ // TODO error if no dispatcher found
+ RequestDispatcher dispatcher = getServletContext().getNamedDispatcher(
+ BKU_APPLET_JSP);
+ log.debug("forward to applet");
+ dispatcher.forward(req, resp);
}
+ @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, java.io.IOException {
doPost(req, resp);
diff --git a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/HashDataInputServlet.java b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/HashDataInputServlet.java
deleted file mode 100644
index c095fcc8..00000000
--- a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/HashDataInputServlet.java
+++ /dev/null
@@ -1,144 +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.webapp;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.List;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import at.gv.egiz.bku.binding.BindingProcessor;
-import at.gv.egiz.bku.binding.Id;
-import at.gv.egiz.bku.binding.IdFactory;
-import at.gv.egiz.bku.slexceptions.SLRuntimeException;
-import at.gv.egiz.bku.utils.StreamUtil;
-import at.gv.egiz.stal.HashDataInput;
-import at.gv.egiz.stal.STAL;
-import at.gv.egiz.stal.service.impl.STALRequestBroker;
-
-public class HashDataInputServlet extends SpringBKUServlet {
-
- private static Log log = LogFactory.getLog(HashDataInputServlet.class);
-
- public HashDataInputServlet() {
-
- }
-
- private STALRequestBroker getSTAL(Id id) {
- BindingProcessor bp = getBindingProcessorManager().getBindingProcessor(id);
- if (bp == null) {
- return null;
- }
- STAL stal = bp.getSTAL();
- if (stal instanceof STALRequestBroker) {
- return (STALRequestBroker) stal;
- } else {
- throw new SLRuntimeException("Unexpected STAL type");
- }
- }
-
- private static boolean isMSIE(HttpServletRequest req) {
- String useragent = req.getHeader("User-Agent");
- String user = useragent.toLowerCase();
- return (user.indexOf("msie") != -1);
- }
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- if ((req.getSession() == null) && (req.getSession().getId() != null)) {
- log.warn("Got request for hashdatainput without session info");
- resp.sendRedirect("expired.html");
- return;
- }
- Id sessionId = IdFactory.getInstance().createId(req.getSession().getId());
- log.debug("Got request for hashdata for session " + sessionId);
- STALRequestBroker rb = getSTAL(sessionId);
- if (rb == null) {
- log.info("STAL instance not found for session: " + sessionId);
- resp.sendRedirect("expired.html");
- return;
- }
- List<HashDataInput> hdi = rb.getHashDataInput();
- log.debug("Got hashdata list with " + hdi.size() + " entries");
- String param = req.getParameter("refId");
- log.debug("Got request for refId:" + param);
- if ((param == null) && (hdi.size() > 1)) {
- resp.sendRedirect("multiHashDataInput.html");
- return;
- }
-
- if ((param == null) && (hdi.size() == 1)) {
- param = hdi.get(0).getReferenceId();
- log.debug("Request parameter not set, setting to: " + param);
- }
- for (HashDataInput hd : hdi) {
- if (hd.getReferenceId().equals(param)) {
- log.debug("Found hashdatainput for refId:" + param);
- resp.setContentType(hd.getMimeType());
-
- String charSet = hd.getEncoding();
- if (charSet == null) {
- charSet = "UTF-8";
- }
- resp.setCharacterEncoding(charSet);
- if (isMSIE(req)) {
- String fileExt = hd.getMimeType().equalsIgnoreCase("text/plain") ? ".txt"
- : ".xhtml";
- if (fileExt.equals(".xhtml")) {
- if (req.getParameter("ieCType") == null) {
- resp.sendRedirect("ieView.html");
- return;
- } else {
- resp.setContentType(req.getParameter("ieCType"));
- if (req.getParameter("ieCType").equals("application/xhtml+xml")) {
- resp.addHeader("content-disposition", "attachment; filename="
- + param + ".xhtml");
- }
- }
- }
- }
- Reader r = new InputStreamReader(hd.getHashDataInput(), charSet);
- Writer w = new OutputStreamWriter(resp.getOutputStream(), charSet);
- StreamUtil.copyStream(r, w);
- w.flush();
- return;
-
- }
- }
- log.error("Cannot find hashdata for id:" + param);
- resp.sendError(404);
- return;
- }
-
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- doGet(req, resp);
- }
-
-}
diff --git a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/ResultServlet.java b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/ResultServlet.java
index 9e69099d..f271dfc9 100644
--- a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/ResultServlet.java
+++ b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/ResultServlet.java
@@ -31,7 +31,7 @@ import org.apache.commons.logging.LogFactory;
import at.gv.egiz.bku.binding.HTTPBindingProcessor;
import at.gv.egiz.bku.binding.HttpUtil;
import at.gv.egiz.bku.binding.IdFactory;
-import at.gv.egiz.bku.conf.Configurator;
+import at.gv.egiz.bku.utils.NullOutputStream;
/**
* Delivers the result to the browser
@@ -99,9 +99,20 @@ public class ResultServlet extends SpringBKUServlet {
resp.sendRedirect(expiredPage);
return;
}
-
- if (bp.getRedirectURL() != null) {
- resp.sendRedirect(bp.getRedirectURL());
+ String redirectUrl = (String) session
+ .getAttribute(BKURequestHandler.REDIRECT_URL_SESSION_ATTRIBUTE);
+ if (redirectUrl == null) {
+ redirectUrl = bp.getRedirectURL();
+ }
+ if (redirectUrl != null) {
+ try {
+ bp.writeResultTo(new NullOutputStream(), encoding);
+ getBindingProcessorManager().removeBindingProcessor(bp.getId());
+ } finally {
+ log.debug("Executing deferred browser redirect to: " + redirectUrl);
+ resp.sendRedirect(redirectUrl);
+ session.invalidate();
+ }
return;
}
resp.setStatus(bp.getResponseCode());
@@ -109,8 +120,8 @@ public class ResultServlet extends SpringBKUServlet {
resp.setHeader("Pragma", "no-cache"); // HTTP 1.0
resp.setDateHeader("Expires", 0);
if (configurator.getProperty(USER_AGENT_PROPERTY_KEY) != null) {
- resp.setHeader(HttpUtil.HTTP_HEADER_USER_AGENT, configurator.getProperty(
- USER_AGENT_PROPERTY_KEY));
+ resp.setHeader(HttpUtil.HTTP_HEADER_USER_AGENT, configurator
+ .getProperty(USER_AGENT_PROPERTY_KEY));
} else {
resp.setHeader(HttpUtil.HTTP_HEADER_USER_AGENT,
"citizen-card-environment/1.2 MOCCA Unknown");