Making changes to client / server from api / common

This commit is contained in:
Joakim Erdfelt 2012-11-06 16:58:54 -07:00
parent 414f964afd
commit 9be64bab11
86 changed files with 783 additions and 897 deletions

View File

@ -18,21 +18,31 @@
package org.eclipse.jetty.websocket.api;
import java.net.HttpCookie;
import java.net.URI;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.net.websocket.HandshakeRequest;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
public class UpgradeRequest implements HandshakeRequest
{
private URI requestURI;
private List<String> subProtocols = new ArrayList<>();
private List<ExtensionConfig> extensions = new ArrayList<>();
private List<HttpCookie> cookies = new ArrayList<>();
private Map<String, List<String>> headers = new HashMap<>();
private Object session;
private Principal userPrincipal;
private String httpVersion;
private String method;
private String host;
protected UpgradeRequest()
{
@ -41,53 +51,121 @@ public class UpgradeRequest implements HandshakeRequest
public UpgradeRequest(String requestURI)
{
this.requestURI = URI.create(requestURI);
this(URI.create(requestURI));
}
public UpgradeRequest(URI requestURI)
{
this.requestURI = requestURI;
this();
setRequestURI(requestURI);
}
public void addExtensions(String... extConfigs)
public void addExtensions(ExtensionConfig... configs)
{
// TODO Auto-generated method stub
for (ExtensionConfig config : configs)
{
extensions.add(config);
}
}
public void addExtensions(String... configs)
{
for (String config : configs)
{
extensions.add(ExtensionConfig.parse(config));
}
}
public List<HttpCookie> getCookies()
{
return cookies;
}
public List<ExtensionConfig> getExtensions()
{
// TODO Auto-generated method stub
return null;
return extensions;
}
public String getHeader(String name)
{
// TODO Auto-generated method stub
return null;
List<String> values = headers.get(name);
// no value list
if (values == null)
{
return null;
}
int size = values.size();
// empty value list
if (size <= 0)
{
return null;
}
// simple return
if (size == 1)
{
return values.get(0);
}
// join it with commas
boolean needsDelim = false;
StringBuilder ret = new StringBuilder();
for (String value : values)
{
if (needsDelim)
{
ret.append(", ");
}
QuoteUtil.quoteIfNeeded(ret,value,QuoteUtil.ABNF_REQUIRED_QUOTING);
needsDelim = true;
}
return ret.toString();
}
public int getHeaderInt(String name)
{
List<String> values = headers.get(name);
// no value list
if (values == null)
{
return -1;
}
int size = values.size();
// empty value list
if (size <= 0)
{
return -1;
}
// simple return
if (size == 1)
{
return Integer.parseInt(values.get(0));
}
throw new NumberFormatException("Cannot convert multi-value header into int");
}
@Override
public Map<String, List<String>> getHeaders()
{
// TODO Auto-generated method stub
return null;
return headers;
}
public List<String> getHeaders(String name)
{
return headers.get(name);
}
public String getHost()
{
return getHeader("Host");
return host;
}
public String getHttpVersion()
{
// TODO Auto-generated method stub
return null;
return httpVersion;
}
public String getMethod()
{
// TODO Auto-generated method stub
return null;
return method;
}
public String getOrigin()
@ -128,13 +206,19 @@ public class UpgradeRequest implements HandshakeRequest
@Override
public Principal getUserPrincipal()
{
// TODO Auto-generated method stub
return null;
return userPrincipal;
}
public boolean hasSubProtocol(String test)
{
return subProtocols.contains(test);
for (String protocol : subProtocols)
{
if (protocol.equalsIgnoreCase(test))
{
return true;
}
}
return false;
}
public boolean isOrigin(String test)
@ -145,10 +229,31 @@ public class UpgradeRequest implements HandshakeRequest
@Override
public boolean isUserInRole(String role)
{
// TODO Auto-generated method stub
return false;
}
public void setCookies(List<HttpCookie> cookies)
{
this.cookies = cookies;
}
public void setHttpVersion(String httpVersion)
{
this.httpVersion = httpVersion;
}
public void setMethod(String method)
{
this.method = method;
}
public void setRequestURI(URI uri)
{
this.requestURI = uri;
this.host = this.requestURI.getHost();
// TODO: parse parameters
}
public void setSession(Object session)
{
this.session = session;
@ -156,11 +261,30 @@ public class UpgradeRequest implements HandshakeRequest
public void setSubProtocols(List<String> subProtocols)
{
this.subProtocols = subProtocols;
this.subProtocols.clear();
if (subProtocols != null)
{
this.subProtocols.addAll(subProtocols);
}
}
public void setSubProtocols(String protocols)
/**
* Set Sub Protocol request list.
*
* @param protocols
* the sub protocols desired
*/
public void setSubProtocols(String... protocols)
{
// TODO Auto-generated method stub
this.subProtocols.clear();
for (String protocol : protocols)
{
this.subProtocols.add(protocol);
}
}
public void setUserPrincipal(Principal userPrincipal)
{
this.userPrincipal = userPrincipal;
}
}

View File

@ -19,7 +19,8 @@
package org.eclipse.jetty.websocket.api;
import java.io.IOException;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -27,12 +28,26 @@ import java.util.Set;
import javax.net.websocket.HandshakeResponse;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
public class UpgradeResponse implements HandshakeResponse
{
public static final String SEC_WEBSOCKET_PROTOCOL = "Sec-WebSocket-Protocol";
private int statusCode;
private String statusReason;
private Map<String, List<String>> headers = new HashMap<>();
private List<ExtensionConfig> extensions = new ArrayList<>();
private boolean success = false;
public void addHeader(String name, String value)
{
// TODO Auto-generated method stub
List<String> values = headers.get(name);
if (values == null)
{
values = new ArrayList<>();
}
values.add(value);
headers.put(name,values);
}
/**
@ -42,8 +57,7 @@ public class UpgradeResponse implements HandshakeResponse
*/
public String getAcceptedSubProtocol()
{
// TODO Auto-generated method stub
return null;
return getHeader(SEC_WEBSOCKET_PROTOCOL);
}
/**
@ -53,51 +67,72 @@ public class UpgradeResponse implements HandshakeResponse
*/
public List<ExtensionConfig> getExtensions()
{
// TODO Auto-generated method stub
return null;
return extensions;
}
public Set<String> getHeaderNamesSet()
public String getHeader(String name)
{
// TODO Auto-generated method stub
return null;
List<String> values = headers.get(name);
// no value list
if (values == null)
{
return null;
}
int size = values.size();
// empty value list
if (size <= 0)
{
return null;
}
// simple return
if (size == 1)
{
return values.get(0);
}
// join it with commas
boolean needsDelim = false;
StringBuilder ret = new StringBuilder();
for (String value : values)
{
if (needsDelim)
{
ret.append(", ");
}
QuoteUtil.quoteIfNeeded(ret,value,QuoteUtil.ABNF_REQUIRED_QUOTING);
needsDelim = true;
}
return ret.toString();
}
public Set<String> getHeaderNames()
{
return headers.keySet();
}
@Override
public Map<String, List<String>> getHeaders()
{
// TODO Auto-generated method stub
return null;
return headers;
}
public String getHeaderValue(String name)
public List<String> getHeaders(String name)
{
// TODO Auto-generated method stub
return null;
}
public Iterator<String> getHeaderValues(String name)
{
// TODO Auto-generated method stub
return null;
return headers.get(name);
}
public int getStatusCode()
{
// TODO Auto-generated method stub
return -1;
return statusCode;
}
public String getStatusReason()
{
// TODO Auto-generated method stub
return null;
return statusReason;
}
public boolean isSuccess()
{
// TODO Auto-generated method stub
return false;
return success;
}
/**
@ -113,6 +148,7 @@ public class UpgradeResponse implements HandshakeResponse
*/
public void sendForbidden(String message) throws IOException
{
}
/**
@ -123,7 +159,7 @@ public class UpgradeResponse implements HandshakeResponse
*/
public void setAcceptedSubProtocol(String protocol)
{
// TODO Auto-generated method stub
setHeader(SEC_WEBSOCKET_PROTOCOL,protocol);
}
/**
@ -143,16 +179,32 @@ public class UpgradeResponse implements HandshakeResponse
*/
public void setExtensions(List<ExtensionConfig> extensions)
{
// TODO Auto-generated method stub
this.extensions.clear();
if (extensions != null)
{
this.extensions.addAll(extensions);
}
}
public void setHeader(String name, String value)
{
// TODO Auto-generated method stub
List<String> values = new ArrayList<>();
values.add(value);
headers.put(name,values);
}
public void validateWebSocketHash(String expectedHash) throws UpgradeException
public void setStatusCode(int statusCode)
{
// TODO Auto-generated method stub
this.statusCode = statusCode;
}
public void setStatusReason(String statusReason)
{
this.statusReason = statusReason;
}
public void setSuccess(boolean success)
{
this.success = success;
}
}

View File

@ -22,12 +22,12 @@ import java.io.IOException;
import java.net.URI;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.client.masks.Masker;
import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.io.event.EventDriver;
import org.eclipse.jetty.websocket.common.events.EventDriver;
public interface WebSocketClient
{

View File

@ -34,16 +34,16 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.util.thread.TimerScheduler;
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.ExtensionFactory;
import org.eclipse.jetty.websocket.client.internal.ConnectionManager;
import org.eclipse.jetty.websocket.client.internal.DefaultWebSocketClient;
import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.api.ExtensionRegistry;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.extensions.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.io.WebSocketSession;
import org.eclipse.jetty.websocket.core.io.event.EventDriver;
import org.eclipse.jetty.websocket.core.io.event.EventDriverFactory;
import org.eclipse.jetty.websocket.core.protocol.ExtensionConfig;
import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.eclipse.jetty.websocket.common.events.EventDriverFactory;
import org.eclipse.jetty.websocket.common.extensions.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.common.io.WebSocketSession;
public class WebSocketClientFactory extends ContainerLifeCycle
{
@ -151,7 +151,7 @@ public class WebSocketClientFactory extends ContainerLifeCycle
return executor;
}
public ExtensionRegistry getExtensionRegistry()
public ExtensionFactory getExtensionFactory()
{
return extensionRegistry;
}

View File

@ -18,27 +18,24 @@
package org.eclipse.jetty.websocket.client.internal;
import java.net.HttpCookie;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.protocol.ExtensionConfig;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
/**
* Allowing a generate from a UpgradeRequest
*/
public class ClientUpgradeRequest implements UpgradeRequest
public class ClientUpgradeRequest extends UpgradeRequest
{
private final static Logger LOG = Log.getLogger(ClientUpgradeRequest.class);
private static final String HEADER_VALUES_DELIM = "\"\\\n\r\t\f\b%+ ;=";
@ -62,37 +59,22 @@ public class ClientUpgradeRequest implements UpgradeRequest
}
private final String key;
private List<String> subProtocols;
private List<ExtensionConfig> extensions;
private Map<String, String> cookies;
private Map<String, String> headers;
private String httpEndPointName;
private String host;
public ClientUpgradeRequest()
{
byte[] bytes = new byte[16];
new Random().nextBytes(bytes);
this.key = new String(B64Code.encode(bytes));
this.subProtocols = new ArrayList<>();
this.extensions = new ArrayList<>();
this.cookies = new HashMap<>();
this.headers = new HashMap<>();
super();
this.key = genRandomKey();
}
@Override
public void addExtensions(String... extConfigs)
public ClientUpgradeRequest(URI requestURI)
{
for (String extConfig : extConfigs)
{
extensions.add(ExtensionConfig.parse(extConfig));
}
super(requestURI);
this.key = genRandomKey();
}
public String generate(URI uri)
public String generate()
{
this.httpEndPointName = uri.toASCIIString();
this.host = uri.getHost();
URI uri = getRequestURI();
StringBuilder request = new StringBuilder(512);
request.append("GET ");
@ -110,7 +92,7 @@ public class ClientUpgradeRequest implements UpgradeRequest
}
request.append(" HTTP/1.1\r\n");
request.append("Host: ").append(this.host);
request.append("Host: ").append(uri.getHost());
if (uri.getPort() > 0)
{
request.append(':').append(uri.getPort());
@ -165,36 +147,33 @@ public class ClientUpgradeRequest implements UpgradeRequest
}
// Cookies
if (!getCookieMap().isEmpty())
List<HttpCookie> cookies = getCookies();
if ((cookies != null) && (cookies.size() > 0))
{
request.append("Cookie: ");
boolean needDelim = false;
for (String cookie : getCookieMap().keySet())
for (HttpCookie cookie : cookies)
{
if (needDelim)
{
request.append("; ");
}
request.append(QuotedStringTokenizer.quoteIfNeeded(cookie,HEADER_VALUES_DELIM));
request.append("=");
String val = cookies.get(cookie);
request.append(QuotedStringTokenizer.quoteIfNeeded(val,HEADER_VALUES_DELIM));
request.append(cookie.toString());
needDelim = true;
}
request.append("\r\n");
}
// Other headers
for (String key : headers.keySet())
for (String key : getHeaders().keySet())
{
String value = headers.get(key);
if (FORBIDDEN_HEADERS.contains(key.toLowerCase()))
{
LOG.warn("Skipping forbidden header - {}: {}",key,value);
LOG.warn("Skipping forbidden header - {}",key);
continue; // skip
}
request.append(key).append(": ");
request.append(QuotedStringTokenizer.quoteIfNeeded(value,HEADER_VALUES_DELIM));
request.append(getHeader(key));
request.append("\r\n");
}
@ -203,118 +182,15 @@ public class ClientUpgradeRequest implements UpgradeRequest
return request.toString();
}
@Override
public Map<String, String> getCookieMap()
private final String genRandomKey()
{
return cookies;
}
@Override
public List<ExtensionConfig> getExtensions()
{
return extensions;
}
@Override
public String getHeader(String name)
{
return headers.get(name);
}
@Override
public Map<String, List<String>> getHeaders()
{
// TODO Auto-generated method stub
return null;
}
@Override
public String getHost()
{
return this.host;
}
@Override
public String getHttpVersion()
{
// TODO Auto-generated method stub
return null;
byte[] bytes = new byte[16];
new Random().nextBytes(bytes);
return new String(B64Code.encode(bytes));
}
public String getKey()
{
return key;
}
@Override
public String getMethod()
{
// TODO Auto-generated method stub
return null;
}
@Override
public String getOrigin()
{
return getHeader("Origin");
}
@Override
public Map<String, String[]> getParameterMap()
{
// TODO Auto-generated method stub
return null;
}
@Override
public String getQueryString()
{
// TODO Auto-generated method stub
return null;
}
@Override
public String getRemoteURI()
{
return httpEndPointName;
}
@Override
public List<String> getSubProtocols()
{
return subProtocols;
}
@Override
public boolean hasSubProtocol(String test)
{
for (String protocol : subProtocols)
{
if (protocol.equalsIgnoreCase(test))
{
return true;
}
}
return false;
}
@Override
public boolean isOrigin(String test)
{
return test.equalsIgnoreCase(getOrigin());
}
@Override
public void setSubProtocols(String protocols)
{
this.subProtocols.clear();
if (StringUtil.isBlank(protocols))
{
return;
}
for (String protocol : protocols.split("\\s*,\\s*"))
{
this.subProtocols.add(protocol);
}
}
}

View File

@ -19,88 +19,15 @@
package org.eclipse.jetty.websocket.client.internal;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.websocket.core.api.UpgradeException;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.protocol.ExtensionConfig;
import org.eclipse.jetty.websocket.api.UpgradeException;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
public class ClientUpgradeResponse implements UpgradeResponse
public class ClientUpgradeResponse extends UpgradeResponse
{
public static final String SEC_WEBSOCKET_PROTOCOL = "Sec-WebSocket-Protocol";
private int statusCode;
private String statusReason;
private MultiMap<String> headers;
private List<ExtensionConfig> extensions;
private boolean success = false;
public ClientUpgradeResponse()
{
headers = new MultiMap<>();
}
@Override
public void addHeader(String name, String value)
{
headers.add(name.toLowerCase(),value);
}
@Override
public String getAcceptedSubProtocol()
{
return headers.getValue(SEC_WEBSOCKET_PROTOCOL,0);
}
@Override
public List<ExtensionConfig> getExtensions()
{
return extensions;
}
@Override
public Set<String> getHeaderNamesSet()
{
return headers.keySet();
}
@Override
public String getHeaderValue(String name)
{
return headers.getValue(name.toLowerCase(),0);
}
@Override
public Iterator<String> getHeaderValues(String name)
{
List<String> values = headers.getValues(name.toLowerCase());
if (values == null)
{
return Collections.emptyIterator();
}
return values.iterator();
}
@Override
public int getStatusCode()
{
return statusCode;
}
@Override
public String getStatusReason()
{
return statusReason;
}
@Override
public boolean isSuccess()
{
return success;
super();
}
@Override
@ -109,51 +36,14 @@ public class ClientUpgradeResponse implements UpgradeResponse
throw new UnsupportedOperationException("Not supported on client implementation");
}
@Override
public void setAcceptedSubProtocol(String protocol)
{
headers.put(SEC_WEBSOCKET_PROTOCOL,protocol);
}
@Override
public void setExtensions(List<ExtensionConfig> extensions)
{
if (this.extensions == null)
{
this.extensions = new ArrayList<>();
}
else
{
this.extensions.clear();
}
this.extensions.addAll(extensions);
}
@Override
public void setHeader(String name, String value)
{
headers.putValues(name,value);
}
public void setStatusCode(int statusCode)
{
this.statusCode = statusCode;
}
public void setStatusReason(String statusReason)
{
this.statusReason = statusReason;
}
@Override
public void validateWebSocketHash(String expectedHash) throws UpgradeException
{
String respHash = getHeaderValue("Sec-WebSocket-Accept");
String respHash = getHeader("Sec-WebSocket-Accept");
success = true;
setSuccess(true);
if (expectedHash.equals(respHash) == false)
{
success = false;
setSuccess(false);
throw new UpgradeException("Invalid Sec-WebSocket-Accept hash");
}
}

View File

@ -36,10 +36,10 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.client.internal.io.WebSocketClientSelectorManager;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
/**
* Internal Connection/Client Manager used to track active clients, their physical vs virtual connection information, and provide some means to create new

View File

@ -25,15 +25,15 @@ import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.StringUtil;
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.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.client.WebSocketClientFactory;
import org.eclipse.jetty.websocket.client.masks.Masker;
import org.eclipse.jetty.websocket.client.masks.RandomMasker;
import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.io.event.EventDriver;
import org.eclipse.jetty.websocket.common.events.EventDriver;
/**
* WebSocketClient for working with Upgrade (request and response), and establishing connections to the websocket URI of your choice.

View File

@ -24,8 +24,8 @@ import java.util.regex.Pattern;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.Utf8LineParser;
import org.eclipse.jetty.websocket.api.UpgradeException;
import org.eclipse.jetty.websocket.client.internal.ClientUpgradeResponse;
import org.eclipse.jetty.websocket.core.api.UpgradeException;
/**
* Responsible for reading UTF8 Response Header lines and parsing them into a provided UpgradeResponse object.

View File

@ -22,8 +22,6 @@ import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;
@ -36,19 +34,18 @@ import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.StringUtil;
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.client.internal.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.internal.ClientUpgradeResponse;
import org.eclipse.jetty.websocket.client.internal.DefaultWebSocketClient;
import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.api.UpgradeException;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.io.IncomingFrames;
import org.eclipse.jetty.websocket.core.io.OutgoingFrames;
import org.eclipse.jetty.websocket.core.io.WebSocketSession;
import org.eclipse.jetty.websocket.core.io.event.EventDriver;
import org.eclipse.jetty.websocket.core.protocol.AcceptHash;
import org.eclipse.jetty.websocket.core.protocol.ExtensionConfig;
import org.eclipse.jetty.websocket.common.AcceptHash;
import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.eclipse.jetty.websocket.common.io.IncomingFrames;
import org.eclipse.jetty.websocket.common.io.OutgoingFrames;
import org.eclipse.jetty.websocket.common.io.WebSocketSession;
/**
* This is the initial connection handling that exists immediately after physical connection is established to destination server.
@ -72,7 +69,8 @@ public class UpgradeConnection extends AbstractConnection
public void run()
{
URI uri = client.getWebSocketUri();
String rawRequest = request.generate(uri);
request.setRequestURI(uri);
String rawRequest = request.generate();
ByteBuffer buf = BufferUtil.toBuffer(rawRequest,StringUtil.__UTF8_CHARSET);
getEndPoint().write("REQ",this,buf);
@ -233,25 +231,26 @@ public class UpgradeConnection extends AbstractConnection
connection.getParser().configureFromExtensions(extensions);
connection.getGenerator().configureFromExtensions(extensions);
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;
}
// 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;
// }
}
// configure session for outgoing flows
@ -264,7 +263,7 @@ public class UpgradeConnection extends AbstractConnection
connection.onOpen();
}
private void validateResponse(UpgradeResponse response)
private void validateResponse(ClientUpgradeResponse response)
{
// Check the Accept hash
String reqKey = request.getKey();
@ -273,14 +272,16 @@ public class UpgradeConnection extends AbstractConnection
// Parse extensions
List<ExtensionConfig> extensions = new ArrayList<>();
Iterator<String> extIter = response.getHeaderValues("Sec-WebSocket-Extensions");
while (extIter.hasNext())
List<String> extValues = response.getHeaders("Sec-WebSocket-Extensions");
if (extValues != null)
{
String extVal = extIter.next();
QuotedStringTokenizer tok = new QuotedStringTokenizer(extVal,",");
while (tok.hasMoreTokens())
for (String extVal : extValues)
{
extensions.add(ExtensionConfig.parse(tok.nextToken()));
QuotedStringTokenizer tok = new QuotedStringTokenizer(extVal,",");
while (tok.hasMoreTokens())
{
extensions.add(ExtensionConfig.parse(tok.nextToken()));
}
}
}
response.setExtensions(extensions);

View File

@ -18,18 +18,21 @@
package org.eclipse.jetty.websocket.client.internal.io;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import javax.net.websocket.SendResult;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.api.extensions.Extension;
import org.eclipse.jetty.websocket.client.WebSocketClientFactory;
import org.eclipse.jetty.websocket.client.internal.DefaultWebSocketClient;
import org.eclipse.jetty.websocket.client.masks.Masker;
import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.io.AbstractWebSocketConnection;
import org.eclipse.jetty.websocket.core.io.IncomingFrames;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
import org.eclipse.jetty.websocket.common.io.IncomingFrames;
/**
* Client side WebSocket physical connection.
@ -77,13 +80,13 @@ public class WebSocketClientConnection extends AbstractWebSocketConnection
connected = true;
}
super.onOpen();
};
}
@Override
public <C> void output(C context, Callback<C> callback, WebSocketFrame frame)
public Future<SendResult> outgoingFrame(WebSocketFrame frame) throws IOException
{
masker.setMask(frame);
super.output(context,callback,frame);
return super.outgoingFrame(frame);
}
@Override

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.concurrent.Executor;
import javax.net.ssl.SSLEngine;
import org.eclipse.jetty.io.ByteBufferPool;
@ -34,9 +35,9 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.client.WebSocketClientFactory;
import org.eclipse.jetty.websocket.client.internal.DefaultWebSocketClient;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
public class WebSocketClientSelectorManager extends SelectorManager
{

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.websocket.client.masks;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
public class FixedMasker implements Masker
{

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.websocket.client.masks;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
public interface Masker
{

View File

@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.client.masks;
import java.util.Random;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
public class RandomMasker implements Masker
{

View File

@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.client.masks;
import java.util.Arrays;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
public class ZeroMasker implements Masker
{

View File

@ -18,9 +18,9 @@
package org.eclipse.jetty.websocket.client.mux;
import org.eclipse.jetty.websocket.core.extensions.mux.add.MuxAddClient;
import org.eclipse.jetty.websocket.core.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.core.io.WebSocketSession;
import org.eclipse.jetty.websocket.common.extensions.mux.add.MuxAddClient;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.common.io.WebSocketSession;
public class MuxClientAddHandler implements MuxAddClient
{

View File

@ -18,8 +18,8 @@
package org.eclipse.jetty.websocket.client.mux;
import org.eclipse.jetty.websocket.core.extensions.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.core.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.common.extensions.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
public class MuxClientExtension extends AbstractMuxExtension
{

View File

@ -25,12 +25,12 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.core.io.AbstractWebSocketConnection;
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

View File

@ -27,10 +27,10 @@ import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.api.UpgradeException;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
import org.eclipse.jetty.websocket.core.api.UpgradeException;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

View File

@ -23,10 +23,9 @@ import java.util.concurrent.Exchanger;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
public class ClientWriteThread extends Thread
{
@ -71,7 +70,7 @@ public class ClientWriteThread extends Thread
{
while (m.get() < messageCount)
{
conn.write(null,new FutureCallback<Void>(),message);
conn.write(message);
if (exchanger != null)
{

View File

@ -32,9 +32,9 @@ import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Assert;
public class ServerReadThread extends Thread

View File

@ -26,7 +26,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
public class ServerWriteThread extends Thread
{

View File

@ -26,10 +26,10 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

View File

@ -26,10 +26,10 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

View File

@ -25,10 +25,10 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.websocket.client;
import static org.hamcrest.Matchers.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Exchanger;
@ -27,13 +29,10 @@ import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.junit.Assert;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
/**
* Testing Socket used on client side WebSocket testing.
*/

View File

@ -18,26 +18,24 @@
package org.eclipse.jetty.websocket.client;
import static org.hamcrest.Matchers.*;
import java.net.URI;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
@RunWith(AdvancedRunner.class)
public class WebSocketClientTest
{
@ -95,7 +93,7 @@ public class WebSocketClientTest
Assert.assertThat("Factory.sockets.size",factory.getConnectionManager().getClients().size(),is(1));
cliSock.getConnection().write(null,new FutureCallback<Void>(),"Hello World!");
cliSock.getConnection().write("Hello World!");
srvSock.echoMessage(1,TimeUnit.MILLISECONDS,500);
// wait for response from server
cliSock.waitForMessage(500,TimeUnit.MILLISECONDS);

View File

@ -33,35 +33,35 @@ import java.net.SocketException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.websocket.SendResult;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.api.WebSocketException;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.extensions.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.io.IncomingFrames;
import org.eclipse.jetty.websocket.core.io.OutgoingFrames;
import org.eclipse.jetty.websocket.core.protocol.AcceptHash;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.ExtensionConfig;
import org.eclipse.jetty.websocket.core.protocol.Generator;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.Parser;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.WebSocketException;
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.common.AcceptHash;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.extensions.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.common.io.IncomingFrames;
import org.eclipse.jetty.websocket.common.io.OutgoingFrames;
import org.junit.Assert;
/**
@ -191,13 +191,13 @@ public class BlockheadServer
}
@Override
public void incoming(WebSocketException e)
public void incomingError(WebSocketException e)
{
incomingFrames.incoming(e);
incomingFrames.incomingError(e);
}
@Override
public void incoming(WebSocketFrame frame)
public void incomingFrame(WebSocketFrame frame)
{
LOG.debug("incoming({})",frame);
int count = parseCount.incrementAndGet();
@ -206,11 +206,11 @@ public class BlockheadServer
LOG.info("Server parsed {} frames",count);
}
WebSocketFrame copy = new WebSocketFrame(frame);
incomingFrames.incoming(copy);
incomingFrames.incomingFrame(copy);
}
@Override
public <C> void output(C context, Callback<C> callback, WebSocketFrame frame) throws IOException
public Future<SendResult> outgoingFrame(WebSocketFrame frame) throws IOException
{
ByteBuffer buf = generator.generate(frame);
if (LOG.isDebugEnabled())
@ -224,6 +224,8 @@ public class BlockheadServer
{
disconnect();
}
return null; // FIXME: need future for server send?
}
public int read(ByteBuffer buf) throws IOException
@ -366,30 +368,31 @@ public class BlockheadServer
outgoing = this;
// Connect extensions
if (!extensions.isEmpty())
{
generator.configureFromExtensions(extensions);
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;
}
}
// FIXME
// if (!extensions.isEmpty())
// {
// generator.configureFromExtensions(extensions);
//
// 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;
// }
// }
// Configure Parser
parser.setIncomingFramesHandler(incoming);
@ -410,7 +413,7 @@ public class BlockheadServer
{
resp.append(", ");
}
resp.append(ext.getParameterizedName());
resp.append(ext.getConfig().getParameterizedName());
delim = true;
}
resp.append("\r\n");
@ -439,7 +442,7 @@ public class BlockheadServer
public void write(WebSocketFrame frame) throws IOException
{
LOG.debug("write(Frame->{}) to {}",frame,outgoing);
outgoing.output(null,null,frame);
outgoing.outgoingFrame(frame);
}
}

View File

@ -18,20 +18,19 @@
package org.eclipse.jetty.websocket.client.blockhead;
import static org.hamcrest.Matchers.*;
import java.util.LinkedList;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.WebSocketException;
import org.eclipse.jetty.websocket.core.io.IncomingFrames;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.io.IncomingFrames;
import org.junit.Assert;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
public class IncomingFramesCapture implements IncomingFrames
{
private static final Logger LOG = Log.getLogger(IncomingFramesCapture.class);
@ -121,14 +120,14 @@ public class IncomingFramesCapture implements IncomingFrames
}
@Override
public void incoming(WebSocketException e)
public void incomingError(WebSocketException e)
{
LOG.debug(e);
errors.add(e);
}
@Override
public void incoming(WebSocketFrame frame)
public void incomingFrame(WebSocketFrame frame)
{
WebSocketFrame copy = new WebSocketFrame(frame);
frames.add(copy);

View File

@ -20,17 +20,19 @@ package org.eclipse.jetty.websocket.client.examples;
import java.net.URI;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.util.FutureCallback;
import javax.net.websocket.SendResult;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.client.WebSocketClientFactory;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
/**
* Example of a simple Echo Client.
@ -69,13 +71,12 @@ public class SimpleEchoClient
this.conn = conn;
try
{
FutureCallback<Void> callback = new FutureCallback<>();
conn.write(null,callback,"Hello");
callback.get(2,TimeUnit.SECONDS); // wait for send to complete.
Future<SendResult> fut;
fut = conn.write("Hello");
fut.get(2,TimeUnit.SECONDS); // wait for send to complete.
callback = new FutureCallback<>();
conn.write(null,callback,"Thanks for the conversation.");
callback.get(2,TimeUnit.SECONDS); // wait for send to complete.
fut = conn.write("Thanks for the conversation.");
fut.get(2,TimeUnit.SECONDS); // wait for send to complete.
conn.close(StatusCode.NORMAL,"I'm done");
}

View File

@ -29,11 +29,11 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.client.WebSocketClientFactory;
import org.eclipse.jetty.websocket.core.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.common.OpCode;
/**
* This is not a general purpose websocket client. It's only for testing the websocket server and is hardwired to a specific draft version of the protocol.

View File

@ -27,7 +27,7 @@ import java.util.List;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
@ -79,7 +79,7 @@ public class HttpResponseHeaderParserTest
Assert.assertThat("Response.statusCode",response.getStatusCode(),is(200));
Assert.assertThat("Response.statusReason",response.getStatusReason(),is("OK"));
Assert.assertThat("Response.header[age]",response.getHeaderValue("age"),is("518097"));
Assert.assertThat("Response.header[age]",response.getHeader("age"),is("518097"));
}
@Test
@ -139,6 +139,6 @@ public class HttpResponseHeaderParserTest
Assert.assertThat("Response.statusCode",response.getStatusCode(),is(200));
Assert.assertThat("Response.statusReason",response.getStatusReason(),is("OK"));
Assert.assertThat("Response.header[age]",response.getHeaderValue("age"),is("518097"));
Assert.assertThat("Response.header[age]",response.getHeader("age"),is("518097"));
}
}

View File

@ -15,11 +15,21 @@
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-servlet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>

View File

@ -36,11 +36,12 @@ public class ServletWebSocketRequest extends UpgradeRequest
{
private List<ExtensionConfig> extensions;
private Map<String, String> cookieMap;
private HttpServletRequest req;
public ServletWebSocketRequest(HttpServletRequest request)
{
super(request.getRequestURI());
// TODO: copy values over
this.req = request;
cookieMap = new HashMap<String, String>();
for (Cookie cookie : request.getCookies())
@ -68,31 +69,12 @@ public class ServletWebSocketRequest extends UpgradeRequest
QuotedStringTokenizer tok = new QuotedStringTokenizer(e.nextElement(),",");
while (tok.hasMoreTokens())
{
addExtensions(tok.nextToken());
ExtensionConfig config = ExtensionConfig.parse(tok.nextToken());
addExtensions(config);
}
}
}
@Override
public void addExtensions(String... extConfigs)
{
for (String extConfig : extConfigs)
{
extensions.add(ExtensionConfig.parse(extConfig));
}
}
public Map<String, String> getCookieMap()
{
return cookieMap;
}
@Override
public List<ExtensionConfig> getExtensions()
{
return extensions;
}
protected String[] parseProtocols(String protocol)
{
if (protocol == null)
@ -112,6 +94,11 @@ public class ServletWebSocketRequest extends UpgradeRequest
return protocols;
}
public void setAttribute(String name, Object o)
{
this.req.setAttribute(name,o);
}
public void setValidExtensions(List<Extension> valid)
{
if (this.extensions != null)

View File

@ -19,44 +19,20 @@
package org.eclipse.jetty.websocket.server;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.websocket.api.UpgradeException;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
public class ServletWebSocketResponse extends UpgradeResponse
{
private String acceptedProtocol;
private List<ExtensionConfig> extensions = new ArrayList<>();
private boolean success = true;
private HttpServletResponse resp;
public ServletWebSocketResponse(HttpServletResponse resp)
{
super();
this.resp = resp;
}
@Override
public void addHeader(String name, String value)
{
super.addHeader(name,value);
}
@Override
public String getAcceptedSubProtocol()
{
return acceptedProtocol;
}
@Override
public List<ExtensionConfig> getExtensions()
{
return this.extensions;
// TODO: copy values from resp
}
@Override
@ -71,34 +47,26 @@ public class ServletWebSocketResponse extends UpgradeResponse
throw new UnsupportedOperationException("Server cannot get Status Reason");
}
@Override
public boolean isSuccess()
public boolean isCommitted()
{
return success;
return this.resp.isCommitted();
}
public void sendError(int statusCode, String message) throws IOException
{
setSuccess(false);
this.resp.sendError(statusCode,message);
}
@Override
public void sendForbidden(String message) throws IOException
{
success = false;
setSuccess(false);
resp.sendError(HttpServletResponse.SC_FORBIDDEN,message);
}
@Override
public void setAcceptedSubProtocol(String protocol)
public void setStatus(int status)
{
this.acceptedProtocol = protocol;
}
@Override
public void setExtensions(List<ExtensionConfig> extensions)
{
this.extensions = extensions;
}
@Override
public void validateWebSocketHash(String expectedHash) throws UpgradeException
{
throw new UnsupportedOperationException("Server cannot validate its own hash");
this.resp.setStatus(status);
}
}

View File

@ -18,9 +18,9 @@
package org.eclipse.jetty.websocket.server;
import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.io.InternalConnection;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.common.io.InternalConnection;
public class UpgradeContext
{

View File

@ -18,9 +18,8 @@
package org.eclipse.jetty.websocket.server;
import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
/**
* Abstract WebSocket creator interface.
@ -28,8 +27,8 @@ import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
* Should you desire filtering of the WebSocket object creation due to criteria such as origin or sub-protocol, then you will be required to implement a custom
* WebSocketCreator implementation.
* <p>
* This has been moved from the WebSocketServlet to a standalone class managed by the {@link WebSocketServerFactory} due to need of WebSocket {@link Extension}s
* that require the ability to create new websockets (such as the mux extension)
* This has been moved from the WebSocketServlet to a standalone class managed by the WebSocketServerFactory due to need of WebSocket {@link Extension}s that
* require the ability to create new websockets (such as the mux extension)
*/
public interface WebSocketCreator
{

View File

@ -26,8 +26,8 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.websocket.core.api.WebSocketBehavior;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
public abstract class WebSocketHandler extends HandlerWrapper
{

View File

@ -24,10 +24,10 @@ import java.util.concurrent.Executor;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.io.AbstractWebSocketConnection;
import org.eclipse.jetty.websocket.core.io.IncomingFrames;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.extensions.Extension;
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
import org.eclipse.jetty.websocket.common.io.IncomingFrames;
public class WebSocketServerConnection extends AbstractWebSocketConnection
{

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
@ -42,21 +41,21 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.util.thread.TimerScheduler;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.api.ExtensionRegistry;
import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.api.WebSocketException;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.extensions.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.io.IncomingFrames;
import org.eclipse.jetty.websocket.core.io.InternalConnection;
import org.eclipse.jetty.websocket.core.io.OutgoingFrames;
import org.eclipse.jetty.websocket.core.io.WebSocketSession;
import org.eclipse.jetty.websocket.core.io.event.EventDriver;
import org.eclipse.jetty.websocket.core.io.event.EventDriverFactory;
import org.eclipse.jetty.websocket.core.protocol.ExtensionConfig;
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.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.extensions.Extension;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory;
import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.eclipse.jetty.websocket.common.events.EventDriverFactory;
import org.eclipse.jetty.websocket.common.extensions.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.common.io.IncomingFrames;
import org.eclipse.jetty.websocket.common.io.InternalConnection;
import org.eclipse.jetty.websocket.common.io.OutgoingFrames;
import org.eclipse.jetty.websocket.common.io.WebSocketSession;
import org.eclipse.jetty.websocket.server.handshake.HandshakeRFC6455;
/**
@ -215,7 +214,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
return this.creator;
}
public ExtensionRegistry getExtensionRegistry()
public ExtensionFactory getExtensionRegistry()
{
return extensionRegistry;
}
@ -355,16 +354,16 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
{
throw new IllegalStateException("Not a 'WebSocket: Upgrade' request");
}
if (!"HTTP/1.1".equals(request.getProtocol()))
if (!"HTTP/1.1".equals(request.getHttpVersion()))
{
throw new IllegalStateException("Not a 'HTTP/1.1' request");
}
int version = request.getIntHeader("Sec-WebSocket-Version");
int version = request.getHeaderInt("Sec-WebSocket-Version");
if (version < 0)
{
// Old pre-RFC version specifications (header not present in RFC-6455)
version = request.getIntHeader("Sec-WebSocket-Draft");
version = request.getHeaderInt("Sec-WebSocket-Draft");
}
WebSocketHandshake handshaker = handshakes.get(version);
@ -409,25 +408,26 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
{
connection.configureFromExtensions(extensions);
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;
}
// 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;
// }
}
// configure session for outgoing flows

View File

@ -27,9 +27,9 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.WebSocketBehavior;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
/**
* Abstract Servlet used to bridge the Servlet API to the WebSocket API.

View File

@ -19,10 +19,11 @@
package org.eclipse.jetty.websocket.server.handshake;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.websocket.core.protocol.AcceptHash;
import org.eclipse.jetty.websocket.core.protocol.ExtensionConfig;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.AcceptHash;
import org.eclipse.jetty.websocket.server.ServletWebSocketRequest;
import org.eclipse.jetty.websocket.server.ServletWebSocketResponse;
import org.eclipse.jetty.websocket.server.WebSocketHandshake;

View File

@ -28,8 +28,8 @@ import org.eclipse.jetty.util.BlockingCallback;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.core.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
/**
* Take {@link ResponseInfo} objects and convert to bytes for response.

View File

@ -26,12 +26,12 @@ import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.core.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.core.extensions.mux.MuxException;
import org.eclipse.jetty.websocket.core.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.core.extensions.mux.add.MuxAddServer;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxException;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.common.extensions.mux.add.MuxAddServer;
/**
* Handler for incoming MuxAddChannel requests.
@ -88,7 +88,8 @@ public class MuxAddHandler implements MuxAddServer
HttpMethod method = HttpMethod.fromString(request.getMethod());
HttpVersion version = HttpVersion.fromString(request.getHttpVersion());
httpChannel.startRequest(method,request.getMethod(),request.getRemoteURI(),version);
String uri = request.getRequestURI().toASCIIString();
httpChannel.startRequest(method,request.getMethod(),uri,version);
for (String headerName : request.getHeaders().keySet())
{

View File

@ -18,8 +18,8 @@
package org.eclipse.jetty.websocket.server.mux;
import org.eclipse.jetty.websocket.core.extensions.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.core.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.common.extensions.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
public class MuxServerExtension extends AbstractMuxExtension
{

View File

@ -22,7 +22,7 @@ import static org.hamcrest.Matchers.*;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.examples.MyEchoServlet;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;

View File

@ -22,7 +22,7 @@ import static org.hamcrest.Matchers.*;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.helper.EchoServlet;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;

View File

@ -18,9 +18,11 @@
package org.eclipse.jetty.websocket.server;
import static org.hamcrest.Matchers.*;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.helper.EchoServlet;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;
@ -29,9 +31,6 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class FragmentExtensionTest
{
private static SimpleServletServer server;

View File

@ -18,9 +18,11 @@
package org.eclipse.jetty.websocket.server;
import static org.hamcrest.Matchers.*;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.helper.EchoServlet;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;
@ -29,9 +31,6 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class IdentityExtensionTest
{
private static SimpleServletServer server;

View File

@ -24,15 +24,14 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -67,7 +66,7 @@ public class LoadTest
{
try
{
conn.write("LOAD_TEXT",new FutureCallback<String>(),message);
conn.write(message);
long iter = count.incrementAndGet();
if ((iter % 100) == 0)
{

View File

@ -19,8 +19,8 @@
package org.eclipse.jetty.websocket.server;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.protocol.Generator;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.Generator;
/**
* Convenience Generator.

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.websocket.server;
import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
@ -36,13 +38,13 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.websocket.core.api.WebSocketBehavior;
import org.eclipse.jetty.websocket.core.api.WebSocketException;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.io.IncomingFrames;
import org.eclipse.jetty.websocket.core.protocol.Generator;
import org.eclipse.jetty.websocket.core.protocol.Parser;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.io.IncomingFrames;
import org.eclipse.jetty.websocket.server.examples.MyEchoSocket;
import org.junit.AfterClass;
import org.junit.Assert;
@ -50,8 +52,6 @@ import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class WebSocketLoadRFC6455Test
{
private class WebSocketClient implements Runnable
@ -66,19 +66,13 @@ public class WebSocketLoadRFC6455Test
private final Parser _parser;
private final IncomingFrames _handler = new IncomingFrames()
{
/*
* public void close(int code,String message) { }
*
* public void onFrame(byte flags, byte opcode, ByteBuffer buffer) { _response=buffer; }
*/
@Override
public void incoming(WebSocketException e)
public void incomingError(WebSocketException e)
{
}
@Override
public void incoming(WebSocketFrame frame)
public void incomingFrame(WebSocketFrame frame)
{
}
};
@ -140,7 +134,7 @@ public class WebSocketLoadRFC6455Test
// TODO: Send it
// TODO: Receive response
Assert.assertEquals(message, _response.toString());
Assert.assertEquals(message,_response.toString());
latch.countDown();
}
}

View File

@ -23,15 +23,13 @@ import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.websocket.core.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.server.examples.MyEchoSocket;
import org.junit.After;
import org.junit.Assert;
@ -40,12 +38,6 @@ import org.junit.Test;
public class WebSocketOverSSLTest
{
// Fire and Forget callback
public static Callback<Void> fnf()
{
return new FutureCallback<Void>();
}
private Server _server;
private int _port;
private QueuedThreadPool _threadPool;
@ -102,7 +94,7 @@ public class WebSocketOverSSLTest
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
_server = new Server();
ServerConnector connector = new ServerConnector(_server, sslContextFactory);
ServerConnector connector = new ServerConnector(_server,sslContextFactory);
_server.addConnector(connector);
_server.setHandler(new WebSocketHandler.Simple(websocket.getClass()));
_server.start();
@ -130,7 +122,7 @@ public class WebSocketOverSSLTest
String message = new String(chars);
for (int i = 0; i < count; ++i)
{
_connection.write(null,fnf(),message);
_connection.write(message);
}
Assert.assertTrue(clientLatch.await(20,TimeUnit.SECONDS));
@ -162,7 +154,7 @@ public class WebSocketOverSSLTest
try
{
Assert.assertEquals(message,message);
connection.write(null,fnf(),message);
connection.write(message);
serverLatch.countDown();
}
catch (IOException x)
@ -181,7 +173,7 @@ public class WebSocketOverSSLTest
clientLatch.countDown();
}
});
_connection.write(null,fnf(),message);
_connection.write(message);
Assert.assertTrue(serverLatch.await(5,TimeUnit.SECONDS));
Assert.assertTrue(clientLatch.await(5,TimeUnit.SECONDS));

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.websocket.server;
import static org.hamcrest.Matchers.*;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.util.Arrays;
@ -25,11 +27,11 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.Generator;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;
import org.eclipse.jetty.websocket.server.helper.RFCServlet;
@ -39,9 +41,6 @@ import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
/**
* Test various <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a> specified requirements placed on {@link WebSocketServlet}
* <p>

View File

@ -20,13 +20,12 @@ package org.eclipse.jetty.websocket.server.ab;
import java.io.IOException;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
/**
* Simple Echo WebSocket, using async writes of echo
@ -55,7 +54,7 @@ public class ABSocket
// echo the message back.
try
{
this.conn.write(null,new FutureCallback<Void>(),buf,offset,len);
this.conn.write(buf,offset,len);
}
catch (IOException e)
{
@ -87,7 +86,7 @@ public class ABSocket
// echo the message back.
try
{
this.conn.write(null,new FutureCallback<Void>(),message);
this.conn.write(message);
}
catch (IOException e)
{

View File

@ -23,8 +23,8 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.protocol.Generator;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.server.SimpleServletServer;
import org.junit.AfterClass;
import org.junit.BeforeClass;

View File

@ -31,11 +31,11 @@ import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.Generator;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.ByteBufferAssert;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;

View File

@ -22,9 +22,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.ab.Fuzzer.SendMode;
import org.junit.Test;

View File

@ -23,10 +23,10 @@ import java.util.Arrays;
import java.util.List;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Test;
public class TestABCase2 extends AbstractABCase

View File

@ -22,9 +22,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Test;
public class TestABCase3 extends AbstractABCase

View File

@ -22,9 +22,9 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Test;
public class TestABCase4 extends AbstractABCase

View File

@ -24,10 +24,10 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -28,10 +28,10 @@ import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.helper.Hex;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -25,11 +25,11 @@ import java.util.List;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.Parser;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.helper.Hex;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -24,10 +24,10 @@ import java.util.List;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.helper.Hex;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -27,11 +27,11 @@ import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.Parser;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.helper.Hex;
import org.junit.Rule;
import org.junit.Test;

View File

@ -27,10 +27,10 @@ import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

View File

@ -27,8 +27,8 @@ import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

View File

@ -26,10 +26,10 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.toolchain.test.annotation.Stress;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.core.api.StatusCode;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -34,9 +34,8 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
@ -44,28 +43,29 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
import javax.net.websocket.SendResult;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.api.WebSocketException;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.extensions.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.io.IncomingFrames;
import org.eclipse.jetty.websocket.core.io.OutgoingFrames;
import org.eclipse.jetty.websocket.core.protocol.CloseInfo;
import org.eclipse.jetty.websocket.core.protocol.ExtensionConfig;
import org.eclipse.jetty.websocket.core.protocol.Generator;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.Parser;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.WebSocketException;
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.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.extensions.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.common.io.IncomingFrames;
import org.eclipse.jetty.websocket.common.io.OutgoingFrames;
import org.eclipse.jetty.websocket.server.helper.FinishedFuture;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;
import org.junit.Assert;
@ -220,25 +220,26 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
generator.configureFromExtensions(extensions);
parser.configureFromExtensions(extensions);
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;
}
// 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;
// }
}
// configure parser
@ -302,13 +303,13 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
}
@Override
public void incoming(WebSocketException e)
public void incomingError(WebSocketException e)
{
incomingFrames.incoming(e);
incomingFrames.incomingError(e);
}
@Override
public void incoming(WebSocketFrame frame)
public void incomingFrame(WebSocketFrame frame)
{
LOG.debug("incoming({})",frame);
int count = parseCount.incrementAndGet();
@ -317,7 +318,7 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
LOG.info("Client parsed {} frames",count);
}
WebSocketFrame copy = new WebSocketFrame(frame);
incomingFrames.incoming(copy);
incomingFrames.incomingFrame(copy);
}
public boolean isConnected()
@ -355,7 +356,7 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
}
@Override
public <C> void output(C context, Callback<C> callback, WebSocketFrame frame) throws IOException
public Future<SendResult> outgoingFrame(WebSocketFrame frame) throws IOException
{
ByteBuffer buf = generator.generate(frame);
if (LOG.isDebugEnabled())
@ -369,6 +370,8 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
{
disconnect();
}
return FinishedFuture.INSTANCE;
}
public int read() throws IOException
@ -542,8 +545,8 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
{
LOG.debug("write(Frame->{}) to {}",frame,outgoing);
frame.setMask(clientmask);
// frame.setMask(new byte[] { 0x00, 0x00, 0x00, 0x00 });
outgoing.output(null,null,frame);
// DEBUG frame.setMask(new byte[] { 0x00, 0x00, 0x00, 0x00 });
outgoing.outgoingFrame(frame);
}
public void writeRaw(ByteBuffer buf) throws IOException

View File

@ -23,8 +23,8 @@ 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.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.server.WebSocketCreator;
import org.eclipse.jetty.websocket.server.WebSocketHandler;
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;

View File

@ -23,15 +23,14 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
@WebSocket
public class BrowserSocket
@ -129,7 +128,7 @@ public class BrowserSocket
try
{
connection.write(null,new FutureCallback<String>(),message);
connection.write(message);
}
catch (IOException e)
{

View File

@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.server.examples;
import java.io.IOException;
import org.eclipse.jetty.websocket.core.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
/**
* Example of a blocking echo websocket.

View File

@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.server.examples;
import java.io.IOException;
import org.eclipse.jetty.websocket.core.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
/**
* Example of a basic blocking echo socket.

View File

@ -20,10 +20,9 @@ package org.eclipse.jetty.websocket.server.examples.echo;
import java.io.IOException;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
/**
* Example Socket for echoing back Big data using the Annotation techniques along with stateless techniques.
@ -40,7 +39,7 @@ public class BigEchoSocket
}
try
{
conn.write(null,new FutureCallback<Void>(),buf,offset,length);
conn.write(buf,offset,length);
}
catch (IOException e)
{
@ -57,7 +56,7 @@ public class BigEchoSocket
}
try
{
conn.write(null,new FutureCallback<Void>(),message);
conn.write(message);
}
catch (IOException e)
{

View File

@ -21,9 +21,8 @@ package org.eclipse.jetty.websocket.server.examples.echo;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
@WebSocket
public class EchoBroadcastPingSocket extends EchoBroadcastSocket
@ -48,7 +47,7 @@ public class EchoBroadcastPingSocket extends EchoBroadcastSocket
System.err.println("Ping");
byte data[] = new byte[]
{ (byte)1, (byte)2, (byte)3 };
conn.ping(null,new FutureCallback<Void>(),data);
conn.ping(data);
}
}
catch (Exception e)

View File

@ -21,12 +21,11 @@ package org.eclipse.jetty.websocket.server.examples.echo;
import java.io.IOException;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
@WebSocket
public class EchoBroadcastSocket
@ -42,7 +41,7 @@ public class EchoBroadcastSocket
{
try
{
sock.conn.write(null,new FutureCallback<Void>(),buf,offset,len);
sock.conn.write(buf,offset,len);
}
catch (IOException e)
{
@ -72,7 +71,7 @@ public class EchoBroadcastSocket
{
try
{
sock.conn.write(null,new FutureCallback<Void>(),text);
sock.conn.write(text);
}
catch (IOException e)
{

View File

@ -18,8 +18,8 @@
package org.eclipse.jetty.websocket.server.examples.echo;
import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.server.WebSocketCreator;
/**

View File

@ -22,13 +22,10 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketFrame;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.core.protocol.Frame;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.extensions.Frame;
/**
* Echo back the incoming text or binary as 2 frames of (roughly) equal size.
@ -39,7 +36,7 @@ public class EchoFragmentSocket
@OnWebSocketFrame
public void onFrame(WebSocketConnection conn, Frame frame)
{
if (!OpCode.isDataFrame(frame.getOpCode()))
if (frame.getType().isData())
{
return;
}
@ -54,20 +51,21 @@ public class EchoFragmentSocket
buf1.limit(half);
buf2.position(half);
Callback<Void> nop = new FutureCallback<>();
try
{
switch (frame.getOpCode())
switch (frame.getType())
{
case OpCode.BINARY:
conn.write(null,nop,buf1);
conn.write(null,nop,buf2);
case BINARY:
conn.write(buf1);
conn.write(buf2);
break;
case OpCode.TEXT:
case TEXT:
// NOTE: This impl is not smart enough to split on a UTF8 boundary
conn.write(null,nop,BufferUtil.toUTF8String(buf1));
conn.write(null,nop,BufferUtil.toUTF8String(buf2));
conn.write(BufferUtil.toUTF8String(buf1));
conn.write(BufferUtil.toUTF8String(buf2));
break;
default:
throw new IOException("Unexpected frame type: " + frame.getType());
}
}
catch (IOException e)

View File

@ -18,9 +18,9 @@
package org.eclipse.jetty.websocket.server.examples.echo;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.core.api.WebSocketException;
import org.eclipse.jetty.websocket.core.api.WebSocketListener;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.WebSocketListener;
public class LogSocket implements WebSocketListener
{

View File

@ -24,7 +24,7 @@ import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.websocket.core.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
public class CaptureSocket extends WebSocketAdapter
{

View File

@ -20,13 +20,12 @@ package org.eclipse.jetty.websocket.server.helper;
import java.io.IOException;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
/**
* Simple Echo WebSocket, using async writes of echo
@ -46,7 +45,7 @@ public class EchoSocket
// echo the message back.
try
{
this.conn.write(null,new FutureCallback<Void>(),buf,offset,len);
this.conn.write(buf,offset,len);
}
catch (IOException e)
{
@ -68,7 +67,7 @@ public class EchoSocket
// echo the message back.
try
{
this.conn.write(null,new FutureCallback<Void>(),message);
this.conn.write(message);
}
catch (IOException e)
{

View File

@ -18,20 +18,19 @@
package org.eclipse.jetty.websocket.server.helper;
import static org.hamcrest.Matchers.*;
import java.util.LinkedList;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.api.WebSocketException;
import org.eclipse.jetty.websocket.core.io.IncomingFrames;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.io.IncomingFrames;
import org.junit.Assert;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
public class IncomingFramesCapture implements IncomingFrames
{
private static final Logger LOG = Log.getLogger(IncomingFramesCapture.class);
@ -121,14 +120,14 @@ public class IncomingFramesCapture implements IncomingFrames
}
@Override
public void incoming(WebSocketException e)
public void incomingError(WebSocketException e)
{
LOG.debug(e);
errors.add(e);
}
@Override
public void incoming(WebSocketFrame frame)
public void incomingFrame(WebSocketFrame frame)
{
WebSocketFrame copy = new WebSocketFrame(frame);
frames.add(copy);

View File

@ -18,18 +18,21 @@
package org.eclipse.jetty.websocket.server.helper;
import static org.hamcrest.Matchers.*;
import java.io.IOException;
import java.util.LinkedList;
import java.util.concurrent.Future;
import javax.net.websocket.SendResult;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.io.OutgoingFrames;
import org.eclipse.jetty.websocket.core.protocol.OpCode;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.io.OutgoingFrames;
import org.junit.Assert;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
public class OutgoingFramesCapture implements OutgoingFrames
{
public static class Write<C>
@ -39,11 +42,11 @@ public class OutgoingFramesCapture implements OutgoingFrames
public WebSocketFrame frame;
}
private LinkedList<Write<?>> writes = new LinkedList<>();
private LinkedList<WebSocketFrame> frames = new LinkedList<>();
public void assertFrameCount(int expectedCount)
{
Assert.assertThat("Captured frame count",writes.size(),is(expectedCount));
Assert.assertThat("Captured frame count",frames.size(),is(expectedCount));
}
public void assertHasFrame(byte op)
@ -58,26 +61,25 @@ public class OutgoingFramesCapture implements OutgoingFrames
public void assertHasNoFrames()
{
Assert.assertThat("Has no frames",writes.size(),is(0));
Assert.assertThat("Has no frames",frames.size(),is(0));
}
public void dump()
{
System.out.printf("Captured %d outgoing writes%n",writes.size());
for (int i = 0; i < writes.size(); i++)
System.out.printf("Captured %d outgoing writes%n",frames.size());
for (int i = 0; i < frames.size(); i++)
{
Write<?> write = writes.get(i);
System.out.printf("[%3d] %s | %s | %s%n",i,write.context,write.callback,write.frame);
System.out.printf(" %s%n",BufferUtil.toDetailString(write.frame.getPayload()));
WebSocketFrame frame = frames.get(i);
System.out.printf("[%3d] %s%n",i,frame);
System.out.printf(" %s%n",BufferUtil.toDetailString(frame.getPayload()));
}
}
public int getFrameCount(byte op)
{
int count = 0;
for (Write<?> write : writes)
for (WebSocketFrame frame : frames)
{
WebSocketFrame frame = write.frame;
if (frame.getOpCode() == op)
{
count++;
@ -86,18 +88,15 @@ public class OutgoingFramesCapture implements OutgoingFrames
return count;
}
public LinkedList<Write<?>> getWrites()
public LinkedList<WebSocketFrame> getFrames()
{
return writes;
return frames;
}
@Override
public <C> void output(C context, Callback<C> callback, WebSocketFrame frame)
public Future<SendResult> outgoingFrame(WebSocketFrame frame) throws IOException
{
Write<C> write = new Write<C>();
write.context = context;
write.callback = callback;
write.frame = frame;
writes.add(write);
frames.add(frame);
return FinishedFuture.INSTANCE;
}
}

View File

@ -20,13 +20,12 @@ package org.eclipse.jetty.websocket.server.helper;
import java.io.IOException;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.core.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
@WebSocket
public class RFCSocket
@ -43,7 +42,7 @@ public class RFCSocket
// echo the message back.
try
{
this.conn.write(null,new FutureCallback<Void>(),buf,offset,len);
this.conn.write(buf,offset,len);
}
catch (IOException e)
{
@ -71,7 +70,7 @@ public class RFCSocket
// echo the message back.
try
{
this.conn.write(null,new FutureCallback<Void>(),message);
this.conn.write(message);
}
catch (IOException e)
{