JSR-356 Adding suppport for @PathParam

This commit is contained in:
Joakim Erdfelt 2013-07-16 16:56:03 -07:00
parent ba50e6b053
commit e69b41e9cd
29 changed files with 260 additions and 90 deletions

View File

@ -68,7 +68,6 @@ public class JsrSession extends WebSocketSession implements javax.websocket.Sess
private final MessageHandlerWrapper wrappers[];
private Set<MessageHandler> messageHandlerSet;
private List<Extension> negotiatedExtensions;
private Map<String, List<String>> jsrParameterMap;
private Map<String, String> pathParameters = new HashMap<>();
private JsrAsyncRemote asyncRemote;
private JsrBasicRemote basicRemote;
@ -344,6 +343,15 @@ public class JsrSession extends WebSocketSession implements javax.websocket.Sess
getPolicy().setMaxTextMessageBufferSize(length);
}
public void setPathParameters(Map<String, String> pathParams)
{
this.pathParameters.clear();
if (pathParams != null)
{
this.pathParameters.putAll(pathParams);
}
}
private void updateMessageHandlerSet()
{
messageHandlerSet.clear();

View File

@ -18,11 +18,14 @@
package org.eclipse.jetty.websocket.jsr356.annotations;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Map;
import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
import org.eclipse.jetty.websocket.common.events.annotated.CallableMethod;
import org.eclipse.jetty.websocket.jsr356.JsrSession;
import org.eclipse.jetty.websocket.jsr356.annotations.Param.Role;
@ -38,11 +41,12 @@ public abstract class JsrCallable extends CallableMethod
super(pojo,method);
Class<?> ptypes[] = method.getParameterTypes();
Annotation pannos[][] = method.getParameterAnnotations();
int len = ptypes.length;
params = new Param[len];
for (int i = 0; i < len; i++)
{
params[i] = new Param(i,ptypes[i]);
params[i] = new Param(i,ptypes[i],pannos[i]);
}
args = new Object[len];
@ -102,7 +106,7 @@ public abstract class JsrCallable extends CallableMethod
public void init(JsrSession session)
{
// Default the session.
// Default for the session.
// Session is an optional parameter (always)
idxSession = findIndexForRole(Param.Role.SESSION);
if (idxSession >= 0)
@ -110,7 +114,7 @@ public abstract class JsrCallable extends CallableMethod
args[idxSession] = session;
}
// Default the path parameters
// Default for the path parameters
// PathParam's are optional parameters (always)
Map<String, String> pathParams = session.getPathParameters();
if ((pathParams != null) && (pathParams.size() > 0))
@ -120,8 +124,25 @@ public abstract class JsrCallable extends CallableMethod
if (param.role == Role.PATH_PARAM)
{
int idx = param.index;
String value = pathParams.get(param.getPathParamName());
args[idx] = value;
String rawvalue = pathParams.get(param.getPathParamName());
Decoder decoder = session.getDecoderFactory().getDecoderFor(param.type);
if (decoder instanceof Decoder.Text<?>)
{
Decoder.Text<?> textDecoder = (Decoder.Text<?>)decoder;
try
{
args[idx] = textDecoder.decode(rawvalue);
}
catch (DecodeException e)
{
session.notifyError(e);
}
}
else
{
throw new InvalidWebSocketException("PathParam decoders must use Decoder.Text");
}
}
}
}

View File

@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.Reader;
import java.lang.annotation.Annotation;
import java.nio.ByteBuffer;
import java.util.Map;
import javax.websocket.CloseReason;
import javax.websocket.DecodeException;
@ -85,6 +86,11 @@ public class JsrEvents<T extends Annotation, C extends EndpointConfig>
*/
private OnMessagePongCallable onPong;
/**
* The Request Parameters (from resolved javax.websocket.server.PathParam entries)
*/
private Map<String, String> requestParameters;
public JsrEvents(AnnotatedEndpointMetadata<T, C> metadata)
{
this.metadata = metadata;
@ -210,6 +216,8 @@ public class JsrEvents<T extends Annotation, C extends EndpointConfig>
public void init(JsrSession session)
{
session.setPathParameters(requestParameters);
if (onOpen != null)
{
onOpen.init(session);
@ -261,4 +269,9 @@ public class JsrEvents<T extends Annotation, C extends EndpointConfig>
}
return onText.isPartialMessageSupported();
}
public void setRequestParameters(Map<String, String> requestParameters)
{
this.requestParameters = requestParameters;
}
}

