Merged branch 'jetty-9.4.x' into 'master'.
This commit is contained in:
commit
84b57c5f07
|
@ -33,10 +33,12 @@ public class RegexPathSpec extends PathSpec
|
||||||
public RegexPathSpec(String regex)
|
public RegexPathSpec(String regex)
|
||||||
{
|
{
|
||||||
super.pathSpec = regex;
|
super.pathSpec = regex;
|
||||||
boolean inGrouping = false;
|
if (regex.startsWith("regex|"))
|
||||||
|
super.pathSpec = regex.substring("regex|".length());
|
||||||
this.pathDepth = 0;
|
this.pathDepth = 0;
|
||||||
this.specLength = pathSpec.length();
|
this.specLength = pathSpec.length();
|
||||||
// build up a simple signature we can use to identify the grouping
|
// build up a simple signature we can use to identify the grouping
|
||||||
|
boolean inGrouping = false;
|
||||||
StringBuilder signature = new StringBuilder();
|
StringBuilder signature = new StringBuilder();
|
||||||
for (char c : pathSpec.toCharArray())
|
for (char c : pathSpec.toCharArray())
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,11 +40,12 @@ public class ServletPathSpec extends PathSpec
|
||||||
|
|
||||||
public ServletPathSpec(String servletPathSpec)
|
public ServletPathSpec(String servletPathSpec)
|
||||||
{
|
{
|
||||||
super();
|
if (servletPathSpec.startsWith("servlet|"))
|
||||||
|
servletPathSpec = servletPathSpec.substring("servlet|".length());
|
||||||
assertValidServletPathSpec(servletPathSpec);
|
assertValidServletPathSpec(servletPathSpec);
|
||||||
|
|
||||||
// The Root Path Spec
|
// The Root Path Spec
|
||||||
if ((servletPathSpec == null) || (servletPathSpec.length() == 0))
|
if (servletPathSpec.length() == 0)
|
||||||
{
|
{
|
||||||
super.pathSpec = "";
|
super.pathSpec = "";
|
||||||
super.pathDepth = -1; // force this to be at the end of the sort order
|
super.pathDepth = -1; // force this to be at the end of the sort order
|
||||||
|
|
|
@ -30,7 +30,6 @@ import javax.websocket.Session;
|
||||||
import javax.websocket.server.ServerEndpoint;
|
import javax.websocket.server.ServerEndpoint;
|
||||||
import javax.websocket.server.ServerEndpointConfig;
|
import javax.websocket.server.ServerEndpointConfig;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec;
|
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.websocket.common.WebSocketSession;
|
import org.eclipse.jetty.websocket.common.WebSocketSession;
|
||||||
|
@ -101,7 +100,7 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
||||||
private void addEndpoint(ServerEndpointMetadata metadata) throws DeploymentException
|
private void addEndpoint(ServerEndpointMetadata metadata) throws DeploymentException
|
||||||
{
|
{
|
||||||
JsrCreator creator = new JsrCreator(this,metadata,this.configuration.getFactory().getExtensionFactory());
|
JsrCreator creator = new JsrCreator(this,metadata,this.configuration.getFactory().getExtensionFactory());
|
||||||
this.configuration.addMapping(new UriTemplatePathSpec(metadata.getPath()),creator);
|
this.configuration.addMapping("uri-template|" + metadata.getPath(), creator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, try attribute on context
|
// Next, try attribute on context
|
||||||
Object enable = context.getAttribute(ENABLE_KEY);
|
Object enable = context.getAttribute(keyName);
|
||||||
|
|
||||||
if(enable != null)
|
if(enable != null)
|
||||||
{
|
{
|
||||||
|
@ -148,6 +148,8 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
|
||||||
String instanceKey = WebSocketUpgradeFilter.class.getName() + ".SCI";
|
String instanceKey = WebSocketUpgradeFilter.class.getName() + ".SCI";
|
||||||
if(context.getAttribute(instanceKey) == null)
|
if(context.getAttribute(instanceKey) == null)
|
||||||
{
|
{
|
||||||
|
if (LOG.isDebugEnabled())
|
||||||
|
LOG.debug("Dynamic filter add to support JSR356/javax.websocket.server: {}", WebSocketUpgradeFilter.class.getName());
|
||||||
WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(context);
|
WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(context);
|
||||||
context.setAttribute(instanceKey, wsuf);
|
context.setAttribute(instanceKey, wsuf);
|
||||||
}
|
}
|
||||||
|
@ -170,6 +172,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
|
||||||
{
|
{
|
||||||
if(!isEnabledViaContext(context, ENABLE_KEY, true))
|
if(!isEnabledViaContext(context, ENABLE_KEY, true))
|
||||||
{
|
{
|
||||||
|
LOG.info("JSR-356 is disabled by configuration");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
//
|
|
||||||
// ========================================================================
|
|
||||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
// All rights reserved. This program and the accompanying materials
|
|
||||||
// are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
// and Apache License v2.0 which accompanies this distribution.
|
|
||||||
//
|
|
||||||
// The Eclipse Public License is available at
|
|
||||||
// http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
//
|
|
||||||
// The Apache License v2.0 is available at
|
|
||||||
// http://www.opensource.org/licenses/apache2.0.php
|
|
||||||
//
|
|
||||||
// You may elect to redistribute this code under either of these licenses.
|
|
||||||
// ========================================================================
|
|
||||||
//
|
|
||||||
|
|
||||||
package org.eclipse.jetty.websocket.jsr356.server;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.http.pathmap.MappedResource;
|
|
||||||
import org.eclipse.jetty.http.pathmap.PathSpec;
|
|
||||||
import org.eclipse.jetty.websocket.server.MappedWebSocketCreator;
|
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
|
||||||
|
|
||||||
public class DummyCreator implements MappedWebSocketCreator
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void addMapping(org.eclipse.jetty.websocket.server.pathmap.PathSpec spec, WebSocketCreator creator)
|
|
||||||
{
|
|
||||||
/* do nothing */
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMapping(PathSpec spec, WebSocketCreator creator)
|
|
||||||
{
|
|
||||||
/* do nothing */
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MappedResource<WebSocketCreator> getMapping(String target)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -26,7 +26,7 @@
|
||||||
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"
|
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"
|
||||||
</Require-Capability>
|
</Require-Capability>
|
||||||
<Provide-Capability>
|
<Provide-Capability>
|
||||||
osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.websocket.servlet.WebSocketServletFactory,org.eclipse.jetty.webapp.Configuration
|
osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.webapp.Configuration
|
||||||
</Provide-Capability>
|
</Provide-Capability>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.websocket.server;
|
package org.eclipse.jetty.websocket.server;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.pathmap.MappedResource;
|
|
||||||
import org.eclipse.jetty.websocket.server.pathmap.PathSpec;
|
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +25,25 @@ import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
*/
|
*/
|
||||||
public interface MappedWebSocketCreator
|
public interface MappedWebSocketCreator
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Add a mapping, of a pathspec to a WebSocketCreator.
|
||||||
|
* <p>
|
||||||
|
* Recognized Path Spec syntaxes
|
||||||
|
* </p>
|
||||||
|
* <dl>
|
||||||
|
* <dt><code>/path/to</code> or <code>/</code> or <code>*.ext</code> or <code>servlet|{spec}</code></dt>
|
||||||
|
* <dd>Servlet Syntax</dd>
|
||||||
|
* <dt><code>^{spec}</code> or <code>regex|{spec}</code></dt>
|
||||||
|
* <dd>Regex Syntax</dd>
|
||||||
|
* <dt><code>uri-template|{spec}</code></dt>
|
||||||
|
* <dd>URI Template (see JSR356 and RFC6570 level 1)</dd>
|
||||||
|
* </dl>
|
||||||
|
*
|
||||||
|
* @param spec the path spec to use.
|
||||||
|
* @param creator the websocket creator for this specific mapping
|
||||||
|
*/
|
||||||
|
void addMapping(String spec, WebSocketCreator creator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a mapping.
|
* Add a mapping.
|
||||||
*
|
*
|
||||||
|
@ -36,7 +53,7 @@ public interface MappedWebSocketCreator
|
||||||
* (support classes moved to generic jetty-http project)
|
* (support classes moved to generic jetty-http project)
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
void addMapping(PathSpec spec, WebSocketCreator creator);
|
void addMapping(org.eclipse.jetty.websocket.server.pathmap.PathSpec spec, WebSocketCreator creator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a mapping.
|
* Add a mapping.
|
||||||
|
@ -48,11 +65,19 @@ public interface MappedWebSocketCreator
|
||||||
void addMapping(org.eclipse.jetty.http.pathmap.PathSpec spec, WebSocketCreator creator);
|
void addMapping(org.eclipse.jetty.http.pathmap.PathSpec spec, WebSocketCreator creator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get specific MappedResource for associated target.
|
/**
|
||||||
|
* Returns the creator for the given path spec.
|
||||||
*
|
*
|
||||||
* @param target the target to get mapping for
|
* @param spec @param spec the spec to test for (using the same spec syntax as seen in {@link #addMapping(String, WebSocketCreator)})
|
||||||
* @return the MappedResource for the target, or null if no match.
|
* @return the websocket creator if path spec exists, or null
|
||||||
* @since 9.2.20
|
|
||||||
*/
|
*/
|
||||||
MappedResource<WebSocketCreator> getMapping(String target);
|
WebSocketCreator getMapping(String spec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the mapping based on the given path spec.
|
||||||
|
*
|
||||||
|
* @param spec the path spec to remove (using the same spec syntax as seen in {@link #addMapping(String, WebSocketCreator)})
|
||||||
|
* @return true if underlying mapping were altered, false otherwise
|
||||||
|
*/
|
||||||
|
boolean removeMapping(String spec);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.websocket.server;
|
package org.eclipse.jetty.websocket.server;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ import org.eclipse.jetty.http.pathmap.PathMappings;
|
||||||
import org.eclipse.jetty.http.pathmap.PathSpec;
|
import org.eclipse.jetty.http.pathmap.PathSpec;
|
||||||
import org.eclipse.jetty.http.pathmap.RegexPathSpec;
|
import org.eclipse.jetty.http.pathmap.RegexPathSpec;
|
||||||
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
||||||
|
import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec;
|
||||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||||
import org.eclipse.jetty.util.component.Dumpable;
|
import org.eclipse.jetty.util.component.Dumpable;
|
||||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||||
|
@ -41,7 +43,7 @@ import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
* Only applicable if using {@link WebSocketUpgradeFilter}
|
* Only applicable if using {@link WebSocketUpgradeFilter}
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class NativeWebSocketConfiguration extends ContainerLifeCycle implements Dumpable
|
public class NativeWebSocketConfiguration extends ContainerLifeCycle implements MappedWebSocketCreator, Dumpable
|
||||||
{
|
{
|
||||||
private final WebSocketServerFactory factory;
|
private final WebSocketServerFactory factory;
|
||||||
private final PathMappings<WebSocketCreator> mappings = new PathMappings<>();
|
private final PathMappings<WebSocketCreator> mappings = new PathMappings<>();
|
||||||
|
@ -135,7 +137,7 @@ public class NativeWebSocketConfiguration extends ContainerLifeCycle implements
|
||||||
*
|
*
|
||||||
* @param spec the pathspec to respond on
|
* @param spec the pathspec to respond on
|
||||||
* @param creator the websocket creator to activate on the provided mapping
|
* @param creator the websocket creator to activate on the provided mapping
|
||||||
* @deprecated use {@link #addMapping(PathSpec, Class)} instead.
|
* @deprecated use {@link #addMapping(PathSpec, WebSocketCreator)} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void addMapping(org.eclipse.jetty.websocket.server.pathmap.PathSpec spec, WebSocketCreator creator)
|
public void addMapping(org.eclipse.jetty.websocket.server.pathmap.PathSpec spec, WebSocketCreator creator)
|
||||||
|
@ -164,10 +166,7 @@ public class NativeWebSocketConfiguration extends ContainerLifeCycle implements
|
||||||
*/
|
*/
|
||||||
public void addMapping(PathSpec pathSpec, final Class<?> endpointClass)
|
public void addMapping(PathSpec pathSpec, final Class<?> endpointClass)
|
||||||
{
|
{
|
||||||
mappings.put(pathSpec, new WebSocketCreator()
|
mappings.put(pathSpec, (req, resp) ->
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -177,10 +176,82 @@ public class NativeWebSocketConfiguration extends ContainerLifeCycle implements
|
||||||
{
|
{
|
||||||
throw new WebSocketException("Unable to create instance of " + endpointClass.getName(), e);
|
throw new WebSocketException("Unable to create instance of " + endpointClass.getName(), e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addMapping(String rawspec, WebSocketCreator creator)
|
||||||
|
{
|
||||||
|
PathSpec spec = toPathSpec(rawspec);
|
||||||
|
addMapping(spec, creator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PathSpec toPathSpec(String rawspec)
|
||||||
|
{
|
||||||
|
// Determine what kind of path spec we are working with
|
||||||
|
if (rawspec.charAt(0) == '/' || rawspec.startsWith("*.") || rawspec.startsWith("servlet|"))
|
||||||
|
{
|
||||||
|
return new ServletPathSpec(rawspec);
|
||||||
|
}
|
||||||
|
else if (rawspec.charAt(0) == '^' || rawspec.startsWith("regex|"))
|
||||||
|
{
|
||||||
|
return new RegexPathSpec(rawspec);
|
||||||
|
}
|
||||||
|
else if (rawspec.startsWith("uri-template|"))
|
||||||
|
{
|
||||||
|
return new UriTemplatePathSpec(rawspec.substring("uri-template|".length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add ability to load arbitrary jetty-http PathSpec implementation
|
||||||
|
// TODO: perhaps via "fully.qualified.class.name|spec" style syntax
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Unrecognized path spec syntax [" + rawspec + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WebSocketCreator getMapping(String rawspec)
|
||||||
|
{
|
||||||
|
PathSpec pathSpec = toPathSpec(rawspec);
|
||||||
|
for (MappedResource<WebSocketCreator> mapping : mappings)
|
||||||
|
{
|
||||||
|
if (mapping.getPathSpec().equals(pathSpec))
|
||||||
|
return mapping.getResource();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeMapping(String rawspec)
|
||||||
|
{
|
||||||
|
PathSpec pathSpec = toPathSpec(rawspec);
|
||||||
|
boolean removed = false;
|
||||||
|
for (Iterator<MappedResource<WebSocketCreator>> iterator = mappings.iterator(); iterator.hasNext(); )
|
||||||
|
{
|
||||||
|
MappedResource<WebSocketCreator> mapping = iterator.next();
|
||||||
|
if (mapping.getPathSpec().equals(pathSpec))
|
||||||
|
{
|
||||||
|
iterator.remove();
|
||||||
|
removed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manually add a WebSocket mapping.
|
||||||
|
*
|
||||||
|
* @param rawspec the pathspec to map to (see {@link MappedWebSocketCreator#addMapping(String, WebSocketCreator)} for syntax details)
|
||||||
|
* @param endpointClass the endpoint class to use for new upgrade requests on the provided
|
||||||
|
* pathspec (can be an {@link org.eclipse.jetty.websocket.api.annotations.WebSocket} annotated
|
||||||
|
* POJO, or implementing {@link org.eclipse.jetty.websocket.api.WebSocketListener})
|
||||||
|
*/
|
||||||
|
public void addMapping(String rawspec, final Class<?> endpointClass)
|
||||||
|
{
|
||||||
|
PathSpec pathSpec = toPathSpec(rawspec);
|
||||||
|
addMapping(pathSpec, endpointClass);
|
||||||
|
}
|
||||||
|
|
||||||
private class PersistedWebSocketCreator implements WebSocketCreator
|
private class PersistedWebSocketCreator implements WebSocketCreator
|
||||||
{
|
{
|
||||||
private final WebSocketCreator delegate;
|
private final WebSocketCreator delegate;
|
||||||
|
|
|
@ -145,6 +145,18 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
|
||||||
configuration.addMapping(spec, creator);
|
configuration.addMapping(spec, creator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addMapping(String spec, WebSocketCreator creator)
|
||||||
|
{
|
||||||
|
configuration.addMapping(spec, creator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeMapping(String spec)
|
||||||
|
{
|
||||||
|
return configuration.removeMapping(spec);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy()
|
public void destroy()
|
||||||
{
|
{
|
||||||
|
@ -279,9 +291,9 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MappedResource<WebSocketCreator> getMapping(String target)
|
public WebSocketCreator getMapping(String target)
|
||||||
{
|
{
|
||||||
return getConfiguration().getMatch(target);
|
return getConfiguration().getMapping(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -68,9 +68,21 @@ public class WebSocketUpgradeHandlerWrapper extends HandlerWrapper implements Ma
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MappedResource<WebSocketCreator> getMapping(String target)
|
public void addMapping(String spec, WebSocketCreator creator)
|
||||||
{
|
{
|
||||||
return this.configuration.getMatch(target);
|
configuration.addMapping(spec, creator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeMapping(String spec)
|
||||||
|
{
|
||||||
|
return configuration.removeMapping(spec);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WebSocketCreator getMapping(String target)
|
||||||
|
{
|
||||||
|
return configuration.getMapping(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
org.eclipse.jetty.websocket.server.WebSocketServerFactory
|
|
|
@ -21,7 +21,6 @@ package org.eclipse.jetty.websocket.server;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
|
@ -35,7 +34,7 @@ public class InfoContextAltAttributeListener implements WebSocketCreator, Servle
|
||||||
{
|
{
|
||||||
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(sce.getServletContext());
|
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(sce.getServletContext());
|
||||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
configuration.addMapping(new ServletPathSpec("/info/*"), this);
|
configuration.addMapping("/info/*", this);
|
||||||
sce.getServletContext().setAttribute(ATTR, configuration);
|
sce.getServletContext().setAttribute(ATTR, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.eclipse.jetty.websocket.server;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
|
@ -33,7 +32,7 @@ public class InfoContextAttributeListener implements WebSocketCreator, ServletCo
|
||||||
{
|
{
|
||||||
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) sce.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
|
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) sce.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
|
||||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
configuration.addMapping(new ServletPathSpec("/info/*"), this);
|
configuration.addMapping("/info/*", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.eclipse.jetty.websocket.server;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
|
@ -33,7 +32,7 @@ public class InfoContextListener implements WebSocketCreator, ServletContextList
|
||||||
{
|
{
|
||||||
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(sce.getServletContext());
|
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(sce.getServletContext());
|
||||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
configuration.addMapping(new ServletPathSpec("/info/*"), this);
|
configuration.addMapping("/info/*", this);
|
||||||
sce.getServletContext().setAttribute(NativeWebSocketConfiguration.class.getName(), configuration);
|
sce.getServletContext().setAttribute(NativeWebSocketConfiguration.class.getName(), configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
|
@ -42,6 +41,6 @@ public class InfoServlet extends HttpServlet implements WebSocketCreator
|
||||||
ServletContext context = config.getServletContext();
|
ServletContext context = config.getServletContext();
|
||||||
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getAttribute(NativeWebSocketConfiguration.class.getName());
|
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getAttribute(NativeWebSocketConfiguration.class.getName());
|
||||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
configuration.addMapping(new ServletPathSpec("/info/*"), this);
|
configuration.addMapping("/info/*", this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,13 +223,13 @@ public class WebSocketCloseTest
|
||||||
try (IBlockheadClient client = new BlockheadClient(server.getServerUri()))
|
try (IBlockheadClient client = new BlockheadClient(server.getServerUri()))
|
||||||
{
|
{
|
||||||
client.setProtocols("fastclose");
|
client.setProtocols("fastclose");
|
||||||
client.setTimeout(1,TimeUnit.SECONDS);
|
client.setTimeout(5,TimeUnit.SECONDS);
|
||||||
client.connect();
|
client.connect();
|
||||||
client.sendStandardRequest();
|
client.sendStandardRequest();
|
||||||
client.expectUpgradeResponse();
|
client.expectUpgradeResponse();
|
||||||
|
|
||||||
// Verify that client got close frame
|
// Verify that client got close frame
|
||||||
EventQueue<WebSocketFrame> frames = client.readFrames(1,1,TimeUnit.SECONDS);
|
EventQueue<WebSocketFrame> frames = client.readFrames(1,5,TimeUnit.SECONDS);
|
||||||
WebSocketFrame frame = frames.poll();
|
WebSocketFrame frame = frames.poll();
|
||||||
assertThat("frames[0].opcode",frame.getOpCode(),is(OpCode.CLOSE));
|
assertThat("frames[0].opcode",frame.getOpCode(),is(OpCode.CLOSE));
|
||||||
CloseInfo close = new CloseInfo(frame);
|
CloseInfo close = new CloseInfo(frame);
|
||||||
|
@ -239,7 +239,7 @@ public class WebSocketCloseTest
|
||||||
client.write(close.asFrame()); // respond with close
|
client.write(close.asFrame()); // respond with close
|
||||||
|
|
||||||
// ensure server socket got close event
|
// ensure server socket got close event
|
||||||
assertThat("Fast Close Latch",closeSocket.closeLatch.await(1,TimeUnit.SECONDS),is(true));
|
assertThat("Fast Close Latch",closeSocket.closeLatch.await(5,TimeUnit.SECONDS),is(true));
|
||||||
assertThat("Fast Close.statusCode",closeSocket.closeStatusCode,is(StatusCode.NORMAL));
|
assertThat("Fast Close.statusCode",closeSocket.closeStatusCode,is(StatusCode.NORMAL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,14 +256,14 @@ public class WebSocketCloseTest
|
||||||
try (IBlockheadClient client = new BlockheadClient(server.getServerUri()))
|
try (IBlockheadClient client = new BlockheadClient(server.getServerUri()))
|
||||||
{
|
{
|
||||||
client.setProtocols("fastfail");
|
client.setProtocols("fastfail");
|
||||||
client.setTimeout(1,TimeUnit.SECONDS);
|
client.setTimeout(5,TimeUnit.SECONDS);
|
||||||
try (StacklessLogging scope = new StacklessLogging(FastFailSocket.class, WebSocketSession.class))
|
try (StacklessLogging scope = new StacklessLogging(FastFailSocket.class, WebSocketSession.class))
|
||||||
{
|
{
|
||||||
client.connect();
|
client.connect();
|
||||||
client.sendStandardRequest();
|
client.sendStandardRequest();
|
||||||
client.expectUpgradeResponse();
|
client.expectUpgradeResponse();
|
||||||
|
|
||||||
EventQueue<WebSocketFrame> frames = client.readFrames(1,1,TimeUnit.SECONDS);
|
EventQueue<WebSocketFrame> frames = client.readFrames(1,5,TimeUnit.SECONDS);
|
||||||
WebSocketFrame frame = frames.poll();
|
WebSocketFrame frame = frames.poll();
|
||||||
assertThat("frames[0].opcode",frame.getOpCode(),is(OpCode.CLOSE));
|
assertThat("frames[0].opcode",frame.getOpCode(),is(OpCode.CLOSE));
|
||||||
CloseInfo close = new CloseInfo(frame);
|
CloseInfo close = new CloseInfo(frame);
|
||||||
|
@ -272,7 +272,7 @@ public class WebSocketCloseTest
|
||||||
client.write(close.asFrame()); // respond with close
|
client.write(close.asFrame()); // respond with close
|
||||||
|
|
||||||
// ensure server socket got close event
|
// ensure server socket got close event
|
||||||
assertThat("Fast Fail Latch",closeSocket.closeLatch.await(1,TimeUnit.SECONDS),is(true));
|
assertThat("Fast Fail Latch",closeSocket.closeLatch.await(5,TimeUnit.SECONDS),is(true));
|
||||||
assertThat("Fast Fail.statusCode",closeSocket.closeStatusCode,is(StatusCode.SERVER_ERROR));
|
assertThat("Fast Fail.statusCode",closeSocket.closeStatusCode,is(StatusCode.SERVER_ERROR));
|
||||||
assertThat("Fast Fail.errors",closeSocket.errors.size(),is(1));
|
assertThat("Fast Fail.errors",closeSocket.errors.size(),is(1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,6 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.websocket.server;
|
package org.eclipse.jetty.websocket.server;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -31,7 +27,6 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.ServerConnector;
|
import org.eclipse.jetty.server.ServerConnector;
|
||||||
import org.eclipse.jetty.servlet.FilterHolder;
|
import org.eclipse.jetty.servlet.FilterHolder;
|
||||||
|
@ -47,6 +42,10 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class WebSocketUpgradeFilterTest
|
public class WebSocketUpgradeFilterTest
|
||||||
{
|
{
|
||||||
|
@ -79,7 +78,7 @@ public class WebSocketUpgradeFilterTest
|
||||||
|
|
||||||
// direct configuration via WSUF
|
// direct configuration via WSUF
|
||||||
wsuf.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
wsuf.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
wsuf.addMapping(new ServletPathSpec("/info/*"), infoCreator);
|
wsuf.addMapping("/info/*", infoCreator);
|
||||||
|
|
||||||
server1.start();
|
server1.start();
|
||||||
return server1;
|
return server1;
|
||||||
|
@ -104,7 +103,7 @@ public class WebSocketUpgradeFilterTest
|
||||||
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
|
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
|
||||||
assertThat("NativeWebSocketConfiguration", configuration, notNullValue());
|
assertThat("NativeWebSocketConfiguration", configuration, notNullValue());
|
||||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
configuration.addMapping(new ServletPathSpec("/info/*"), infoCreator);
|
configuration.addMapping("/info/*", infoCreator);
|
||||||
|
|
||||||
server12.start();
|
server12.start();
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ public class WebSocketUpgradeFilterTest
|
||||||
|
|
||||||
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(context.getServletContext());
|
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(context.getServletContext());
|
||||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
configuration.addMapping(new ServletPathSpec("/info/*"), infoCreator);
|
configuration.addMapping("/info/*", infoCreator);
|
||||||
context.setAttribute(NativeWebSocketConfiguration.class.getName(), configuration);
|
context.setAttribute(NativeWebSocketConfiguration.class.getName(), configuration);
|
||||||
|
|
||||||
server13.start();
|
server13.start();
|
||||||
|
@ -153,7 +152,7 @@ public class WebSocketUpgradeFilterTest
|
||||||
|
|
||||||
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(context.getServletContext());
|
NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(context.getServletContext());
|
||||||
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
configuration.addMapping(new ServletPathSpec("/info/*"), infoCreator);
|
configuration.addMapping("/info/*", infoCreator);
|
||||||
context.addBean(configuration, true);
|
context.addBean(configuration, true);
|
||||||
|
|
||||||
FilterHolder wsufHolder = new FilterHolder(new WebSocketUpgradeFilter(configuration));
|
FilterHolder wsufHolder = new FilterHolder(new WebSocketUpgradeFilter(configuration));
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<web-app
|
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||||
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
|
||||||
version="3.1">
|
version="3.1">
|
||||||
|
|
||||||
|
<!-- disable JSR-356 -->
|
||||||
|
<context-param>
|
||||||
|
<param-name>org.eclipse.jetty.websocket.jsr356</param-name>
|
||||||
|
<param-value>false</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
<listener>
|
<listener>
|
||||||
<listener-class>org.eclipse.jetty.websocket.server.InfoContextAttributeListener</listener-class>
|
<listener-class>org.eclipse.jetty.websocket.server.InfoContextAttributeListener</listener-class>
|
||||||
</listener>
|
</listener>
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<web-app
|
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||||
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
|
||||||
version="3.1">
|
version="3.1">
|
||||||
|
|
||||||
|
<!-- disable JSR-356 -->
|
||||||
|
<context-param>
|
||||||
|
<param-name>org.eclipse.jetty.websocket.jsr356</param-name>
|
||||||
|
<param-value>false</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>info-servlet</servlet-name>
|
<servlet-name>info-servlet</servlet-name>
|
||||||
<servlet-class>org.eclipse.jetty.websocket.server.InfoServlet</servlet-class>
|
<servlet-class>org.eclipse.jetty.websocket.server.InfoServlet</servlet-class>
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
<Bundle-Description>Websocket Servlet Interface</Bundle-Description>
|
<Bundle-Description>Websocket Servlet Interface</Bundle-Description>
|
||||||
<Bundle-Classpath />
|
<Bundle-Classpath />
|
||||||
<DynamicImport-Package>org.eclipse.jetty.websocket.server.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}",org.eclipse.jetty.websocket.server.pathmap.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}"</DynamicImport-Package>
|
<DynamicImport-Package>org.eclipse.jetty.websocket.server.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}",org.eclipse.jetty.websocket.server.pathmap.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}"</DynamicImport-Package>
|
||||||
<Require-Capability>osgi.serviceloader; filter:="(osgi.serviceloader=org.eclipse.jetty.websocket.servlet.WebSocketServletFactory)";cardinality:=multiple, osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)"</Require-Capability>
|
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
Loading…
Reference in New Issue