aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java119
1 files changed, 46 insertions, 73 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java
index abfb4a1c0..244197379 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java
@@ -20,6 +20,7 @@ import at.gv.egovernment.moa.id.moduls.IRequest;
import at.gv.egovernment.moa.id.moduls.ModulStorage;
import at.gv.egovernment.moa.id.moduls.NoPassivAuthenticationException;
import at.gv.egovernment.moa.id.moduls.RequestStorage;
+import at.gv.egovernment.moa.id.storage.ExceptionStoreImpl;
import at.gv.egovernment.moa.id.util.MOAIDMessageProvider;
import at.gv.egovernment.moa.logging.Logger;
@@ -33,64 +34,6 @@ public class DispatcherServlet extends AuthServlet {
public static final String PARAM_TARGET_MODULE = "mod";
public static final String PARAM_TARGET_ACTION = "action";
- /*
- * public static final String PARAM_DISPATCHER_TARGETS =
- * "DispatcherTargets"; public static final String PARAM_DISPATCHER_TYPE =
- * "DispatcherType"; public static final String PARAM_DISPATCHER_TYPE_UNAUTH
- * = "UNAUTH"; public static final String PARAM_DISPATCHER_TYPE_AUTH =
- * "AUTH"; public static String SYSTEM_NEWLINE =
- * System.getProperty("line.separator");
- */
- /*
- * private HashMap<String, HashMap<String, HttpServlet>> endpointMap = new
- * HashMap<String, HashMap<String, HttpServlet>>();
- *
- * private void registerModule(IModulInfo modulInfo) {
- *
- * HashMap<String, HttpServlet> tempMap = new HashMap<String,
- * HttpServlet>();
- *
- * try {
- *
- * String path = modulInfo.getPath();
- *
- * if (path == null) { throw new Exception(String.format(
- * "%s does not return a valid target path!", new Object[] {
- * modulInfo.getClass().getName() })); }
- *
- * Logger.debug("Registering: " + modulInfo.getName() + " under " + path);
- *
- * List<ServletInfo> servletInfos = modulInfo.getServlets();
- *
- * Iterator<ServletInfo> servletInfoIterator = servletInfos.iterator();
- *
- * while (servletInfoIterator.hasNext()) {
- *
- * ServletInfo servletInfo = servletInfoIterator.next();
- *
- * if (servletInfo.getType() == ServletType.UNAUTH) { HttpServlet servlet =
- * servletInfo.getServletInstance(); String target =
- * servletInfo.getTarget();
- *
- * if (target == null) { throw new Exception( String.format(
- * "%s does not return a valid target identifier!", new Object[] {
- * servlet.getClass() .getName() })); }
- *
- * if (tempMap.containsKey(target)) { throw new Exception(String.format(
- * "%s tried to overwrite %s/%s", new Object[] {
- * servlet.getClass().getName(), path, target })); }
- *
- * tempMap.put(target, servlet); Logger.info("Registered Servlet class: " +
- * servlet.getClass().getName() + " OK"); }
- *
- * }
- *
- * // when there was no error we register all servlets into the real //
- * endpoint map ... if (!tempMap.isEmpty()) { endpointMap.put(path,
- * tempMap); } } catch (Throwable e) {
- * Logger.error("Registering Modul class: " + modulInfo.getClass().getName()
- * + " FAILED!!", e); } }
- */
@Override
public void init(ServletConfig config) throws ServletException {
try {
@@ -105,20 +48,53 @@ public class DispatcherServlet extends AuthServlet {
throw new ServletException(ex);
}
Logger.info("Dispatcher Servlet initialization");
-
- /*
- * List<IModulInfo> modules = ModulStorage.getAllModules();
- * Iterator<IModulInfo> it = modules.iterator(); while (it.hasNext()) {
- * IModulInfo info = it.next(); String targetClass =
- * info.getClass().getName(); try { registerModule(info); } catch
- * (Throwable e) { Logger.error("Registering Class " + targetClass +
- * " FAILED!!", e); } }
- */
}
protected void processRequest(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
try {
+ Logger.info("REQUEST: " + req.getRequestURI());
+ Logger.info("QUERY : " + req.getQueryString());
+ String errorid = req.getParameter(ERROR_CODE_PARAM);
+ if (errorid != null) {
+
+ Throwable throwable = ExceptionStoreImpl.getStore()
+ .fetchException(errorid);
+ ExceptionStoreImpl.getStore().removeException(errorid);
+
+ if (throwable != null) {
+
+ IRequest errorRequest = RequestStorage
+ .getPendingRequest(req.getSession());
+ if (errorRequest != null) {
+ try {
+ IModulInfo handlingModule = ModulStorage
+ .getModuleByPath(errorRequest
+ .requestedModule());
+ if (handlingModule != null) {
+ if (handlingModule.generateErrorMessage(
+ throwable, req, resp, errorRequest)) {
+ return;
+ }
+ }
+ } catch (Throwable e) {
+ Logger.error(e);
+ handleErrorNoRedirect(throwable.getMessage(),
+ throwable, req, resp);
+ }
+ }
+ handleErrorNoRedirect(throwable.getMessage(), throwable,
+ req, resp);
+
+ } else {
+ // TODO: use better string
+ handleErrorNoRedirect("UNKOWN ERROR DETECTED!", null, req,
+ resp);
+ }
+
+ return;
+ }
+
Object moduleObject = req.getParameter(PARAM_TARGET_MODULE);
String module = null;
if (moduleObject != null && (moduleObject instanceof String)) {
@@ -181,8 +157,7 @@ public class DispatcherServlet extends AuthServlet {
HttpSession httpSession = req.getSession();
IRequest protocolRequest = null;
try {
- protocolRequest = RequestStorage
- .getPendingRequest(httpSession);
+ protocolRequest = RequestStorage.getPendingRequest(httpSession);
if (protocolRequest != null) {
// check if pending request is same protocol and action
@@ -253,12 +228,10 @@ public class DispatcherServlet extends AuthServlet {
}
moduleAction.processRequest(protocolRequest, req, resp);
-
- RequestStorage.removePendingRequest(httpSession);
-
+ RequestStorage.removePendingRequest(httpSession);
authmanager.logout(req, resp);
-
+
} catch (Throwable e) {
e.printStackTrace();
// Try handle module specific, if not possible rethrow