From cac60be3e0be598bf30bc39d813a19c4f213482d Mon Sep 17 00:00:00 2001 From: tkellner Date: Tue, 10 Dec 2013 16:21:26 +0000 Subject: Allow to override servlet init parameters with context parameters git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1247 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/webapp/MoccaParameterBean.java | 17 +++++++++++++++-- .../at/gv/egiz/bku/online/webapp/ResultServlet.java | 4 ++-- .../java/at/gv/egiz/bku/online/webapp/UIServlet.java | 4 ++-- .../at/gv/egiz/bku/online/webapp/WebRequestHandler.java | 4 ++-- .../java/at/gv/egiz/mocca/id/DataURLServerServlet.java | 5 +++-- 5 files changed, 24 insertions(+), 10 deletions(-) (limited to 'BKUOnline/src') diff --git a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/MoccaParameterBean.java b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/MoccaParameterBean.java index 0e2e4b02..4bba6947 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/MoccaParameterBean.java +++ b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/MoccaParameterBean.java @@ -36,6 +36,8 @@ import java.util.Arrays; import java.util.Locale; import java.util.regex.Pattern; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; import javax.servlet.http.HttpServletResponse; import org.apache.commons.configuration.Configuration; @@ -47,8 +49,8 @@ import at.gv.egiz.bku.utils.StreamUtil; public class MoccaParameterBean { - private final Logger log = LoggerFactory.getLogger(MoccaParameterBean.class); - + private static final Logger log = LoggerFactory.getLogger(MoccaParameterBean.class); + public static final String PARAM_UI_PAGE_P = "appletPage"; public static final String PARAM_APPLET_WIDTH = "appletWidth"; @@ -234,4 +236,15 @@ public class MoccaParameterBean { response.addHeader("P3P", P3P_POLICY); } } + + public static String getInitParameter(String name, ServletConfig config, + ServletContext context) { + String initVal = config.getInitParameter(name); + String contextVal = context.getInitParameter(config.getServletName() + "." + name); + log.debug("Reading init param " + name + ": " + initVal + + " - context param " + (config.getServletName() + "." + name) + ": " + contextVal); + if (contextVal != null) + return contextVal; + return initVal; + } } 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 9c531a3c..67253f24 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 @@ -63,12 +63,12 @@ public class ResultServlet extends HttpServlet { @Override public void init() throws ServletException { - String encoding = getServletConfig().getInitParameter("responseEncoding"); + String encoding = MoccaParameterBean.getInitParameter("responseEncoding", getServletConfig(), getServletContext()); if (encoding != null) { log.info("Init default responseEncoding to: {}.", encoding); responseEncoding = encoding; } - String url = getServletConfig().getInitParameter("expiredPageUrl"); + String url = MoccaParameterBean.getInitParameter("expiredPageUrl", getServletConfig(), getServletContext()); if (url != null) { // try { // expiredPageUrl = new URL(url).toString(); diff --git a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/UIServlet.java b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/UIServlet.java index 1a1c30d0..0b344f9d 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/UIServlet.java +++ b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/UIServlet.java @@ -55,7 +55,7 @@ public class UIServlet extends HttpServlet { @Override public void init() throws ServletException { - String url = getServletConfig().getInitParameter("expiredPageUrl"); + String url = MoccaParameterBean.getInitParameter("expiredPageUrl", getServletConfig(), getServletContext()); if (url != null) { // try { // expiredPageUrl = new URL(url).toString(); @@ -99,7 +99,7 @@ public class UIServlet extends HttpServlet { MoccaParameterBean parameterBean = new MoccaParameterBean((HTTPBindingProcessor) bindingProcessor); req.setAttribute("moccaParam", parameterBean); - String uiPage = getServletConfig().getInitParameter("uiPage"); + String uiPage = MoccaParameterBean.getInitParameter("uiPage", getServletConfig(), getServletContext()); uiPage = parameterBean.getUIPage(uiPage); if (uiPage == null) { uiPage = "applet.jsp"; diff --git a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/WebRequestHandler.java b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/WebRequestHandler.java index 6accc5a1..2912fb02 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/WebRequestHandler.java +++ b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/WebRequestHandler.java @@ -56,7 +56,7 @@ public class WebRequestHandler extends HttpServlet { @Override public void init() throws ServletException { - String url = getServletConfig().getInitParameter("uiRedirectUrl"); + String url = MoccaParameterBean.getInitParameter("uiRedirectUrl", getServletConfig(), getServletContext()); if (url != null) { uiRedirectUrl = url; log.info("Init uiRedirectUrl to: {}.", uiRedirectUrl); @@ -99,7 +99,7 @@ public class WebRequestHandler extends HttpServlet { } // create new binding processor - String protocol = getServletConfig().getInitParameter("protocol"); + String protocol = MoccaParameterBean.getInitParameter("protocol", getServletConfig(), getServletContext()); if (protocol == null || protocol.isEmpty()) { protocol = req.getScheme(); } diff --git a/BKUOnline/src/main/java/at/gv/egiz/mocca/id/DataURLServerServlet.java b/BKUOnline/src/main/java/at/gv/egiz/mocca/id/DataURLServerServlet.java index 3e47fd79..7dd2cd22 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/mocca/id/DataURLServerServlet.java +++ b/BKUOnline/src/main/java/at/gv/egiz/mocca/id/DataURLServerServlet.java @@ -53,6 +53,7 @@ import at.gv.egiz.bku.binding.FormParameter; import at.gv.egiz.bku.binding.Id; import at.gv.egiz.bku.binding.InputDecoder; import at.gv.egiz.bku.binding.InputDecoderFactory; +import at.gv.egiz.bku.online.webapp.MoccaParameterBean; import at.gv.egiz.bku.slcommands.SLCommand; import at.gv.egiz.bku.slcommands.SLMarshallerFactory; import at.gv.egiz.bku.slcommands.SLResult; @@ -185,12 +186,12 @@ public class DataURLServerServlet extends HttpServlet { } // create new binding processor - String protocol = getServletConfig().getInitParameter("protocol"); + String protocol = MoccaParameterBean.getInitParameter("protocol", getServletConfig(), getServletContext()); if (protocol == null || protocol.isEmpty()) { protocol = req.getScheme(); } SAMLBindingProcessorImpl bindingProcessor = (SAMLBindingProcessorImpl) bindingProcessorManager - .createBindingProcessor(protocol, locale); + .createBindingProcessor(protocol, locale); if (bindingProcessor != null && respElement != null) { -- cgit v1.2.3