Issue #1216 improving init/destroy in WSUF

This commit is contained in:
Joakim Erdfelt 2017-01-04 10:42:51 -04:00
parent ecc3c57dd1
commit 9324971d20
1 changed files with 12 additions and 4 deletions

View File

@ -110,6 +110,8 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
}
private NativeWebSocketConfiguration configuration;
private ServletContext context;
private String instanceKey;
private boolean localConfiguration = false;
private boolean alreadySetToAttribute = false;
@ -147,8 +149,10 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
@Override
public void destroy()
{
LOG.info(".destroy()");
try
{
context.setAttribute(instanceKey, null);
alreadySetToAttribute = false;
if(localConfiguration)
{
@ -286,6 +290,8 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
@Override
public void init(FilterConfig config) throws ServletException
{
LOG.info(".init()");
try
{
String configurationKey = config.getInitParameter(CONFIG_ATTRIBUTE_KEY);
@ -343,15 +349,17 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
getFactory().getPolicy().setInputBufferSize(Integer.parseInt(max));
}
String key = config.getInitParameter(CONTEXT_ATTRIBUTE_KEY);
if (key == null)
instanceKey = config.getInitParameter(CONTEXT_ATTRIBUTE_KEY);
if (instanceKey == null)
{
// assume default
key = WebSocketUpgradeFilter.class.getName();
instanceKey = WebSocketUpgradeFilter.class.getName();
}
this.context = config.getServletContext();
// Set instance of this filter to context attribute
setToAttribute(config.getServletContext(), key);
setToAttribute(config.getServletContext(), instanceKey);
}
catch (ServletException e)
{