Bug 367099 - Upgrade jetty-websocket for RFC 6455

+ Renaming *D13 classes to *RFC6455 per dicussion in jetty-dev mailing
list
This commit is contained in:
Joakim Erdfelt 2011-12-19 10:03:01 -07:00
parent f7103d88f9
commit 6d907fa61d
15 changed files with 160 additions and 152 deletions

View File

@ -87,7 +87,7 @@ public class DeflateFrameExtension extends AbstractExtension
catch(DataFormatException e)
{
LOG.warn(e);
getConnection().close(WebSocketConnectionD13.CLOSE_BAD_PAYLOAD,e.toString());
getConnection().close(WebSocketConnectionRFC6455.CLOSE_BAD_PAYLOAD,e.toString());
}
}

View File

@ -420,9 +420,9 @@ public class WebSocketClient
if (channel!=null)
{
if (ex instanceof ProtocolException)
closeChannel(channel,WebSocketConnectionD13.CLOSE_PROTOCOL,ex.getMessage());
closeChannel(channel,WebSocketConnectionRFC6455.CLOSE_PROTOCOL,ex.getMessage());
else
closeChannel(channel,WebSocketConnectionD13.CLOSE_NO_CLOSE,ex.getMessage());
closeChannel(channel,WebSocketConnectionRFC6455.CLOSE_NO_CLOSE,ex.getMessage());
}
}
finally
@ -487,7 +487,7 @@ public class WebSocketClient
if (channel!=null)
{
closeChannel(channel,WebSocketConnectionD13.CLOSE_NO_CLOSE,"cancelled");
closeChannel(channel,WebSocketConnectionRFC6455.CLOSE_NO_CLOSE,"cancelled");
return true;
}
return false;
@ -547,7 +547,7 @@ public class WebSocketClient
}
if (channel!=null)
closeChannel(channel,WebSocketConnectionD13.CLOSE_NO_CLOSE,"timeout");
closeChannel(channel,WebSocketConnectionRFC6455.CLOSE_NO_CLOSE,"timeout");
if (exception!=null)
throw new ExecutionException(exception);
if (connection!=null)

View File