View File

@ -18,6 +18,10 @@
package org.eclipse.jetty.websocket.jsr356.annotations;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
public class Param
@ -55,16 +59,26 @@ public class Param
public int index;
public Class<?> type;
private transient Map<Class<? extends Annotation>, Annotation> annotations;
/*
* The bound role for this parameter.
*/
public Role role = null;
private String pathParamName = null;
public Param(int idx, Class<?> type)
public Param(int idx, Class<?> type, Annotation[] annos)
{
this.index = idx;
this.type = type;
if (annos != null)
{
this.annotations = new HashMap<>();
for (Annotation anno : annos)
{
this.annotations.put(anno.annotationType(),anno);
}
}
}
public void bind(Role role)
@ -72,6 +86,17 @@ public class Param
this.role = role;
}
@SuppressWarnings("unchecked")
public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
{
if (this.annotations == null)
{
return null;
}
return (A)this.annotations.get(annotationClass);
}
public String getPathParamName()
{
return this.pathParamName;

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.ByteBuffer;
import java.util.Map;
import javax.websocket.CloseReason;
import javax.websocket.DecodeException;
@ -46,9 +47,9 @@ import org.eclipse.jetty.websocket.jsr356.annotations.JsrEvents;
public class JsrAnnotatedEventDriver extends AbstractJsrEventDriver implements EventDriver
{
private static final Logger LOG = Log.getLogger(JsrAnnotatedEventDriver.class);
private final JsrEvents events;
private final JsrEvents<?, ?> events;
public JsrAnnotatedEventDriver(WebSocketPolicy policy, EndpointInstance endpointInstance, JsrEvents events)
public JsrAnnotatedEventDriver(WebSocketPolicy policy, EndpointInstance endpointInstance, JsrEvents<?, ?> events)
{
super(policy,endpointInstance);
this.events = events;
@ -324,6 +325,11 @@ public class JsrAnnotatedEventDriver extends AbstractJsrEventDriver implements E
}
}
public void setRequestParameters(Map<String, String> requestParameters)
{
events.setRequestParameters(requestParameters);
}
@Override
public String toString()
{

View File

@ -18,9 +18,9 @@
package org.eclipse.jetty.websocket.jsr356;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.server.WebSocketHandler;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
@ -35,7 +35,7 @@ public class EchoHandler extends WebSocketHandler implements WebSocketCreator
}
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
return socket;
}

View File

@ -50,7 +50,7 @@ public class JsrParamIdDecoderTest
JsrParamIdDecoder paramId = new JsrParamIdDecoder(metadata);
OnMessageCallable callable = getOnMessageCallableFrom(DateTextSocket.class,"onMessage");
Param param = new Param(0,Date.class);
Param param = new Param(0,Date.class,null);
Assert.assertThat("Match for Decoder",paramId.process(param,callable),is(true));
}

View File

