From 2fb00e3ccc0ffa8e06cab2b0c50b5025ea42d53a Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 25 Nov 2002 21:59:46 +0000 Subject: [PATCH] use req.getContextPath to find the RootUri.. much more robust. 4.0 and 4.1 compatible due to new web.xml mapping --- etc/web.xml | 24 +++++++++--------------- source/Mir.java | 13 +++++++++++-- source/OpenMir.java | 7 +++++++ source/mir/misc/HTMLTemplateProcessor.java | 2 +- source/mir/misc/MirConfig.java | 18 +++++++++--------- source/mir/servlet/AbstractServlet.java | 14 ++++++-------- source/mircoders/producer/Producer.java | 1 - 7 files changed, 43 insertions(+), 36 deletions(-) diff --git a/etc/web.xml b/etc/web.xml index 7169c059..c1b1d009 100755 --- a/etc/web.xml +++ b/etc/web.xml @@ -35,27 +35,21 @@ - + - OutputMir + Mir - - OutputMir - - - - Config - config - - - + + /Mir + + Mir - /Mir + /servlet/Mir @@ -65,8 +59,8 @@ - OutputMir - /OutputMir + OpenMir + /servlet/OpenMir diff --git a/source/Mir.java b/source/Mir.java index f66b9a7d..545d85f0 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -58,9 +58,12 @@ import java.util.Locale; * Mir.java - main servlet, that dispatches to servletmodules * * @author $Author: mh $ - * @version $Revision: 1.17.2.1 $ $Date: 2002/09/01 21:31:39 $ + * @version $Revision: 1.17.2.2 $ $Date: 2002/11/25 21:59:47 $ * * $Log: Mir.java,v $ + * Revision 1.17.2.2 2002/11/25 21:59:47 mh + * use req.getContextPath to find the RootUri.. much more robust. 4.0 and 4.1 compatible due to new web.xml mapping + * * Revision 1.17.2.1 2002/09/01 21:31:39 mh * Mir goes GPL * @@ -76,6 +79,8 @@ public class Mir extends AbstractServlet { private static ModuleMessage messageModule = null; private final static HashMap servletModuleInstanceHash = new HashMap(); + private static boolean nameSet = false; + public HttpSession session; public void doGet(HttpServletRequest req, HttpServletResponse res) @@ -95,7 +100,11 @@ public class Mir extends AbstractServlet { if (getServletContext().getAttribute("mir.confed") == null) { getConfig(req); } - MirConfig.setServletName(getServletName()); + + if (!nameSet) { + MirConfig.setAdminServletName(getServletName()); + nameSet = true; + } session = req.getSession(true); diff --git a/source/OpenMir.java b/source/OpenMir.java index da49b755..912a6664 100755 --- a/source/OpenMir.java +++ b/source/OpenMir.java @@ -61,6 +61,8 @@ public class OpenMir extends AbstractServlet { private static String lang; public HttpSession session; + private boolean nameSet = false; + public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { doPost(req,res); @@ -77,6 +79,11 @@ public class OpenMir extends AbstractServlet { if(getServletContext().getAttribute("mir.confed") == null) { getConfig(req); } + if (!nameSet) { + MirConfig.setOpenServletName(getServletName()); + nameSet = true; + } + session = req.getSession(); if(session.getAttribute("Language")==null){ diff --git a/source/mir/misc/HTMLTemplateProcessor.java b/source/mir/misc/HTMLTemplateProcessor.java index 63f088ee..f517a3ce 100755 --- a/source/mir/misc/HTMLTemplateProcessor.java +++ b/source/mir/misc/HTMLTemplateProcessor.java @@ -87,7 +87,7 @@ public final class HTMLTemplateProcessor { //actionRoot = docRoot + "/servlet/" + MirConfig.getProp("ServletName"); //actionRoot = docRoot + "/servlet/NadirAktuell"; - actionRoot = docRoot + "/servlet/Mir"; + actionRoot = docRoot + "/Mir"; defEncoding = MirConfig.getProp("Mir.DefaultEncoding"); openAction = MirConfig.getProp("Producer.OpenAction"); diff --git a/source/mir/misc/MirConfig.java b/source/mir/misc/MirConfig.java index c628d480..b1887522 100755 --- a/source/mir/misc/MirConfig.java +++ b/source/mir/misc/MirConfig.java @@ -74,14 +74,14 @@ public class MirConfig extends Configuration { * @param name, The name of the servlet (usually "Mir") * @param confName, the name of the config file to load. */ - public static synchronized void initConfig(ServletContext ctx, String uri, + public static synchronized void initConfig(ServletContext ctx, String ctxPath, String name, String confName) { initConfResource(confName); configHash = new HashMap(); configHash.put("Home", ctx.getRealPath("/")); configHash.put("ServletContext", ctx); - configHash.put("RootUri", uri); + configHash.put("RootUri", ctxPath); Enumeration resKeys = getResourceKeys(); while(resKeys.hasMoreElements()) { @@ -89,13 +89,13 @@ public class MirConfig extends Configuration { configHash.put(keyNm, getProperty(keyNm)); } } - /** - * Returns the property asked for by pulling it out a HashMap - * @param a String containing the property name (key) - * @return a String containing the prop. value - */ - public static void setServletName(String servletName) { - configHash.put("ServletName",servletName); + + public static void setAdminServletName(String servletName) { + configHash.put("AdminServletName",servletName); + } + + public static void setOpenServletName(String servletName) { + configHash.put("OpenServletName",servletName); } /** diff --git a/source/mir/servlet/AbstractServlet.java b/source/mir/servlet/AbstractServlet.java index 715c8306..ef36bf2f 100755 --- a/source/mir/servlet/AbstractServlet.java +++ b/source/mir/servlet/AbstractServlet.java @@ -46,10 +46,10 @@ import java.util.Random; /** * Title: Mir * Description: Abstract servlet-class - * Copyright: Copyright (c) 2001 - * Company: Indymedia - * @author idfx - * @version 1.0 + * Copyright: Copyright (c) 2001, 2002 + * Company: Mir-coders group + * @author idfx, the Mir-coders group + * @version $Id: AbstractServlet.java,v 1.15.4.4 2002/11/25 21:59:46 mh Exp $ */ public abstract class AbstractServlet extends HttpServlet { @@ -63,14 +63,12 @@ public abstract class AbstractServlet extends HttpServlet { throws UnavailableException { //String RealPath = super.getServletContext().getRealPath("/"); - String uri = req.getRequestURI(); String name = super.getServletName(); - String rootUri = StringUtil.replace(uri, "/servlet/"+name, ""); // init config //MirConfig.initConfig(RealPath, RootUri, Name, getInitParameter("Config")); - MirConfig.initConfig(super.getServletContext(), rootUri, name, - getInitParameter("Config")); + MirConfig.initConfig(super.getServletContext(), req.getContextPath(), + name, getInitParameter("Config")); theLog = Logfile.getInstance(MirConfig.getPropWithHome(name + ".Logfile")); theLog.printInfo(name + " started."); diff --git a/source/mircoders/producer/Producer.java b/source/mircoders/producer/Producer.java index c62d9ca9..94e08e53 100755 --- a/source/mircoders/producer/Producer.java +++ b/source/mircoders/producer/Producer.java @@ -50,7 +50,6 @@ abstract public class Producer { protected static String producerProductionHost = MirConfig.getProp("Producer.ProductionHost"); protected static String producerOpenAction = MirConfig.getProp("Producer.OpenAction");; - /** @todo same as in HTMLTemplateProcessor, this should be dynamically set */ protected static String actionRoot = MirConfig.getProp("RootUri") + "/Mir"; protected static Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home") + "/" + MirConfig.getProp("Producer.Logfile")); -- 2.11.0