add some methods to the ServletWebSocketRequest and rename one method

This commit is contained in:
Jesse McConnell 2012-12-10 12:16:06 -06:00
parent 4ff9c2cea1
commit a2a5a97bfe
2 changed files with 39 additions and 2 deletions

View File

@ -18,7 +18,10 @@
package org.eclipse.jetty.websocket.server;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
@ -114,8 +117,42 @@ public class ServletWebSocketRequest extends UpgradeRequest
return protocols;
}
public void setAttribute(String name, Object o)
public void setServletAttribute(String name, Object o)
{
this.req.setAttribute(name,o);
}
public Principal getPrincipal()
{
return req.getUserPrincipal();
}
public StringBuffer getRequestURL()
{
return req.getRequestURL();
}
public Map<String, Object> getServletAttributes()
{
Map<String, Object> attributes = new HashMap<String,Object>();
for (String name : Collections.list((Enumeration<String>)req.getAttributeNames()))
{
attributes.put(name, req.getAttribute(name));
}
return attributes;
}
public Map<String, List<String>> getServletParameters()
{
Map<String, List<String>> parameters = new HashMap<String, List<String>>();
for (String name : Collections.list((Enumeration<String>)req.getParameterNames()))
{
parameters.put(name, Collections.unmodifiableList(Arrays.asList(req.getParameterValues(name))));
}
return parameters;
}
}

View File

@ -446,7 +446,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
}
// Tell jetty about the new connection
request.setAttribute(HttpConnection.UPGRADE_CONNECTION_ATTRIBUTE,connection);
request.setServletAttribute(HttpConnection.UPGRADE_CONNECTION_ATTRIBUTE,connection);
// Process (version specific) handshake response
LOG.debug("Handshake Response: {}",handshaker);