@ -379,7 +379,7 @@ public class WebSocketClientFactory extends AggregateLifeCycle
if (origin != null)
request.append("Origin: ").append(origin).append("\r\n");
request.append("Sec-WebSocket-Version: ").append(WebSocketConnectionD13.VERSION).append("\r\n");
request.append("Sec-WebSocket-Version: ").append(WebSocketConnectionRFC6455.VERSION).append("\r\n");
if (_future.getProtocol() != null)
request.append("Sec-WebSocket-Protocol: ").append(_future.getProtocol()).append("\r\n");
@ -436,7 +436,7 @@ public class WebSocketClientFactory extends AggregateLifeCycle
{
_error = "No Sec-WebSocket-Accept";
}
else if (!WebSocketConnectionD13.hashKey(_key).equals(_accept))
else if (!WebSocketConnectionRFC6455.hashKey(_key).equals(_accept))
{
_error = "Bad Sec-WebSocket-Accept";
}
@ -444,14 +444,14 @@ public class WebSocketClientFactory extends AggregateLifeCycle
{
Buffer header = _parser.getHeaderBuffer();
MaskGen maskGen = _future.getMaskGen();
WebSocketConnectionD13 connection =
new WebSocketConnectionD13(_future.getWebSocket(),
WebSocketConnectionRFC6455 connection =
new WebSocketConnectionRFC6455(_future.getWebSocket(),
_endp,
_buffers, System.currentTimeMillis(),
_future.getMaxIdleTime(),
_future.getProtocol(),
null,
WebSocketConnectionD13.VERSION,
WebSocketConnectionRFC6455.VERSION,
maskGen);
if (header.hasContent())

View File

@ -60,9 +60,9 @@ import org.eclipse.jetty.websocket.WebSocket.OnTextMessage;
* +---------------------------------------------------------------+
* </pre>
*/
public class WebSocketConnectionD13 extends AbstractConnection implements WebSocketConnection
public class WebSocketConnectionRFC6455 extends AbstractConnection implements WebSocketConnection
{
private static final Logger LOG = Log.getLogger(WebSocketConnectionD13.class);
private static final Logger LOG = Log.getLogger(WebSocketConnectionRFC6455.class);
final static byte OP_CONTINUATION = 0x00;
final static byte OP_TEXT = 0x01;
@ -89,6 +89,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
final static int FLAG_FIN=0x8;
// Per RFC 6455, section 1.3 - Opening Handshake - this version is "13"
final static int VERSION=13;
static boolean isLastFrame(byte flags)
@ -104,7 +105,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
private final static byte[] MAGIC;
private final List<Extension> _extensions;
private final WebSocketParserD13 _parser;
private final WebSocketGeneratorD13 _generator;
private final WebSocketGeneratorRFC6455 _generator;
private final WebSocketGenerator _outbound;
private final WebSocket _webSocket;
private final OnFrame _onFrame;
@ -137,14 +138,14 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
/* ------------------------------------------------------------ */
public WebSocketConnectionD13(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol, List<Extension> extensions,int draft)
public WebSocketConnectionRFC6455(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol, List<Extension> extensions,int draft)
throws IOException
{
this(websocket,endpoint,buffers,timestamp,maxIdleTime,protocol,extensions,draft,null);
}
/* ------------------------------------------------------------ */
public WebSocketConnectionD13(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol, List<Extension> extensions,int draft, MaskGen maskgen)
public WebSocketConnectionRFC6455(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol, List<Extension> extensions,int draft, MaskGen maskgen)
throws IOException
{
super(endpoint,timestamp);
@ -159,7 +160,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
_onTextMessage=_webSocket instanceof OnTextMessage ? (OnTextMessage)_webSocket : null;
_onBinaryMessage=_webSocket instanceof OnBinaryMessage ? (OnBinaryMessage)_webSocket : null;
_onControl=_webSocket instanceof OnControl ? (OnControl)_webSocket : null;
_generator = new WebSocketGeneratorD13(buffers, _endp,maskgen);
_generator = new WebSocketGeneratorRFC6455(buffers, _endp,maskgen);
_extensions=extensions;
WebSocketParser.FrameHandler frameHandler = new WSFrameHandler();
@ -272,7 +273,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
@Override
public void onIdleExpired(long idleForMs)
{
closeOut(WebSocketConnectionD13.CLOSE_NORMAL,"Idle for "+idleForMs+"ms > "+_endp.getMaxIdleTime()+"ms");
closeOut(WebSocketConnectionRFC6455.CLOSE_NORMAL,"Idle for "+idleForMs+"ms > "+_endp.getMaxIdleTime()+"ms");
}
/* ------------------------------------------------------------ */
@ -289,10 +290,10 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
{
closed=_closeCode==0;
if (closed)
_closeCode=WebSocketConnectionD13.CLOSE_NO_CLOSE;
_closeCode=WebSocketConnectionRFC6455.CLOSE_NO_CLOSE;
}
if (closed)
_webSocket.onClose(WebSocketConnectionD13.CLOSE_NO_CLOSE,"closed");
_webSocket.onClose(WebSocketConnectionRFC6455.CLOSE_NO_CLOSE,"closed");
}
/* ------------------------------------------------------------ */
@ -359,15 +360,15 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
// Close code 1005/1006 are never to be sent as a status over
// a Close control frame. Code<-1 also means no node.
if (code<0 || (code == WebSocketConnectionD13.CLOSE_NO_CODE) || code==WebSocketConnectionD13.CLOSE_NO_CLOSE)
if (code<0 || (code == WebSocketConnectionRFC6455.CLOSE_NO_CODE) || code==WebSocketConnectionRFC6455.CLOSE_NO_CLOSE)
code=-1;
else if (code==0)
code=WebSocketConnectionD13.CLOSE_NORMAL;
code=WebSocketConnectionRFC6455.CLOSE_NORMAL;
byte[] bytes = ("xx"+(message==null?"":message)).getBytes(StringUtil.__ISO_8859_1);
bytes[0]=(byte)(code/0x100);
bytes[1]=(byte)(code%0x100);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD13.OP_CLOSE,bytes,0,code>0?bytes.length:0);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionRFC6455.OP_CLOSE,bytes,0,code>0?bytes.length:0);
_outbound.flush();
}
}
@ -417,7 +418,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
if (_closedOut)
throw new IOException("closedOut "+_closeCode+":"+_closeMessage);
byte[] data = content.getBytes(StringUtil.__UTF8);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD13.OP_TEXT,data,0,data.length);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionRFC6455.OP_TEXT,data,0,data.length);
checkWriteable();
}
@ -426,7 +427,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
{
if (_closedOut)
throw new IOException("closedOut "+_closeCode+":"+_closeMessage);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD13.OP_BINARY,content,offset,length);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionRFC6455.OP_BINARY,content,offset,length);
checkWriteable();
}
@ -467,7 +468,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
if (_disconnecting)
return;
_disconnecting=true;
WebSocketConnectionD13.this.closeOut(code,message);
WebSocketConnectionRFC6455.this.closeOut(code,message);
}
/* ------------------------------------------------------------ */
@ -631,7 +632,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
{
boolean lastFrame = isLastFrame(flags);
synchronized(WebSocketConnectionD13.this)
synchronized(WebSocketConnectionRFC6455.this)
{
// Ignore incoming after a close
if (_closedIn)
@ -643,14 +644,14 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
if (isControlFrame(opcode) && buffer.length()>MAX_CONTROL_FRAME_PAYLOAD)
{
errorClose(WebSocketConnectionD13.CLOSE_PROTOCOL,"Control frame too large: " + buffer.length() + " > " + MAX_CONTROL_FRAME_PAYLOAD);
errorClose(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"Control frame too large: " + buffer.length() + " > " + MAX_CONTROL_FRAME_PAYLOAD);
return;
}
// TODO: check extensions for RSV bit(s) meanings
if ((flags&0x7)!=0)
{
errorClose(WebSocketConnectionD13.CLOSE_PROTOCOL,"RSV bits set 0x"+Integer.toHexString(flags));
errorClose(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"RSV bits set 0x"+Integer.toHexString(flags));
return;
}
@ -675,16 +676,16 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
switch(opcode)
{
case WebSocketConnectionD13.OP_CONTINUATION:
case WebSocketConnectionRFC6455.OP_CONTINUATION:
{
if (_opcode==-1)
{
errorClose(WebSocketConnectionD13.CLOSE_PROTOCOL,"Bad Continuation");
errorClose(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"Bad Continuation");
return;
}
// If text, append to the message buffer
if (_onTextMessage!=null && _opcode==WebSocketConnectionD13.OP_TEXT)
if (_onTextMessage!=null && _opcode==WebSocketConnectionRFC6455.OP_TEXT)
{
if (_utf8.append(buffer.array(),buffer.getIndex(),buffer.length(),_connection.getMaxTextMessageSize()))
{
@ -724,39 +725,39 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
}
break;
}
case WebSocketConnectionD13.OP_PING:
case WebSocketConnectionRFC6455.OP_PING:
{
LOG.debug("PING {}",this);
if (!_closedOut)
{
_connection.sendControl(WebSocketConnectionD13.OP_PONG,buffer.array(),buffer.getIndex(),buffer.length());
_connection.sendControl(WebSocketConnectionRFC6455.OP_PONG,buffer.array(),buffer.getIndex(),buffer.length());
}
break;
}
case WebSocketConnectionD13.OP_PONG:
case WebSocketConnectionRFC6455.OP_PONG:
{
LOG.debug("PONG {}",this);
break;
}
case WebSocketConnectionD13.OP_CLOSE:
case WebSocketConnectionRFC6455.OP_CLOSE:
{
int code=WebSocketConnectionD13.CLOSE_NO_CODE;
int code=WebSocketConnectionRFC6455.CLOSE_NO_CODE;
String message=null;
if (buffer.length()>=2)
{
code=(0xff&buffer.array()[buffer.getIndex()])*0x100+(0xff&buffer.array()[buffer.getIndex()+1]);
// Validate close status codes.
if (code < WebSocketConnectionD13.CLOSE_NORMAL ||
code == WebSocketConnectionD13.CLOSE_UNDEFINED ||
code == WebSocketConnectionD13.CLOSE_NO_CLOSE ||
code == WebSocketConnectionD13.CLOSE_NO_CODE ||
if (code < WebSocketConnectionRFC6455.CLOSE_NORMAL ||
code == WebSocketConnectionRFC6455.CLOSE_UNDEFINED ||
code == WebSocketConnectionRFC6455.CLOSE_NO_CLOSE ||
code == WebSocketConnectionRFC6455.CLOSE_NO_CODE ||
( code > 1010 && code <= 2999 ) ||
code >= 5000 )
{
errorClose(WebSocketConnectionD13.CLOSE_PROTOCOL,"Invalid close code " + code);
errorClose(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"Invalid close code " + code);
return;
}
@ -772,18 +773,18 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
else if(buffer.length() == 1)
{
// Invalid length. use status code 1002 (Protocol error)
errorClose(WebSocketConnectionD13.CLOSE_PROTOCOL,"Invalid payload length of 1");
errorClose(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"Invalid payload length of 1");
return;
}
closeIn(code,message);
break;
}
case WebSocketConnectionD13.OP_TEXT:
case WebSocketConnectionRFC6455.OP_TEXT:
{
if (_opcode!=-1)
{
errorClose(WebSocketConnectionD13.CLOSE_PROTOCOL,"Expected Continuation"+Integer.toHexString(opcode));
errorClose(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"Expected Continuation"+Integer.toHexString(opcode));
return;
}
@ -797,7 +798,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
else
{
LOG.warn("Frame discarded. Text aggregation disabled for {}",_endp);
errorClose(WebSocketConnectionD13.CLOSE_POLICY_VIOLATION,"Text frame aggregation disabled");
errorClose(WebSocketConnectionRFC6455.CLOSE_POLICY_VIOLATION,"Text frame aggregation disabled");
}
}
// append bytes to message buffer (if they fit)
@ -811,7 +812,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
}
else
{
_opcode=WebSocketConnectionD13.OP_TEXT;
_opcode=WebSocketConnectionRFC6455.OP_TEXT;
}
}
else
@ -820,11 +821,11 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
break;
}
case WebSocketConnectionD13.OP_BINARY:
case WebSocketConnectionRFC6455.OP_BINARY:
{
if (_opcode!=-1)
{
errorClose(WebSocketConnectionD13.CLOSE_PROTOCOL,"Expected Continuation"+Integer.toHexString(opcode));
errorClose(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"Expected Continuation"+Integer.toHexString(opcode));
return;
}
@ -845,14 +846,14 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
else
{
LOG.warn("Frame discarded. Binary aggregation disabed for {}",_endp);
errorClose(WebSocketConnectionD13.CLOSE_POLICY_VIOLATION,"Binary frame aggregation disabled");
errorClose(WebSocketConnectionRFC6455.CLOSE_POLICY_VIOLATION,"Binary frame aggregation disabled");
}
}
break;
}
default:
errorClose(WebSocketConnectionD13.CLOSE_PROTOCOL,"Bad opcode 0x"+Integer.toHexString(opcode));
errorClose(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"Bad opcode 0x"+Integer.toHexString(opcode));
break;
}
}
@ -860,13 +861,13 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
{
LOG.warn("{} for {}",notUtf8,_endp);
LOG.debug(notUtf8);
errorClose(WebSocketConnectionD13.CLOSE_BAD_PAYLOAD,"Invalid UTF-8");
errorClose(WebSocketConnectionRFC6455.CLOSE_BAD_PAYLOAD,"Invalid UTF-8");
}
catch(Throwable probablyNotUtf8)
{
LOG.warn("{} for {}",probablyNotUtf8,_endp);
LOG.debug(probablyNotUtf8);
errorClose(WebSocketConnectionD13.CLOSE_BAD_PAYLOAD,"Invalid Payload: "+probablyNotUtf8);
errorClose(WebSocketConnectionRFC6455.CLOSE_BAD_PAYLOAD,"Invalid Payload: "+probablyNotUtf8);
}
}
@ -892,7 +893,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
if (max>0 && (bufferLen+length)>max)
{
LOG.warn("Binary message too large > {}B for {}",_connection.getMaxBinaryMessageSize(),_endp);
_connection.close(WebSocketConnectionD13.CLOSE_MESSAGE_TOO_LARGE,"Message size > "+_connection.getMaxBinaryMessageSize());
_connection.close(WebSocketConnectionRFC6455.CLOSE_MESSAGE_TOO_LARGE,"Message size > "+_connection.getMaxBinaryMessageSize());
_opcode=-1;
if (_aggregate!=null)
_aggregate.clear();
@ -904,7 +905,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
private void textMessageTooLarge()
{
LOG.warn("Text message too large > {} chars for {}",_connection.getMaxTextMessageSize(),_endp);
_connection.close(WebSocketConnectionD13.CLOSE_MESSAGE_TOO_LARGE,"Text message size > "+_connection.getMaxTextMessageSize()+" chars");
_connection.close(WebSocketConnectionRFC6455.CLOSE_MESSAGE_TOO_LARGE,"Text message size > "+_connection.getMaxTextMessageSize()+" chars");
_opcode=-1;
_utf8.reset();
@ -920,7 +921,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
@Override
public String toString()
{
return WebSocketConnectionD13.this.toString()+"FH";
return WebSocketConnectionRFC6455.this.toString()+"FH";
}
}

View File

@ -20,6 +20,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -192,8 +193,10 @@ public class WebSocketFactory
throw new IllegalStateException("!HTTP/1.1");
int draft = request.getIntHeader("Sec-WebSocket-Version");
if (draft < 0)
if (draft < 0) {
// Old pre-RFC version specifications (header not present in RFC-6455)
draft = request.getIntHeader("Sec-WebSocket-Draft");
}
AbstractHttpConnection http = AbstractHttpConnection.getCurrentConnection();
if (http instanceof BlockingHttpConnection)
throw new IllegalStateException("Websockets not supported on blocking connectors");
@ -215,8 +218,8 @@ public class WebSocketFactory
final List<Extension> extensions;
switch (draft)
{
case -1:
case 0:
case -1: // unspecified draft/version
case 0: // Old school draft/version
extensions=Collections.emptyList();
connection = new WebSocketServletConnectionD00(websocket, endp, _buffers, http.getTimeStamp(), _maxIdleTime, protocol);
break;
@ -234,13 +237,15 @@ public class WebSocketFactory
extensions= initExtensions(extensions_requested,8-WebSocketConnectionD08.OP_EXT_DATA, 16-WebSocketConnectionD08.OP_EXT_CTRL,3);
connection = new WebSocketServletConnectionD08(websocket, endp, _buffers, http.getTimeStamp(), _maxIdleTime, protocol,extensions,draft);
break;
case 13:
extensions= initExtensions(extensions_requested,8-WebSocketConnectionD13.OP_EXT_DATA, 16-WebSocketConnectionD13.OP_EXT_CTRL,3);
connection = new WebSocketServletConnectionD13(websocket, endp, _buffers, http.getTimeStamp(), _maxIdleTime, protocol,extensions,draft);
case WebSocketConnectionRFC6455.VERSION: // RFC 6455 Version
extensions= initExtensions(extensions_requested,8-WebSocketConnectionRFC6455.OP_EXT_DATA, 16-WebSocketConnectionRFC6455.OP_EXT_CTRL,3);
connection = new WebSocketServletConnectionRFC6455(websocket, endp, _buffers, http.getTimeStamp(), _maxIdleTime, protocol,extensions,draft);
break;
default:
LOG.warn("Unsupported Websocket version: "+draft);
response.setHeader("Sec-WebSocket-Version","0,6,8,13");
// Per RFC 6455 - 4.4 - Supporting Multiple Versions of WebSocket Protocol
// Using the examples as outlined
response.setHeader("Sec-WebSocket-Version","13, 8, 6, 0");
throw new HttpException(400, "Unsupported draft specification: " + draft);
}

View File

@ -27,7 +27,7 @@ import org.eclipse.jetty.io.EofException;
* threads will call the addMessage methods while other
* threads are flushing the generator.
*/
public class WebSocketGeneratorD13 implements WebSocketGenerator
public class WebSocketGeneratorRFC6455 implements WebSocketGenerator
{
final private WebSocketBuffers _buffers;
final private EndPoint _endp;
@ -38,14 +38,14 @@ public class WebSocketGeneratorD13 implements WebSocketGenerator
private final MaskGen _maskGen;
private boolean _closed;
public WebSocketGeneratorD13(WebSocketBuffers buffers, EndPoint endp)
public WebSocketGeneratorRFC6455(WebSocketBuffers buffers, EndPoint endp)
{
_buffers=buffers;
_endp=endp;
_maskGen=null;
}
public WebSocketGeneratorD13(WebSocketBuffers buffers, EndPoint endp, MaskGen maskGen)
public WebSocketGeneratorRFC6455(WebSocketBuffers buffers, EndPoint endp, MaskGen maskGen)
{
_buffers=buffers;
_endp=endp;
@ -63,7 +63,7 @@ public class WebSocketGeneratorD13 implements WebSocketGenerator
if (_closed)
throw new EofException("Closed");
if (opcode==WebSocketConnectionD13.OP_CLOSE)
if (opcode==WebSocketConnectionRFC6455.OP_CLOSE)
_closed=true;
boolean mask=_maskGen!=null;
@ -71,13 +71,13 @@ public class WebSocketGeneratorD13 implements WebSocketGenerator
if (_buffer==null)
_buffer=mask?_buffers.getBuffer():_buffers.getDirectBuffer();
boolean last=WebSocketConnectionD13.isLastFrame(flags);
boolean last=WebSocketConnectionRFC6455.isLastFrame(flags);
int space=mask?14:10;
do
{
opcode = _opsent?WebSocketConnectionD13.OP_CONTINUATION:opcode;
opcode = _opsent?WebSocketConnectionRFC6455.OP_CONTINUATION:opcode;
opcode=(byte)(((0xf&flags)<<4)+(0xf&opcode));
_opsent=true;

View File

@ -161,9 +161,9 @@ public class WebSocketParserD13 implements WebSocketParser
// System.err.printf("%s %s %s >>\n",TypeUtil.toHexString(_flags),TypeUtil.toHexString(_opcode),data.length());
_bytesNeeded-=data.length();
progress=true;
_handler.onFrame((byte)(_flags&(0xff^WebSocketConnectionD13.FLAG_FIN)), _opcode, data);
_handler.onFrame((byte)(_flags&(0xff^WebSocketConnectionRFC6455.FLAG_FIN)), _opcode, data);
_opcode=WebSocketConnectionD13.OP_CONTINUATION;
_opcode=WebSocketConnectionRFC6455.OP_CONTINUATION;
}
if (_buffer.space() == 0)
@ -199,7 +199,7 @@ public class WebSocketParserD13 implements WebSocketParser
{
case START:
_skip=false;
_state=_opcode==WebSocketConnectionD13.OP_CLOSE?State.SEEK_EOF:State.OPCODE;
_state=_opcode==WebSocketConnectionRFC6455.OP_CLOSE?State.SEEK_EOF:State.OPCODE;
_bytesNeeded=_state.getNeeds();
continue;
@ -209,10 +209,10 @@ public class WebSocketParserD13 implements WebSocketParser
_opcode=(byte)(b&0xf);
_flags=(byte)(0xf&(b>>4));
if (WebSocketConnectionD13.isControlFrame(_opcode)&&!WebSocketConnectionD13.isLastFrame(_flags))
if (WebSocketConnectionRFC6455.isControlFrame(_opcode)&&!WebSocketConnectionRFC6455.isLastFrame(_flags))
{
LOG.warn("Fragmented Control from "+_endp);
_handler.close(WebSocketConnectionD13.CLOSE_PROTOCOL,"Fragmented control");
_handler.close(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"Fragmented control");
progress=true;
_skip=true;
}
@ -254,7 +254,7 @@ public class WebSocketParserD13 implements WebSocketParser
if (_length>_buffer.capacity() && !_fragmentFrames)
{
progress=true;
_handler.close(WebSocketConnectionD13.CLOSE_POLICY_VIOLATION,"frame size "+_length+">"+_buffer.capacity());
_handler.close(WebSocketConnectionRFC6455.CLOSE_POLICY_VIOLATION,"frame size "+_length+">"+_buffer.capacity());
_skip=true;
}
@ -273,7 +273,7 @@ public class WebSocketParserD13 implements WebSocketParser
if (_length>=_buffer.capacity() && !_fragmentFrames)
{
progress=true;
_handler.close(WebSocketConnectionD13.CLOSE_POLICY_VIOLATION,"frame size "+_length+">"+_buffer.capacity());
_handler.close(WebSocketConnectionRFC6455.CLOSE_POLICY_VIOLATION,"frame size "+_length+">"+_buffer.capacity());
_skip=true;
}
@ -323,7 +323,7 @@ public class WebSocketParserD13 implements WebSocketParser
_buffer.skip(_bytesNeeded);
_state=State.START;
progress=true;
_handler.close(WebSocketConnectionD13.CLOSE_PROTOCOL,"Not masked");
_handler.close(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,"Not masked");
}
else
{

View File

@ -7,15 +7,15 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.io.EndPoint;
public class WebSocketServletConnectionD13 extends WebSocketConnectionD13 implements WebSocketServletConnection
public class WebSocketServletConnectionRFC6455 extends WebSocketConnectionRFC6455 implements WebSocketServletConnection
{
public WebSocketServletConnectionD13(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol,
public WebSocketServletConnectionRFC6455(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol,
List<Extension> extensions, int draft, MaskGen maskgen) throws IOException
{
super(websocket,endpoint,buffers,timestamp,maxIdleTime,protocol,extensions,draft,maskgen);
}
public WebSocketServletConnectionD13(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol,
public WebSocketServletConnectionRFC6455(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol,
List<Extension> extensions, int draft) throws IOException
{
super(websocket,endpoint,buffers,timestamp,maxIdleTime,protocol,extensions,draft);

View File

@ -140,7 +140,7 @@ public class TestClient implements WebSocket.OnFrame
{
__framesSent++;
byte flags= (byte)(off+len==data.length?0x8:0);
byte op=(byte)(off==0?opcode:WebSocketConnectionD13.OP_CONTINUATION);
byte op=(byte)(off==0?opcode:WebSocketConnectionRFC6455.OP_CONTINUATION);
if (_verbose)
System.err.printf("%s#sendFrame %s|%s %s\n",this.getClass().getSimpleName(),TypeUtil.toHexString(flags),TypeUtil.toHexString(op),TypeUtil.toHexString(data,off,len));
@ -158,7 +158,9 @@ public class TestClient implements WebSocket.OnFrame
public void disconnect() throws Exception
{
if (_connection!=null)
_connection.disconnect();
{
_connection.close();
}
}
@ -245,11 +247,11 @@ public class TestClient implements WebSocket.OnFrame
{
long next = System.currentTimeMillis()+delay;
byte opcode=binary?WebSocketConnectionD13.OP_BINARY:WebSocketConnectionD13.OP_TEXT;
byte opcode=binary?WebSocketConnectionRFC6455.OP_BINARY:WebSocketConnectionRFC6455.OP_TEXT;
byte data[]=null;
if (opcode==WebSocketConnectionD13.OP_TEXT)
if (opcode==WebSocketConnectionRFC6455.OP_TEXT)
{
StringBuilder b = new StringBuilder();
while (b.length()<size)
@ -263,7 +265,7 @@ public class TestClient implements WebSocket.OnFrame
}
for (int i=0;i<clients;i++)
client[i].ping(opcode,data,opcode==WebSocketConnectionD13.OP_PING?-1:fragment);
client[i].ping(opcode,data,opcode==WebSocketConnectionRFC6455.OP_PING?-1:fragment);
while(System.currentTimeMillis()<next)
Thread.sleep(10);

View File

@ -207,7 +207,7 @@ public class TestServer extends Server
{
System.err.println("Ping "+connection);
byte[] data = { (byte)1, (byte) 2, (byte) 3 };
connection.sendControl(WebSocketConnectionD13.OP_PING,data,0,data.length);
connection.sendControl(WebSocketConnectionRFC6455.OP_PING,data,0,data.length);
}
}
catch (Exception e)
@ -223,7 +223,7 @@ public class TestServer extends Server
@Override
public boolean onControl(byte controlCode, byte[] data, int offset, int length)
{
if (controlCode==WebSocketConnectionD13.OP_PONG)
if (controlCode==WebSocketConnectionRFC6455.OP_PONG)
System.err.println("Pong "+getConnection());
return super.onControl(controlCode,data,offset,length);
}

View File

@ -167,7 +167,7 @@ public class WebSocketClientTest
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD13.CLOSE_NO_CLOSE,close.get());
Assert.assertEquals(WebSocketConnectionRFC6455.CLOSE_NO_CLOSE,close.get());
Assert.assertTrue(error instanceof ConnectException);
}
@ -207,7 +207,7 @@ public class WebSocketClientTest
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD13.CLOSE_NO_CLOSE,close.get());
Assert.assertEquals(WebSocketConnectionRFC6455.CLOSE_NO_CLOSE,close.get());
Assert.assertTrue(error instanceof TimeoutException);
}
@ -246,7 +246,7 @@ public class WebSocketClientTest
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD13.CLOSE_NO_CLOSE,close.get());
Assert.assertEquals(WebSocketConnectionRFC6455.CLOSE_NO_CLOSE,close.get());
Assert.assertTrue(error instanceof TimeoutException);
}
@ -287,7 +287,7 @@ public class WebSocketClientTest
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD13.CLOSE_PROTOCOL,close.get());
Assert.assertEquals(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,close.get());
Assert.assertTrue(error instanceof IOException);
Assert.assertTrue(error.getMessage().indexOf("404 NOT FOUND")>0);
@ -330,7 +330,7 @@ public class WebSocketClientTest
error=e.getCause();
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD13.CLOSE_PROTOCOL,close.get());
Assert.assertEquals(WebSocketConnectionRFC6455.CLOSE_PROTOCOL,close.get());
Assert.assertTrue(error instanceof IOException);
Assert.assertTrue(error.getMessage().indexOf("Bad Sec-WebSocket-Accept")>=0);
}
@ -368,7 +368,7 @@ public class WebSocketClientTest
socket.close();
_latch.await(10,TimeUnit.SECONDS);
Assert.assertEquals(WebSocketConnectionD13.CLOSE_NO_CLOSE,close.get());
Assert.assertEquals(WebSocketConnectionRFC6455.CLOSE_NO_CLOSE,close.get());
}
@ -406,7 +406,7 @@ public class WebSocketClientTest
long start=System.currentTimeMillis();
_latch.await(10,TimeUnit.SECONDS);
Assert.assertTrue(System.currentTimeMillis()-start<5000);
Assert.assertEquals(WebSocketConnectionD13.CLOSE_NORMAL,close.get());
Assert.assertEquals(WebSocketConnectionRFC6455.CLOSE_NORMAL,close.get());
}
@ -748,7 +748,7 @@ public class WebSocketClientTest
}
connection.getOutputStream().write((
"HTTP/1.1 101 Upgrade\r\n" +
"Sec-WebSocket-Accept: "+ WebSocketConnectionD13.hashKey(key) +"\r\n" +
"Sec-WebSocket-Accept: "+ WebSocketConnectionRFC6455.hashKey(key) +"\r\n" +
"\r\n").getBytes());
}
}

