cleanup the isEnabledViaContext check in JavaxWebSocket SCI

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2019-01-17 12:27:42 +11:00
parent f16789b101
commit bc951030ba
1 changed files with 15 additions and 25 deletions

View File

@ -54,46 +54,31 @@ public class JavaxWebSocketServletContainerInitializer implements ServletContain
* *
* @param context the context to search * @param context the context to search
* @param keyName the key name * @param keyName the key name
* @param defValue the default value, if the value is not specified in the context * @return the value for the feature key, otherwise null if key is not set in context
* @return the value for the feature key
*/ */
public static Boolean isEnabledViaContext(ServletContext context, String keyName, Boolean defValue) private static Boolean isEnabledViaContext(ServletContext context, String keyName)
{ {
// Try context parameters first // Try context parameters first
String cp = context.getInitParameter(keyName); String cp = context.getInitParameter(keyName);
if (cp != null) if (cp != null)
{ {
if (TypeUtil.isTrue(cp)) if (TypeUtil.isTrue(cp))
{
return true; return true;
} else
if (TypeUtil.isFalse(cp))
{
return false; return false;
}
return defValue;
} }
// Next, try attribute on context // Next, try attribute on context
Object enable = context.getAttribute(keyName); Object enable = context.getAttribute(keyName);
if (enable != null) if (enable != null)
{ {
if (TypeUtil.isTrue(enable)) if (TypeUtil.isTrue(enable))
{
return true; return true;
} else
if (TypeUtil.isFalse(enable))
{
return false; return false;
}
} }
return defValue; return null;
} }
public static JavaxWebSocketServerContainer configureContext(ServletContextHandler context) public static JavaxWebSocketServerContainer configureContext(ServletContextHandler context)
@ -110,13 +95,18 @@ public class JavaxWebSocketServletContainerInitializer implements ServletContain
@Override @Override
public void onStartup(Set<Class<?>> c, ServletContext context) throws ServletException public void onStartup(Set<Class<?>> c, ServletContext context) throws ServletException
{ {
Boolean dft = isEnabledViaContext(context, DEPRECATED_ENABLE_KEY, null); Boolean enableKey = isEnabledViaContext(context, ENABLE_KEY);
if (dft==null) Boolean deprecatedEnabledKey = isEnabledViaContext(context, DEPRECATED_ENABLE_KEY);
dft = Boolean.TRUE; if (deprecatedEnabledKey != null)
else
LOG.warn("Deprecated parameter used: " + DEPRECATED_ENABLE_KEY); LOG.warn("Deprecated parameter used: " + DEPRECATED_ENABLE_KEY);
if (!isEnabledViaContext(context, ENABLE_KEY, dft)) boolean websocketEnabled = true;
if (enableKey != null)
websocketEnabled = enableKey;
else if (deprecatedEnabledKey != null)
websocketEnabled = deprecatedEnabledKey;
if (!websocketEnabled)
{ {
LOG.info("Javax Websocket is disabled by configuration for context {}", context.getContextPath()); LOG.info("Javax Websocket is disabled by configuration for context {}", context.getContextPath());
return; return;