393733 - WebSocketClient interface should support multiple connections
+ Removing deprecated methods from Session + Fixing client side UpgradeConnection to handle extension via new ExtensionStack object + Making ExtensionStack.getNegotiatedExtensions() return List<ExtensionConfig> instead of List<String> + Fixing tests that relied on changes
This commit is contained in:
parent
c631d9b461
commit
4660f35210
|
@ -19,8 +19,6 @@
|
|||
package org.eclipse.jetty.websocket.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
public interface Session
|
||||
{
|
||||
|
@ -52,26 +50,6 @@ public interface Session
|
|||
*/
|
||||
long getMaximumMessageSize();
|
||||
|
||||
/**
|
||||
* Return the list of extensions currently in use for this conversation.
|
||||
* <p>
|
||||
* Convenience method for <code>.getUpgradeResponse().getExtensions()</code>
|
||||
*
|
||||
* @return the negotiated extensions
|
||||
*/
|
||||
@Deprecated
|
||||
List<String> getNegotiatedExtensions();
|
||||
|
||||
/**
|
||||
* Return the sub protocol agreed during the websocket handshake for this conversation.
|
||||
* <p>
|
||||
* Convenience method for <code>.getUpgradeResponse().getAcceptedSubProtocol()</code>
|
||||
*
|
||||
* @return the negotiated subprotocol
|
||||
*/
|
||||
@Deprecated
|
||||
String getNegotiatedSubprotocol();
|
||||
|
||||
/**
|
||||
* Returns the version of the websocket protocol currently being used. This is taken as the value of the Sec-WebSocket-Version header used in the opening
|
||||
* handshake. i.e. "13".
|
||||
|
@ -80,14 +58,6 @@ public interface Session
|
|||
*/
|
||||
String getProtocolVersion();
|
||||
|
||||
/**
|
||||
* Return the query string associated with the request this session was opened under.
|
||||
* <p>
|
||||
* Convenience method for <code>.getUpgradeRequest().getRequestURI().getQuery()</code>
|
||||
*/
|
||||
@Deprecated
|
||||
String getQueryString();
|
||||
|
||||
/**
|
||||
* Return a reference to the RemoteEndpoint object representing the other end of this conversation.
|
||||
*
|
||||
|
@ -95,18 +65,6 @@ public interface Session
|
|||
*/
|
||||
RemoteEndpoint getRemote();
|
||||
|
||||
/**
|
||||
* Return the URI that this session was opened under.
|
||||
* <p>
|
||||
* Note, this is different than the servlet-api getRequestURI, as this will return the query portion as well.
|
||||
* <p>
|
||||
* Convenience method for <code>.getUpgradeRequest().getRequestURI()</code>
|
||||
*
|
||||
* @return the request URI.
|
||||
*/
|
||||
@Deprecated
|
||||
URI getRequestURI();
|
||||
|
||||
/**
|
||||
* Get the UpgradeRequest used to create this session
|
||||
*
|
||||
|
|
|
@ -36,15 +36,14 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.api.extensions.Extension;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.client.internal.ConnectPromise;
|
||||
import org.eclipse.jetty.websocket.common.AcceptHash;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketSession;
|
||||
import org.eclipse.jetty.websocket.common.events.EventDriver;
|
||||
import org.eclipse.jetty.websocket.common.extensions.ExtensionStack;
|
||||
|
||||
/**
|
||||
* This is the initial connection handling that exists immediately after physical connection is established to destination server.
|
||||
|
@ -212,51 +211,27 @@ public class UpgradeConnection extends AbstractConnection
|
|||
// Initialize / Negotiate Extensions
|
||||
EventDriver websocket = connectPromise.getDriver();
|
||||
WebSocketPolicy policy = connectPromise.getClient().getPolicy();
|
||||
String acceptedSubProtocol = response.getAcceptedSubProtocol();
|
||||
|
||||
WebSocketSession session = new WebSocketSession(request.getRequestURI(),websocket,connection);
|
||||
session.setPolicy(policy);
|
||||
session.setNegotiatedSubprotocol(acceptedSubProtocol);
|
||||
session.setUpgradeResponse(response);
|
||||
|
||||
connection.setSession(session);
|
||||
List<Extension> extensions = connectPromise.getClient().initExtensions(response.getExtensions());
|
||||
|
||||
// Start with default routing.
|
||||
IncomingFrames incoming = session;
|
||||
// OutgoingFrames outgoing = connection;
|
||||
// Initialize / Negotiate Extensions
|
||||
ExtensionStack extensionStack = new ExtensionStack(connectPromise.getClient().getExtensionFactory());
|
||||
extensionStack.negotiate(response.getExtensions());
|
||||
|
||||
// Connect extensions
|
||||
if (extensions != null)
|
||||
{
|
||||
connection.getParser().configureFromExtensions(extensions);
|
||||
connection.getGenerator().configureFromExtensions(extensions);
|
||||
extensionStack.configure(connection.getParser());
|
||||
extensionStack.configure(connection.getGenerator());
|
||||
|
||||
// FIXME
|
||||
// Iterator<Extension> extIter;
|
||||
// // Connect outgoings
|
||||
// extIter = extensions.iterator();
|
||||
// while (extIter.hasNext())
|
||||
// {
|
||||
// Extension ext = extIter.next();
|
||||
// ext.setNextOutgoingFrames(outgoing);
|
||||
// outgoing = ext;
|
||||
// }
|
||||
//
|
||||
// // Connect incomings
|
||||
// Collections.reverse(extensions);
|
||||
// extIter = extensions.iterator();
|
||||
// while (extIter.hasNext())
|
||||
// {
|
||||
// Extension ext = extIter.next();
|
||||
// ext.setNextIncomingFrames(incoming);
|
||||
// incoming = ext;
|
||||
// }
|
||||
}
|
||||
// Setup Incoming Routing
|
||||
connection.setNextIncomingFrames(extensionStack);
|
||||
extensionStack.setNextIncoming(session);
|
||||
|
||||
// configure session for outgoing flows
|
||||
// session.setOutgoing(outgoing);
|
||||
// configure connection for incoming flows
|
||||
connection.getParser().setIncomingFramesHandler(incoming);
|
||||
// Setup Outgoing Routing
|
||||
session.setOutgoingHandler(extensionStack);
|
||||
extensionStack.setNextOutgoing(connection);
|
||||
|
||||
// Now swap out the connection
|
||||
endp.setConnection(connection);
|
||||
|
|
|
@ -401,13 +401,13 @@ public class BlockheadServer
|
|||
// Respond to used extensions
|
||||
resp.append("Sec-WebSocket-Extensions: ");
|
||||
boolean delim = false;
|
||||
for (String ext : extensionStack.getNegotiatedExtensions())
|
||||
for (ExtensionConfig ext : extensionStack.getNegotiatedExtensions())
|
||||
{
|
||||
if (delim)
|
||||
{
|
||||
resp.append(", ");
|
||||
}
|
||||
resp.append(ext);
|
||||
resp.append(ext.getParameterizedName());
|
||||
delim = true;
|
||||
}
|
||||
resp.append("\r\n");
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.io.IOException;
|
|||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -62,9 +61,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
|||
private ExtensionFactory extensionFactory;
|
||||
private boolean active = false;
|
||||
private long maximumMessageSize;
|
||||
private List<String> negotiatedExtensions = new ArrayList<>();
|
||||
private String protocolVersion;
|
||||
private String negotiatedSubprotocol;
|
||||
private long timeout;
|
||||
private Map<String, String[]> parameterMap = new HashMap<>();
|
||||
private WebSocketRemoteEndpoint remote;
|
||||
|
@ -184,18 +181,6 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
|||
return maximumMessageSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNegotiatedExtensions()
|
||||
{
|
||||
return negotiatedExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNegotiatedSubprotocol()
|
||||
{
|
||||
return negotiatedSubprotocol;
|
||||
}
|
||||
|
||||
@ManagedAttribute(readonly = true)
|
||||
public OutgoingFrames getOutgoingHandler()
|
||||
{
|
||||
|
@ -214,12 +199,6 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
|||
return protocolVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryString()
|
||||
{
|
||||
return getRequestURI().getQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteEndpoint getRemote()
|
||||
{
|
||||
|
@ -245,7 +224,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
|||
@Override
|
||||
public String getSubProtocol()
|
||||
{
|
||||
return getNegotiatedSubprotocol();
|
||||
return upgradeResponse.getAcceptedSubProtocol();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -359,17 +338,6 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
|||
this.maximumMessageSize = length;
|
||||
}
|
||||
|
||||
public void setNegotiatedExtensions(List<String> negotiatedExtensions)
|
||||
{
|
||||
this.negotiatedExtensions.clear();
|
||||
this.negotiatedExtensions.addAll(negotiatedExtensions);
|
||||
}
|
||||
|
||||
public void setNegotiatedSubprotocol(String negotiatedSubprotocol)
|
||||
{
|
||||
this.negotiatedSubprotocol = negotiatedSubprotocol;
|
||||
}
|
||||
|
||||
public void setOutgoingHandler(OutgoingFrames outgoing)
|
||||
{
|
||||
this.outgoingHandler = outgoing;
|
||||
|
|
|
@ -159,9 +159,9 @@ public class ExtensionStack extends ContainerLifeCycle implements IncomingFrames
|
|||
*
|
||||
* @return list of negotiated extensions
|
||||
*/
|
||||
public List<String> getNegotiatedExtensions()
|
||||
public List<ExtensionConfig> getNegotiatedExtensions()
|
||||
{
|
||||
List<String> ret = new ArrayList<>();
|
||||
List<ExtensionConfig> ret = new ArrayList<>();
|
||||
if (extensions == null)
|
||||
{
|
||||
return ret;
|
||||
|
@ -169,7 +169,7 @@ public class ExtensionStack extends ContainerLifeCycle implements IncomingFrames
|
|||
|
||||
for (Extension ext : extensions)
|
||||
{
|
||||
ret.add(ext.getConfig().getParameterizedName());
|
||||
ret.add(ext.getConfig());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,9 @@ public class DummyMuxAddServer implements MuxAddServer
|
|||
|
||||
EventDriver websocket = this.eventDriverFactory.wrap(echo);
|
||||
WebSocketSession session = new WebSocketSession(request.getRequestURI(),websocket,channel);
|
||||
session.setNegotiatedSubprotocol("echo");
|
||||
UpgradeResponse uresponse = new UpgradeResponse();
|
||||
uresponse.setAcceptedSubProtocol("echo");
|
||||
session.setUpgradeResponse(uresponse);
|
||||
channel.setSession(session);
|
||||
channel.setSubProtocol("echo");
|
||||
channel.onOpen();
|
||||
|
|
|
@ -415,8 +415,9 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
|
|||
// Setup Session
|
||||
WebSocketSession session = new WebSocketSession(request.getRequestURI(),driver,connection);
|
||||
session.setPolicy(getPolicy().clonePolicy());
|
||||
session.setNegotiatedSubprotocol(response.getAcceptedSubProtocol());
|
||||
session.setNegotiatedExtensions(extensionStack.getNegotiatedExtensions());
|
||||
session.setUpgradeRequest(request);
|
||||
response.setExtensions(extensionStack.getNegotiatedExtensions());
|
||||
session.setUpgradeResponse(response);
|
||||
connection.setSession(session);
|
||||
|
||||
// Setup Incoming Routing
|
||||
|
|
Loading…
Reference in New Issue