View File

@ -13,7 +13,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketGeneratorD13Test
public class WebSocketGeneratorRFC6455Test
{
private ByteArrayBuffer _out;
private WebSocketGenerator _generator;
@ -44,7 +44,7 @@ public class WebSocketGeneratorD13Test
@Test
public void testOneString() throws Exception
{
_generator = new WebSocketGeneratorD13(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorRFC6455(_buffers, _endPoint,null);
byte[] data = "Hell\uFF4F W\uFF4Frld".getBytes(StringUtil.__UTF8);
_generator.addFrame((byte)0x8,(byte)0x04,data,0,data.length);
@ -71,7 +71,7 @@ public class WebSocketGeneratorD13Test
@Test
public void testOneBuffer() throws Exception
{
_generator = new WebSocketGeneratorD13(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorRFC6455(_buffers, _endPoint,null);
String string = "Hell\uFF4F W\uFF4Frld";
byte[] bytes=string.getBytes(StringUtil.__UTF8);
@ -99,7 +99,7 @@ public class WebSocketGeneratorD13Test
@Test
public void testOneLongBuffer() throws Exception
{
_generator = new WebSocketGeneratorD13(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorRFC6455(_buffers, _endPoint,null);
byte[] b=new byte[150];
for (int i=0;i<b.length;i++)
@ -120,7 +120,7 @@ public class WebSocketGeneratorD13Test
@Test
public void testOneStringMasked() throws Exception
{
_generator = new WebSocketGeneratorD13(_buffers, _endPoint,_maskGen);
_generator = new WebSocketGeneratorRFC6455(_buffers, _endPoint,_maskGen);
byte[] data = "Hell\uFF4F W\uFF4Frld".getBytes(StringUtil.__UTF8);
_generator.addFrame((byte)0x8,(byte)0x04,data,0,data.length);
@ -149,7 +149,7 @@ public class WebSocketGeneratorD13Test
@Test
public void testOneBufferMasked() throws Exception
{
_generator = new WebSocketGeneratorD13(_buffers, _endPoint,_maskGen);
_generator = new WebSocketGeneratorRFC6455(_buffers, _endPoint,_maskGen);
String string = "Hell\uFF4F W\uFF4Frld";
byte[] bytes=string.getBytes(StringUtil.__UTF8);
@ -179,7 +179,7 @@ public class WebSocketGeneratorD13Test
@Test
public void testOneLongBufferMasked() throws Exception
{
_generator = new WebSocketGeneratorD13(_buffers, _endPoint,_maskGen);
_generator = new WebSocketGeneratorRFC6455(_buffers, _endPoint,_maskGen);
byte[] b=new byte[150];
for (int i=0;i<b.length;i++)
@ -203,7 +203,7 @@ public class WebSocketGeneratorD13Test
@Test
public void testClose() throws Exception
{
_generator = new WebSocketGeneratorD13(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorRFC6455(_buffers, _endPoint,null);
byte[] data = "xxGame Over".getBytes(StringUtil.__UTF8);
data[0]=(byte)(1000/0x100);

View File

@ -142,7 +142,7 @@ public class WebSocketLoadD13Test
private final int iterations;
private final CountDownLatch latch;
private final SocketEndPoint _endp;
private final WebSocketGeneratorD13 _generator;
private final WebSocketGeneratorRFC6455 _generator;
private final WebSocketParserD13 _parser;
private final WebSocketParser.FrameHandler _handler = new WebSocketParser.FrameHandler()
{
@ -167,7 +167,7 @@ public class WebSocketLoadD13Test
this.iterations = iterations;
_endp=new SocketEndPoint(socket);
_generator = new WebSocketGeneratorD13(new WebSocketBuffers(32*1024),_endp,new FixedMaskGen());
_generator = new WebSocketGeneratorRFC6455(new WebSocketBuffers(32*1024),_endp,new FixedMaskGen());
_parser = new WebSocketParserD13(new WebSocketBuffers(32*1024),_endp,_handler,false);
}
@ -202,7 +202,7 @@ public class WebSocketLoadD13Test
for (int i = 0; i < iterations; ++i)
{
byte[] data = message.getBytes(StringUtil.__UTF8);
_generator.addFrame((byte)0x8,WebSocketConnectionD13.OP_TEXT,data,0,data.length);
_generator.addFrame((byte)0x8,WebSocketConnectionRFC6455.OP_TEXT,data,0,data.length);
_generator.flush();
//System.err.println("-> "+message);

View File

@ -35,7 +35,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketMessageD13Test
public class WebSocketMessageRFC6455Test
{
private static Server __server;
private static Connector __connector;
@ -82,7 +82,7 @@ public class WebSocketMessageD13Test
@Test
public void testHash()
{
assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",WebSocketConnectionD13.hashKey("dGhlIHNhbXBsZSBub25jZQ=="));
assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",WebSocketConnectionRFC6455.hashKey("dGhlIHNhbXBsZSBub25jZQ=="));
}
@Test
@ -98,7 +98,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: chat, superchat\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -123,7 +123,7 @@ public class WebSocketMessageD13Test
String data=message.toString();
__serverWebSocket.connection.sendMessage(data);
assertEquals(WebSocketConnectionD13.OP_TEXT,input.read());
assertEquals(WebSocketConnectionRFC6455.OP_TEXT,input.read());
assertEquals(0x7e,input.read());
assertEquals(0x1f,input.read());
assertEquals(0xf6,input.read());
@ -146,7 +146,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -181,7 +181,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"Sec-WebSocket-Extensions: identity;param=0\r\n"+
"Sec-WebSocket-Extensions: identity;param=1, identity ; param = '2' ; other = ' some = value ' \r\n"+
"\r\n").getBytes("ISO-8859-1"));
@ -224,7 +224,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"Sec-WebSocket-Extensions: fragment;maxLength=4;minFragments=7\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -278,7 +278,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: echo\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"Sec-WebSocket-Extensions: x-deflate-frame;minLength=64\r\n"+
"Sec-WebSocket-Extensions: fragment;minFragments=2\r\n"+
"\r\n").getBytes("ISO-8859-1"));
@ -329,7 +329,7 @@ public class WebSocketMessageD13Test
output.write(buf,0,l+3);
output.flush();
assertEquals(0x40+WebSocketConnectionD13.OP_TEXT,input.read());
assertEquals(0x40+WebSocketConnectionRFC6455.OP_TEXT,input.read());
assertEquals(0x20+3,input.read());
assertEquals(0x7e,input.read());
assertEquals(0x02,input.read());
@ -376,7 +376,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: echo\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
output.write(0x84);
@ -415,7 +415,7 @@ public class WebSocketMessageD13Test
byte[] bytes="This is a long message of text that we will send again and again".getBytes(StringUtil.__ISO_8859_1);
byte[] mesg=new byte[bytes.length+6];
mesg[0]=(byte)(0x80+WebSocketConnectionD13.OP_TEXT);
mesg[0]=(byte)(0x80+WebSocketConnectionRFC6455.OP_TEXT);
mesg[1]=(byte)(0x80+bytes.length);
mesg[2]=(byte)0xff;
mesg[3]=(byte)0xff;
@ -434,7 +434,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: latch\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -522,7 +522,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: latch\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -610,7 +610,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: echo\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
output.write(0x89);
@ -649,7 +649,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -681,10 +681,10 @@ public class WebSocketMessageD13Test
output.flush();
assertEquals(0x80|WebSocketConnectionD13.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionRFC6455.OP_CLOSE,input.read());
assertEquals(33,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(WebSocketConnectionD13.CLOSE_MESSAGE_TOO_LARGE,code);
assertEquals(WebSocketConnectionRFC6455.CLOSE_MESSAGE_TOO_LARGE,code);
lookFor("Text message size > 10240 chars",input);
}
@ -701,7 +701,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -739,10 +739,10 @@ public class WebSocketMessageD13Test
output.write(bytes[i]^0xff);
output.flush();
assertEquals(0x80|WebSocketConnectionD13.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionRFC6455.OP_CLOSE,input.read());
assertEquals(30,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(WebSocketConnectionD13.CLOSE_MESSAGE_TOO_LARGE,code);
assertEquals(WebSocketConnectionRFC6455.CLOSE_MESSAGE_TOO_LARGE,code);
lookFor("Text message size > 15 chars",input);
}
@ -760,7 +760,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -790,10 +790,10 @@ public class WebSocketMessageD13Test
assertEquals(0x80|WebSocketConnectionD13.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionRFC6455.OP_CLOSE,input.read());
assertEquals(30,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(WebSocketConnectionD13.CLOSE_MESSAGE_TOO_LARGE,code);
assertEquals(WebSocketConnectionRFC6455.CLOSE_MESSAGE_TOO_LARGE,code);
lookFor("Text message size > 15 chars",input);
}
@ -810,7 +810,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: aggregate\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -826,7 +826,7 @@ public class WebSocketMessageD13Test
assertNotNull(__serverWebSocket.connection);
__serverWebSocket.getConnection().setMaxBinaryMessageSize(1024);
output.write(WebSocketConnectionD13.OP_BINARY);
output.write(WebSocketConnectionRFC6455.OP_BINARY);
output.write(0x8a);
output.write(0xff);
output.write(0xff);
@ -847,7 +847,7 @@ public class WebSocketMessageD13Test
output.write(bytes[i]^0xff);
output.flush();
assertEquals(0x80+WebSocketConnectionD13.OP_BINARY,input.read());
assertEquals(0x80+WebSocketConnectionRFC6455.OP_BINARY,input.read());
assertEquals(20,input.read());
lookFor("01234567890123456789",input);
}
@ -865,7 +865,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -904,10 +904,10 @@ public class WebSocketMessageD13Test
output.flush();
assertEquals(0x80|WebSocketConnectionD13.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionRFC6455.OP_CLOSE,input.read());
assertEquals(19,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(WebSocketConnectionD13.CLOSE_MESSAGE_TOO_LARGE,code);
assertEquals(WebSocketConnectionRFC6455.CLOSE_MESSAGE_TOO_LARGE,code);
lookFor("Message size > 15",input);
}
@ -977,7 +977,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: chat\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -1088,7 +1088,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: chat\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -1159,7 +1159,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: chat\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -1186,10 +1186,10 @@ public class WebSocketMessageD13Test
output.write(0x28);
output.flush();
assertEquals(0x80|WebSocketConnectionD13.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionRFC6455.OP_CLOSE,input.read());
assertEquals(15,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(WebSocketConnectionD13.CLOSE_BAD_PAYLOAD,code);
assertEquals(WebSocketConnectionRFC6455.CLOSE_BAD_PAYLOAD,code);
lookFor("Invalid UTF-8",input);
}
@ -1206,7 +1206,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -1234,10 +1234,10 @@ public class WebSocketMessageD13Test
output.write(bytes[i]^0xff);
output.flush();
assertEquals(0x80|WebSocketConnectionD13.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionRFC6455.OP_CLOSE,input.read());
assertEquals(19,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(WebSocketConnectionD13.CLOSE_MESSAGE_TOO_LARGE,code);
assertEquals(WebSocketConnectionRFC6455.CLOSE_MESSAGE_TOO_LARGE,code);
lookFor("Message size > 15",input);
}
@ -1254,7 +1254,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -1316,7 +1316,7 @@ public class WebSocketMessageD13Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: "+WebSocketConnectionD13.VERSION+"\r\n"+
"Sec-WebSocket-Version: "+WebSocketConnectionRFC6455.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -1360,7 +1360,7 @@ public class WebSocketMessageD13Test
final AtomicReference<String> received = new AtomicReference<String>();
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
WebSocketGeneratorD13 gen = new WebSocketGeneratorD13(new WebSocketBuffers(8096),endp,null);
WebSocketGeneratorRFC6455 gen = new WebSocketGeneratorRFC6455(new WebSocketBuffers(8096),endp,null);
byte[] data = message.getBytes(StringUtil.__UTF8);
gen.addFrame((byte)0x8,(byte)0x4,data,0,data.length);
@ -1394,7 +1394,7 @@ public class WebSocketMessageD13Test
MaskGen maskGen = new RandomMaskGen();
WebSocketGeneratorD13 gen = new WebSocketGeneratorD13(new WebSocketBuffers(8096),endp,maskGen);
WebSocketGeneratorRFC6455 gen = new WebSocketGeneratorRFC6455(new WebSocketBuffers(8096),endp,maskGen);
byte[] data = message.getBytes(StringUtil.__UTF8);
gen.addFrame((byte)0x8,(byte)0x1,data,0,data.length);
@ -1524,9 +1524,9 @@ public class WebSocketMessageD13Test
{
switch(opcode)
{
case WebSocketConnectionD13.OP_CLOSE:
case WebSocketConnectionD13.OP_PING:
case WebSocketConnectionD13.OP_PONG:
case WebSocketConnectionRFC6455.OP_CLOSE:
case WebSocketConnectionRFC6455.OP_PING:
case WebSocketConnectionRFC6455.OP_PONG:
break;
default:

View File

@ -20,7 +20,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketParserD13Test
public class WebSocketParserRFC6455Test
{
private ByteArrayEndPoint _endPoint;
private MaskedByteArrayBuffer _in;
@ -269,7 +269,7 @@ public class WebSocketParserD13Test
int progress =_parser.parseNext();
assertTrue(progress>0);
assertEquals(WebSocketConnectionD13.CLOSE_POLICY_VIOLATION,_handler._code);
assertEquals(WebSocketConnectionRFC6455.CLOSE_POLICY_VIOLATION,_handler._code);
for (int i=0;i<2048;i++)
@ -313,7 +313,7 @@ public class WebSocketParserD13Test
assertTrue(progress>0);
assertEquals(2,_handler._frames);
assertEquals(WebSocketConnectionD13.OP_CONTINUATION,_handler._opcode);
assertEquals(WebSocketConnectionRFC6455.OP_CONTINUATION,_handler._opcode);
assertEquals(1,_handler._data.size());
String mesg=_handler._data.remove(0);