@ -53,19 +53,29 @@ public class AnnotatedServerEndpointMetadata extends AnnotatedEndpointMetadata<S
@Override
public void customizeParamsOnClose(LinkedList<IJsrParamId> params)
{
params.addFirst(JsrParamPath.INSTANCE);
super.customizeParamsOnClose(params);
params.addFirst(JsrPathParamId.INSTANCE);
}
@Override
public void customizeParamsOnError(LinkedList<IJsrParamId> params)
{
params.addFirst(JsrParamPath.INSTANCE);
super.customizeParamsOnError(params);
params.addFirst(JsrPathParamId.INSTANCE);
}
@Override
public void customizeParamsOnOpen(LinkedList<IJsrParamId> params)
{
params.addFirst(JsrParamPath.INSTANCE);
super.customizeParamsOnOpen(params);
params.addFirst(JsrPathParamId.INSTANCE);
}
@Override
public void customizeParamsOnMessage(LinkedList<IJsrParamId> params)
{
super.customizeParamsOnMessage(params);
params.addFirst(JsrPathParamId.INSTANCE);
}
@Override

View File

@ -28,7 +28,7 @@ import javax.websocket.Encoder;
import javax.websocket.Extension;
import javax.websocket.server.ServerEndpointConfig;
public class EmptyServerEndpointConfig implements ServerEndpointConfig
public class BasicServerEndpointConfig implements ServerEndpointConfig
{
private final List<Class<? extends Decoder>> decoders;
private final List<Class<? extends Encoder>> encoders;
@ -39,11 +39,11 @@ public class EmptyServerEndpointConfig implements ServerEndpointConfig
private final String path;
private Map<String, Object> userProperties;
public EmptyServerEndpointConfig(Class<?> endpointClass, String path)
public BasicServerEndpointConfig(Class<?> endpointClass, String path)
{
this.endpointClass = endpointClass;
this.path = path;
this.decoders = new ArrayList<>();
this.encoders = new ArrayList<>();
this.subprotocols = new ArrayList<>();
@ -51,7 +51,27 @@ public class EmptyServerEndpointConfig implements ServerEndpointConfig
this.userProperties = new HashMap<>();
this.configurator = BasicServerEndpointConfigurator.INSTANCE;
}
public BasicServerEndpointConfig(ServerEndpointConfig copy)
{
this.endpointClass = copy.getEndpointClass();
this.path = copy.getPath();
this.decoders = new ArrayList<>(copy.getDecoders());
this.encoders = new ArrayList<>(copy.getEncoders());
this.subprotocols = new ArrayList<>(copy.getSubprotocols());
this.extensions = new ArrayList<>(copy.getExtensions());
this.userProperties = new HashMap<>(copy.getUserProperties());
if (copy.getConfigurator() != null)
{
this.configurator = copy.getConfigurator();
}
else
{
this.configurator = BasicServerEndpointConfigurator.INSTANCE;
}
}
@Override
public List<Class<? extends Encoder>> getEncoders()
{

View File

@ -25,9 +25,11 @@ import javax.websocket.server.ServerEndpointConfig;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance;
import org.eclipse.jetty.websocket.jsr356.server.pathmap.WebSocketPathSpec;
import org.eclipse.jetty.websocket.server.pathmap.PathSpec;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
public class JsrCreator implements WebSocketCreator
@ -41,11 +43,11 @@ public class JsrCreator implements WebSocketCreator
}
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
JsrHandshakeRequest hsreq = new JsrHandshakeRequest(req);
JsrHandshakeResponse hsresp = new JsrHandshakeResponse(resp);
ServerEndpointConfig config = metadata.getConfig();
ServerEndpointConfig.Configurator configurator = config.getConfigurator();
@ -81,6 +83,15 @@ public class JsrCreator implements WebSocketCreator
{
Class<?> endpointClass = config.getEndpointClass();
Object endpoint = config.getConfigurator().getEndpointInstance(endpointClass);
PathSpec pathSpec = hsreq.getRequestPathSpec();
if (pathSpec instanceof WebSocketPathSpec)
{
// We have a PathParam path spec
WebSocketPathSpec wspathSpec = (WebSocketPathSpec)pathSpec;
String requestPath = req.getRequestPath();
// Wrap the config with the path spec information
config = new PathParamServerEndpointConfig(config,wspathSpec,requestPath);
}
return new EndpointInstance(endpoint,config,metadata);
}
catch (InstantiationException e)

View File

@ -25,13 +25,14 @@ import java.util.Map;
import javax.websocket.server.HandshakeRequest;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.server.pathmap.PathSpec;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
public class JsrHandshakeRequest implements HandshakeRequest
{
private final UpgradeRequest request;
private final ServletUpgradeRequest request;
public JsrHandshakeRequest(UpgradeRequest req)
public JsrHandshakeRequest(ServletUpgradeRequest req)
{
this.request = req;
}
@ -60,6 +61,11 @@ public class JsrHandshakeRequest implements HandshakeRequest
return request.getQueryString();
}
public PathSpec getRequestPathSpec()
{
return (PathSpec)request.getServletAttribute(PathSpec.class.getName());
}
@Override
public URI getRequestURI()
{
@ -69,15 +75,12 @@ public class JsrHandshakeRequest implements HandshakeRequest
@Override
public Principal getUserPrincipal()
{
// TODO: need to return User Principal
return null;
return request.getUserPrincipal();
}
@Override
public boolean isUserInRole(String role)
{
// TODO: need to return isUserInRole result
return false;
return request.isUserInRole(role);
}
}

View File

@ -29,14 +29,14 @@ import org.eclipse.jetty.websocket.jsr356.annotations.Param.Role;
/**
* Param handling for static parameters annotated with &#064;{@link PathParam}
*/
public class JsrParamPath implements IJsrParamId
public class JsrPathParamId implements IJsrParamId
{
public static final IJsrParamId INSTANCE = new JsrParamPath();
public static final IJsrParamId INSTANCE = new JsrPathParamId();
@Override
public boolean process(Param param, JsrCallable callable) throws InvalidSignatureException
{
PathParam pathparam = param.type.getAnnotation(PathParam.class);
PathParam pathparam = param.getAnnotation(PathParam.class);
if(pathparam != null)
{
param.bind(Role.PATH_PARAM);

View File

@ -40,11 +40,20 @@ public class JsrServerEndpointImpl implements EventDriverImpl
{
throw new IllegalStateException(String.format("Websocket %s must be an %s",websocket.getClass().getName(),EndpointInstance.class.getName()));
}
EndpointInstance ei = (EndpointInstance)websocket;
AnnotatedServerEndpointMetadata metadata = (AnnotatedServerEndpointMetadata)ei.getMetadata();
JsrEvents<ServerEndpoint,ServerEndpointConfig> events = new JsrEvents<>(metadata);
return new JsrAnnotatedEventDriver(policy,ei,events);
JsrEvents<ServerEndpoint, ServerEndpointConfig> events = new JsrEvents<>(metadata);
JsrAnnotatedEventDriver driver = new JsrAnnotatedEventDriver(policy,ei,events);
ServerEndpointConfig config = (ServerEndpointConfig)ei.getConfig();
if (config instanceof PathParamServerEndpointConfig)
{
PathParamServerEndpointConfig ppconfig = (PathParamServerEndpointConfig)config;
driver.setRequestParameters(ppconfig.getPathParamMap());
}
return driver;
}
@Override
@ -60,7 +69,7 @@ public class JsrServerEndpointImpl implements EventDriverImpl
{
return false;
}
EndpointInstance ei = (EndpointInstance)websocket;
Object endpoint = ei.getEndpoint();

View File

@ -0,0 +1,51 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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 java.util.HashMap;
import java.util.Map;
import javax.websocket.server.ServerEndpointConfig;
import org.eclipse.jetty.websocket.jsr356.server.pathmap.WebSocketPathSpec;
/**
* Wrapper for a {@link ServerEndpointConfig} where there PathParm information from the incoming request.
*/
public class PathParamServerEndpointConfig extends BasicServerEndpointConfig implements ServerEndpointConfig
{
private final Map<String, String> pathParamMap;
public PathParamServerEndpointConfig(ServerEndpointConfig config, WebSocketPathSpec pathSpec, String requestPath)
{
super(config);
Map<String, String> pathMap = pathSpec.getPathParams(requestPath);
pathParamMap = new HashMap<String, String>();
if (pathMap != null)
{
pathParamMap.putAll(pathMap);
}
}
public Map<String, String> getPathParamMap()
{
return pathParamMap;
}
}

View File

@ -68,7 +68,7 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
}
else
{
cec = new EmptyServerEndpointConfig(endpoint.getClass(),path);
cec = new BasicServerEndpointConfig(endpoint.getClass(),path);
}
}
return new EndpointInstance(endpoint,cec,metadata);

View File

@ -170,10 +170,8 @@ public class PrimitiveEchoTest
EchoCase.add(TESTCASES,ShortObjectTextSocket.class).addMessage(-32001L).expect("-32001");
// PathParam based
/*
EchoCase.add(TESTCASES,IntParamTextSocket.class).requestPath("/echo/primitives/integer/params/5678")
.addMessage(1234).expect("1234|5678");
*/
}
@BeforeClass

