From 8b32456fed407f7d764888e2557e6e2e1979fef3 Mon Sep 17 00:00:00 2001 From: bertung Date: Sat, 14 Mar 2015 18:09:55 +0200 Subject: [PATCH 1/3] getInitParameter also from ServletContext If the init parameter does not exists in servlet configuration, also check the servlet context for it. --- .../main/java/org/atmosphere/cpr/AtmosphereConfig.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereConfig.java b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereConfig.java index 460688a6ed7..1195707fd99 100755 --- a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereConfig.java +++ b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereConfig.java @@ -106,11 +106,15 @@ public Map handlers() { * Return the value of the init params defined in web.xml or application.xml. * * @param name the name - * @return the list of init params defined in web.xml or application.xml + * @return the value for the init parameter if defined */ public String getInitParameter(String name) { try { - return framework.getServletConfig().getInitParameter(name); + String value=framework.getServletConfig().getInitParameter(name); + if(value==null) { + value=framework.getServletContext().getInitParameter(name); + } + return value; } catch (Throwable ex) { // Don't fail if Tomcat crash on startup with an NPE return null; @@ -120,7 +124,7 @@ public String getInitParameter(String name) { /** * Return all init param. * - * @return + * @return the list of init params defined in web.xml or application.xml for the servlet */ public Enumeration getInitParameterNames() { return framework().getServletConfig().getInitParameterNames(); From 1dcad704063f50839d1bba39d20003e16e8ae878 Mon Sep 17 00:00:00 2001 From: bertung Date: Mon, 16 Mar 2015 17:21:26 +0200 Subject: [PATCH 2/3] Add a configuration parameter for Servlet Context Init Parameter use Add a configuration parameter to use Servlet Context Init Parameters if an init parameter is not defined for the servlet configuration. --- .../main/java/org/atmosphere/cpr/ApplicationConfig.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/cpr/src/main/java/org/atmosphere/cpr/ApplicationConfig.java b/modules/cpr/src/main/java/org/atmosphere/cpr/ApplicationConfig.java index 6ffca18e6cf..c446ac11012 100644 --- a/modules/cpr/src/main/java/org/atmosphere/cpr/ApplicationConfig.java +++ b/modules/cpr/src/main/java/org/atmosphere/cpr/ApplicationConfig.java @@ -900,5 +900,12 @@ public interface ApplicationConfig { * Value: org.atmosphere.cpr.AsynchronousProcessor.closeOnCancel */ java.lang.String CLOSE_STREAM_ON_CANCEL = "org.atmosphere.cpr.AsynchronousProcessor.closeOnCancel"; + + /** + * Use init parameters specified for servlet context in addition to servlet config + * Default: false + * Value: org.atmosphere.cpr.AtmosphereConfig.getInitParameter + */ + java.lang.String USE_SERVLET_CONTEXT_PARAMETERS = "org.atmosphere.cpr.AtmosphereConfig.getInitParameter"; } From 41d97a409bf462d8104e18d256ab6b88690d8830 Mon Sep 17 00:00:00 2001 From: bertung Date: Mon, 16 Mar 2015 17:28:48 +0200 Subject: [PATCH 3/3] Add a configurable for the servler context init parameter use Add a configurable for the servler context init parameter use so that the existing application may not have any side effects --- .../src/main/java/org/atmosphere/cpr/AtmosphereConfig.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereConfig.java b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereConfig.java index 1195707fd99..7864831eaa0 100755 --- a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereConfig.java +++ b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereConfig.java @@ -44,6 +44,7 @@ public class AtmosphereConfig { private boolean supportSession; private boolean sessionTimeoutRemovalAllowed; private boolean throwExceptionOnCloned; + private boolean useServletContextParameters; private AtmosphereFramework framework; private Map properties = new HashMap(); protected List shutdownHooks = new ArrayList(); @@ -51,6 +52,8 @@ public class AtmosphereConfig { public AtmosphereConfig(AtmosphereFramework framework) { this.framework = framework; + String value=framework.getServletContext().getInitParameter(ApplicationConfig.USE_SERVLET_CONTEXT_PARAMETERS); + useServletContextParameters=value!=null && Boolean.valueOf(value); } public List getAtmosphereHandlerConfig() { @@ -111,7 +114,7 @@ public Map handlers() { public String getInitParameter(String name) { try { String value=framework.getServletConfig().getInitParameter(name); - if(value==null) { + if(value==null && useServletContextParameters) { value=framework.getServletContext().getInitParameter(name); } return value;