Skip to content

Commit

Permalink
Merge pull request #1898 from bertung/master
Browse files Browse the repository at this point in the history
getInitParameter also from ServletContext
  • Loading branch information
jfarcand committed Mar 17, 2015
2 parents 95e310c + 41d97a4 commit ffc0c6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Expand Up @@ -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";
}

13 changes: 10 additions & 3 deletions modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereConfig.java
Expand Up @@ -44,13 +44,16 @@ public class AtmosphereConfig {
private boolean supportSession;
private boolean sessionTimeoutRemovalAllowed;
private boolean throwExceptionOnCloned;
private boolean useServletContextParameters;
private AtmosphereFramework framework;
private Map<String, Object> properties = new HashMap<String, Object>();
protected List<ShutdownHook> shutdownHooks = new ArrayList<ShutdownHook>();
protected List<StartupHook> startUpHook = new ArrayList<StartupHook>();

protected AtmosphereConfig(AtmosphereFramework framework) {
this.framework = framework;
String value=framework.getServletContext().getInitParameter(ApplicationConfig.USE_SERVLET_CONTEXT_PARAMETERS);
useServletContextParameters=value!=null && Boolean.valueOf(value);
}

public List<AtmosphereHandlerConfig> getAtmosphereHandlerConfig() {
Expand Down Expand Up @@ -106,11 +109,15 @@ public Map<String, AtmosphereFramework.AtmosphereHandlerWrapper> 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 && useServletContextParameters) {
value=framework.getServletContext().getInitParameter(name);
}
return value;
} catch (Throwable ex) {
// Don't fail if Tomcat crash on startup with an NPE
return null;
Expand All @@ -120,7 +127,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<String> getInitParameterNames() {
return framework().getServletConfig().getInitParameterNames();
Expand Down

0 comments on commit ffc0c6e

Please sign in to comment.