View File

@ -113,7 +113,9 @@ public class ServerAnnotatedEndpointScanner_GoodSignaturesTest
Field fClose = findFieldRef(AnnotatedServerEndpointMetadata.class,"onClose");
Field fError = findFieldRef(AnnotatedServerEndpointMetadata.class,"onError");
Field fText = findFieldRef(AnnotatedServerEndpointMetadata.class,"onText");
Field fTextStream = findFieldRef(AnnotatedServerEndpointMetadata.class,"onTextStream");
Field fBinary = findFieldRef(AnnotatedServerEndpointMetadata.class,"onBinary");
Field fBinaryStream = findFieldRef(AnnotatedServerEndpointMetadata.class,"onBinaryStream");
Field fPong = findFieldRef(AnnotatedServerEndpointMetadata.class,"onPong");
// @formatter:off
@ -152,8 +154,8 @@ public class ServerAnnotatedEndpointScanner_GoodSignaturesTest
// -- Beans
Case.add(data, DateTextSocket.class, fText, Date.class);
// -- Reader Events
Case.add(data, ReaderParamSocket.class, fText, Reader.class, String.class);
Case.add(data, StringReturnReaderParamSocket.class, fText, Reader.class, String.class);
Case.add(data, ReaderParamSocket.class, fTextStream, Reader.class, String.class);
Case.add(data, StringReturnReaderParamSocket.class, fTextStream, Reader.class, String.class);
// -- Binary Events
Case.add(data, BasicBinaryMessageByteBufferSocket.class, fBinary, ByteBuffer.class);
// -- Pong Events

View File

@ -27,7 +27,6 @@ import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
import org.eclipse.jetty.websocket.common.ConnectionState;
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
public class WebSocketServerConnection extends AbstractWebSocketConnection

View File

@ -43,8 +43,6 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory;
@ -158,12 +156,8 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
{
try
{
// TODO: use ServletUpgradeRequest in Jetty 9.1
@SuppressWarnings("deprecation")
ServletWebSocketRequest sockreq = new ServletWebSocketRequest(request);
// TODO: use ServletUpgradeResponse in Jetty 9.1
@SuppressWarnings("deprecation")
ServletWebSocketResponse sockresp = new ServletWebSocketResponse(response);
ServletUpgradeRequest sockreq = new ServletUpgradeRequest(request);
ServletUpgradeResponse sockresp = new ServletUpgradeResponse(response);
UpgradeContext context = getActiveUpgradeContext();
if (context == null)
@ -171,6 +165,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
context = new UpgradeContext();
setActiveUpgradeContext(context);
}
context.setRequest(sockreq);
context.setResponse(sockresp);
@ -236,7 +231,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
* Default Creator logic
*/
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
if (registeredSocketClasses.size() < 1)
{

View File

@ -100,7 +100,7 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
WebSocketCreator creator = resource.getResource();
// Store PathSpec resource mapping as request attribute
httpreq.setAttribute(PathSpec.class.getName(),resource);
httpreq.setAttribute(PathSpec.class.getName(),resource.getPathSpec());
// We have an upgrade request
if (factory.acceptWebSocket(creator,httpreq,httpresp))

View File

@ -26,13 +26,10 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.examples.echo.BigEchoSocket;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.junit.AfterClass;
import org.junit.Assert;
@ -57,14 +54,7 @@ public class AnnotatedMaxMessageSizeTest
@Override
public void configure(WebSocketServletFactory factory)
{
factory.setCreator(new WebSocketCreator()
{
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
{
return new BigEchoSocket();
}
});
factory.register(BigEchoSocket.class);
}
};

View File

@ -28,6 +28,8 @@ import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.helper.EchoSocket;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
@ -45,7 +47,7 @@ public class RequestHeadersTest
private EchoSocket echoSocket = new EchoSocket();
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
this.lastRequest = req;
this.lastResponse = resp;

View File

@ -30,8 +30,6 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.log.StacklessLogging;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
@ -40,6 +38,8 @@ import org.eclipse.jetty.websocket.common.events.AbstractEventDriver;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;
import org.eclipse.jetty.websocket.server.helper.RFCSocket;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
@ -86,7 +86,7 @@ public class WebSocketCloseTest
}
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
if (req.hasSubProtocol("fastclose"))
{

View File

@ -23,11 +23,11 @@ import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.common.extensions.compress.FrameCompressionExtension;
import org.eclipse.jetty.websocket.common.extensions.compress.MessageCompressionExtension;
import org.eclipse.jetty.websocket.server.WebSocketHandler;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
@ -69,7 +69,7 @@ public class BrowserDebugTool implements WebSocketCreator
private Server server;
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
LOG.debug("Creating BrowserSocket");

View File

@ -20,9 +20,9 @@ package org.eclipse.jetty.websocket.server.examples;
import java.io.IOException;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.server.examples.echo.BigEchoSocket;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
@ -33,7 +33,7 @@ public class MyCustomCreationServlet extends WebSocketServlet
public static class MyCustomCreator implements WebSocketCreator
{
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
String query = req.getQueryString();

View File

@ -18,8 +18,8 @@
package org.eclipse.jetty.websocket.server.examples.echo;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
/**
@ -32,7 +32,7 @@ public class EchoCreator implements WebSocketCreator
private LogSocket logSocket = new LogSocket();
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
for (String protocol : req.getSubProtocols())
{

View File

@ -274,4 +274,18 @@ public class ServletUpgradeRequest extends UpgradeRequest
this.req.setAttribute(name,o);
}
public Object getServletAttribute(String name)
{
return req.getAttribute(name);
}
public boolean isUserInRole(String role)
{
return req.isUserInRole(role);
}
public String getRequestPath()
{
return req.getServletPath();
}
}

View File

@ -18,8 +18,6 @@
package org.eclipse.jetty.websocket.servlet;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.extensions.Extension;
/**
@ -35,11 +33,6 @@ public interface WebSocketCreator
{
/**
* Create a websocket from the incoming request.
* <p>
* Note: if you have Servlet specific information you need to access from the UpgradeRequest, cast the {@link UpgradeRequest} to
* {@link ServletUpgradeRequest} for this extra information.
* <p>
* Future versions of this interface will change to use the Servlet specific Upgrade Request and Response parameters.
*
* @param req
* the request details
@ -47,5 +40,5 @@ public interface WebSocketCreator
* the response details
* @return a websocket object to use, or null if no websocket should be created from this request.
*/
Object createWebSocket(UpgradeRequest req, UpgradeResponse resp);
Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp);
}

View File

@ -18,8 +18,8 @@
package examples;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
public class MyAdvancedEchoCreator implements WebSocketCreator
@ -35,7 +35,7 @@ public class MyAdvancedEchoCreator implements WebSocketCreator
}
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
for (String subprotocol : req.getSubProtocols())
{