353073 updated to draft 11

This commit is contained in:
Greg Wilkins 2011-08-24 10:28:39 +10:00
parent 96d46df7da
commit 44b8d56289
12 changed files with 109 additions and 108 deletions

View File

@ -81,7 +81,7 @@ public class DeflateFrameExtension extends AbstractExtension
catch(DataFormatException e)
{
Log.warn(e);
getConnection().close(WebSocketConnectionD10.CLOSE_PROTOCOL,e.toString());
getConnection().close(WebSocketConnectionD11.CLOSE_PROTOCOL,e.toString());
}
}

View File

@ -138,7 +138,7 @@ public class TestClient implements WebSocket.OnFrame
{
__framesSent++;
byte flags= (byte)(off+len==data.length?0x8:0);
byte op=(byte)(off==0?opcode:WebSocketConnectionD10.OP_CONTINUATION);
byte op=(byte)(off==0?opcode:WebSocketConnectionD11.OP_CONTINUATION);
if (_verbose)
System.err.printf("%s#addFrame %s|%s %s\n",this.getClass().getSimpleName(),TypeUtil.toHexString(flags),TypeUtil.toHexString(op),TypeUtil.toHexString(data,off,len));
@ -240,11 +240,11 @@ public class TestClient implements WebSocket.OnFrame
{
long next = System.currentTimeMillis()+delay;
byte opcode=binary?WebSocketConnectionD10.OP_BINARY:WebSocketConnectionD10.OP_TEXT;
byte opcode=binary?WebSocketConnectionD11.OP_BINARY:WebSocketConnectionD11.OP_TEXT;
byte data[]=null;
if (opcode==WebSocketConnectionD10.OP_TEXT)
if (opcode==WebSocketConnectionD11.OP_TEXT)
{
StringBuilder b = new StringBuilder();
while (b.length()<size)
@ -258,7 +258,7 @@ public class TestClient implements WebSocket.OnFrame
}
for (int i=0;i<clients;i++)
client[i].ping(opcode,data,opcode==WebSocketConnectionD10.OP_PING?-1:fragment);
client[i].ping(opcode,data,opcode==WebSocketConnectionD11.OP_PING?-1:fragment);
while(System.currentTimeMillis()<next)
Thread.sleep(10);

View File

@ -474,8 +474,8 @@ public class WebSocketClient extends AggregateLifeCycle
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: "+_key+"\r\n"+
(_origin==null?"":"Sec-WebSocket-Origin: "+_origin+"\r\n")+
"Sec-WebSocket-Version: "+WebSocketConnectionD10.VERSION+"\r\n";
(_origin==null?"":"Origin: "+_origin+"\r\n")+
"Sec-WebSocket-Version: "+WebSocketConnectionD11.VERSION+"\r\n";
if (holder.getProtocol()!=null)
request+="Sec-WebSocket-Protocol: "+holder.getProtocol()+"\r\n";
@ -526,12 +526,12 @@ public class WebSocketClient extends AggregateLifeCycle
{
if (_accept==null)
_error="No Sec-WebSocket-Accept";
else if (!WebSocketConnectionD10.hashKey(_key).equals(_accept))
else if (!WebSocketConnectionD11.hashKey(_key).equals(_accept))
_error="Bad Sec-WebSocket-Accept";
else
{
Buffer header=_parser.getHeaderBuffer();
WebSocketConnectionD10 connection = new WebSocketConnectionD10(_holder.getWebSocket(),_endp,_buffers,System.currentTimeMillis(),_holder.getMaxIdleTime(),_holder.getProtocol(),null,10, new WebSocketGeneratorD10.RandomMaskGen());
WebSocketConnectionD11 connection = new WebSocketConnectionD11(_holder.getWebSocket(),_endp,_buffers,System.currentTimeMillis(),_holder.getMaxIdleTime(),_holder.getProtocol(),null,10, new WebSocketGeneratorD11.RandomMaskGen());
if (header.hasContent())
connection.fillBuffersFrom(header);
@ -638,9 +638,9 @@ public class WebSocketClient extends AggregateLifeCycle
if (channel!=null)
{
if (ex instanceof ProtocolException)
closeChannel(channel,WebSocketConnectionD10.CLOSE_PROTOCOL,ex.getMessage());
closeChannel(channel,WebSocketConnectionD11.CLOSE_PROTOCOL,ex.getMessage());
else
closeChannel(channel,WebSocketConnectionD10.CLOSE_NOCLOSE,ex.getMessage());
closeChannel(channel,WebSocketConnectionD11.CLOSE_NOCLOSE,ex.getMessage());
}
}
finally
@ -695,7 +695,7 @@ public class WebSocketClient extends AggregateLifeCycle
if (channel!=null)
{
closeChannel(channel,WebSocketConnectionD10.CLOSE_NOCLOSE,"cancelled");
closeChannel(channel,WebSocketConnectionD11.CLOSE_NOCLOSE,"cancelled");
return true;
}
return false;
@ -755,7 +755,7 @@ public class WebSocketClient extends AggregateLifeCycle
}
if (channel!=null)
closeChannel(channel,WebSocketConnectionD10.CLOSE_NOCLOSE,"timeout");
closeChannel(channel,WebSocketConnectionD11.CLOSE_NOCLOSE,"timeout");
if (exception!=null)
throw new ExecutionException(exception);
if (connection!=null)

View File

@ -37,9 +37,9 @@ import org.eclipse.jetty.websocket.WebSocket.OnBinaryMessage;
import org.eclipse.jetty.websocket.WebSocket.OnControl;
import org.eclipse.jetty.websocket.WebSocket.OnFrame;
import org.eclipse.jetty.websocket.WebSocket.OnTextMessage;
import org.eclipse.jetty.websocket.WebSocketGeneratorD10.MaskGen;
import org.eclipse.jetty.websocket.WebSocketGeneratorD11.MaskGen;
public class WebSocketConnectionD10 extends AbstractConnection implements WebSocketConnection
public class WebSocketConnectionD11 extends AbstractConnection implements WebSocketConnection
{
final static byte OP_CONTINUATION = 0x00;
final static byte OP_TEXT = 0x01;
@ -78,9 +78,9 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
private final static byte[] MAGIC;
private final IdleCheck _idle;
private final List<Extension> _extensions;
private final WebSocketParserD10 _parser;
private final WebSocketParserD11 _parser;
private final WebSocketParser.FrameHandler _inbound;
private final WebSocketGeneratorD10 _generator;
private final WebSocketGeneratorD11 _generator;
private final WebSocketGenerator _outbound;
private final WebSocket _webSocket;
private final OnFrame _onFrame;
@ -119,14 +119,14 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
/* ------------------------------------------------------------ */
public WebSocketConnectionD10(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol, List<Extension> extensions,int draft)
public WebSocketConnectionD11(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 WebSocketConnectionD10(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol, List<Extension> extensions,int draft, MaskGen maskgen)
public WebSocketConnectionD11(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol, List<Extension> extensions,int draft, MaskGen maskgen)
throws IOException
{
super(endpoint,timestamp);
@ -145,7 +145,7 @@ public class WebSocketConnectionD10 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 WebSocketGeneratorD10(buffers, _endp,maskgen);
_generator = new WebSocketGeneratorD11(buffers, _endp,maskgen);
_extensions=extensions;
if (_extensions!=null)
@ -164,7 +164,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
_outbound=(_extensions==null||_extensions.size()==0)?_generator:extensions.get(extensions.size()-1);
_inbound=(_extensions==null||_extensions.size()==0)?_frameHandler:extensions.get(0);
_parser = new WebSocketParserD10(buffers, endpoint,_inbound,maskgen==null);
_parser = new WebSocketParserD11(buffers, endpoint,_inbound,maskgen==null);
_protocol=protocol;
@ -277,7 +277,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
public void idleExpired()
{
long idle = System.currentTimeMillis()-((SelectChannelEndPoint)_endp).getIdleTimestamp();
closeOut(WebSocketConnectionD10.CLOSE_NORMAL,"Idle for "+idle+"ms");
closeOut(WebSocketConnectionD11.CLOSE_NORMAL,"Idle for "+idle+"ms");
}
/* ------------------------------------------------------------ */
@ -294,10 +294,10 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
{
closed=_closeCode==0;
if (closed)
_closeCode=WebSocketConnectionD10.CLOSE_NOCLOSE;
_closeCode=WebSocketConnectionD11.CLOSE_NOCLOSE;
}
if (closed)
_webSocket.onClose(WebSocketConnectionD10.CLOSE_NOCLOSE,"closed");
_webSocket.onClose(WebSocketConnectionD11.CLOSE_NOCLOSE,"closed");
}
/* ------------------------------------------------------------ */
@ -373,11 +373,11 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
else
{
if (code<=0)
code=WebSocketConnectionD10.CLOSE_NORMAL;
code=WebSocketConnectionD11.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,WebSocketConnectionD10.OP_CLOSE,bytes,0,bytes.length);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD11.OP_CLOSE,bytes,0,bytes.length);
}
_outbound.flush();
@ -410,8 +410,8 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
private class WSFrameConnection implements WebSocket.FrameConnection
{
volatile boolean _disconnecting;
int _maxTextMessage=WebSocketConnectionD10.this._maxTextMessageSize;
int _maxBinaryMessage=WebSocketConnectionD10.this._maxBinaryMessageSize;
int _maxTextMessage=WebSocketConnectionD11.this._maxTextMessageSize;
int _maxBinaryMessage=WebSocketConnectionD11.this._maxBinaryMessageSize;
/* ------------------------------------------------------------ */
public void sendMessage(String content) throws IOException
@ -419,7 +419,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
if (_closedOut)
throw new IOException("closedOut "+_closeCode+":"+_closeMessage);
byte[] data = content.getBytes(StringUtil.__UTF8);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD10.OP_TEXT,data,0,data.length);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD11.OP_TEXT,data,0,data.length);
checkWriteable();
_idle.access(_endp);
}
@ -429,7 +429,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
{
if (_closedOut)
throw new IOException("closedOut "+_closeCode+":"+_closeMessage);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD10.OP_BINARY,content,offset,length);
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD11.OP_BINARY,content,offset,length);
checkWriteable();
_idle.access(_endp);
}
@ -472,7 +472,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
if (_disconnecting)
return;
_disconnecting=true;
WebSocketConnectionD10.this.closeOut(code,message);
WebSocketConnectionD11.this.closeOut(code,message);
}
/* ------------------------------------------------------------ */
@ -609,7 +609,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
{
boolean lastFrame = isLastFrame(flags);
synchronized(WebSocketConnectionD10.this)
synchronized(WebSocketConnectionD11.this)
{
// Ignore incoming after a close
if (_closedIn)
@ -634,10 +634,10 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
switch(opcode)
{
case WebSocketConnectionD10.OP_CONTINUATION:
case WebSocketConnectionD11.OP_CONTINUATION:
{
// If text, append to the message buffer
if (_onTextMessage!=null && _opcode==WebSocketConnectionD10.OP_TEXT)
if (_onTextMessage!=null && _opcode==WebSocketConnectionD11.OP_TEXT)
{
if (_utf8.append(buffer.array(),buffer.getIndex(),buffer.length(),_connection.getMaxTextMessageSize()))
{
@ -677,23 +677,23 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
}
break;
}
case WebSocketConnectionD10.OP_PING:
case WebSocketConnectionD11.OP_PING:
{
Log.debug("PING {}",this);
if (!_closedOut)
_connection.sendControl(WebSocketConnectionD10.OP_PONG,buffer.array(),buffer.getIndex(),buffer.length());
_connection.sendControl(WebSocketConnectionD11.OP_PONG,buffer.array(),buffer.getIndex(),buffer.length());
break;
}
case WebSocketConnectionD10.OP_PONG:
case WebSocketConnectionD11.OP_PONG:
{
Log.debug("PONG {}",this);
break;
}
case WebSocketConnectionD10.OP_CLOSE:
case WebSocketConnectionD11.OP_CLOSE:
{
int code=WebSocketConnectionD10.CLOSE_NOCODE;
int code=WebSocketConnectionD11.CLOSE_NOCODE;
String message=null;
if (buffer.length()>=2)
{
@ -705,7 +705,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
break;
}
case WebSocketConnectionD10.OP_TEXT:
case WebSocketConnectionD11.OP_TEXT:
{
if(_onTextMessage!=null)
{
@ -725,7 +725,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
}
else
{
_opcode=WebSocketConnectionD10.OP_TEXT;
_opcode=WebSocketConnectionD11.OP_TEXT;
}
}
else
@ -769,7 +769,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
int max = _connection.getMaxBinaryMessageSize();
if (max>0 && (bufferLen+length)>max)
{
_connection.close(WebSocketConnectionD10.CLOSE_LARGE,"Message size > "+_connection.getMaxBinaryMessageSize());
_connection.close(WebSocketConnectionD11.CLOSE_LARGE,"Message size > "+_connection.getMaxBinaryMessageSize());
_opcode=-1;
if (_aggregate!=null)
_aggregate.clear();
@ -780,7 +780,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
private void textMessageTooLarge()
{
_connection.close(WebSocketConnectionD10.CLOSE_LARGE,"Text message size > "+_connection.getMaxTextMessageSize()+" chars");
_connection.close(WebSocketConnectionD11.CLOSE_LARGE,"Text message size > "+_connection.getMaxTextMessageSize()+" chars");
_opcode=-1;
_utf8.reset();
@ -795,7 +795,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
public String toString()
{
return WebSocketConnectionD10.this.toString()+"FH";
return WebSocketConnectionD11.this.toString()+"FH";
}
}

View File

@ -178,8 +178,9 @@ public class WebSocketFactory
case 8:
case 9:
case 10:
extensions= initExtensions(extensions_requested,8-WebSocketConnectionD10.OP_EXT_DATA, 16-WebSocketConnectionD10.OP_EXT_CTRL,3);
connection = new WebSocketConnectionD10(websocket, endp, _buffers, http.getTimeStamp(), _maxIdleTime, protocol,extensions,draft);
case 11:
extensions= initExtensions(extensions_requested,8-WebSocketConnectionD11.OP_EXT_DATA, 16-WebSocketConnectionD11.OP_EXT_CTRL,3);
connection = new WebSocketConnectionD11(websocket, endp, _buffers, http.getTimeStamp(), _maxIdleTime, protocol,extensions,draft);
break;
default:
Log.warn("Unsupported Websocket version: "+draft);
@ -216,9 +217,9 @@ public class WebSocketFactory
{
if ("websocket".equalsIgnoreCase(request.getHeader("Upgrade")))
{
String origin = request.getHeader("Sec-WebSocket-Origin");
String origin = request.getHeader("Origin");
if (origin==null)
origin = request.getHeader("Origin");
origin = request.getHeader("Sec-WebSocket-Origin");
if (!_acceptor.checkOrigin(request,origin))
{
response.sendError(HttpServletResponse.SC_FORBIDDEN);

View File

@ -28,7 +28,7 @@ import org.eclipse.jetty.io.EofException;
* threads will call the addMessage methods while other
* threads are flushing the generator.
*/
public class WebSocketGeneratorD10 implements WebSocketGenerator
public class WebSocketGeneratorD11 implements WebSocketGenerator
{
final private WebSocketBuffers _buffers;
final private EndPoint _endp;
@ -93,14 +93,14 @@ public class WebSocketGeneratorD10 implements WebSocketGenerator
}
public WebSocketGeneratorD10(WebSocketBuffers buffers, EndPoint endp)
public WebSocketGeneratorD11(WebSocketBuffers buffers, EndPoint endp)
{
_buffers=buffers;
_endp=endp;
_maskGen=null;
}
public WebSocketGeneratorD10(WebSocketBuffers buffers, EndPoint endp, MaskGen maskGen)
public WebSocketGeneratorD11(WebSocketBuffers buffers, EndPoint endp, MaskGen maskGen)
{
_buffers=buffers;
_endp=endp;
@ -116,14 +116,14 @@ public class WebSocketGeneratorD10 implements WebSocketGenerator
if (_buffer==null)
_buffer=mask?_buffers.getBuffer():_buffers.getDirectBuffer();
boolean last=WebSocketConnectionD10.isLastFrame(flags);
boolean last=WebSocketConnectionD11.isLastFrame(flags);
byte orig=opcode;
int space=mask?14:10;
do
{
opcode = _opsent?WebSocketConnectionD10.OP_CONTINUATION:opcode;
opcode = _opsent?WebSocketConnectionD11.OP_CONTINUATION:opcode;
opcode=(byte)(((0xf&flags)<<4)+(0xf&opcode));
_opsent=true;

View File

@ -27,7 +27,7 @@ import org.eclipse.jetty.util.log.Log;
* Parser the WebSocket protocol.
*
*/
public class WebSocketParserD10 implements WebSocketParser
public class WebSocketParserD11 implements WebSocketParser
{
public enum State {
@ -70,7 +70,7 @@ public class WebSocketParserD10 implements WebSocketParser
* @param endp
* @param handler
*/
public WebSocketParserD10(WebSocketBuffers buffers, EndPoint endp, FrameHandler handler, boolean shouldBeMasked)
public WebSocketParserD11(WebSocketBuffers buffers, EndPoint endp, FrameHandler handler, boolean shouldBeMasked)
{
_buffers=buffers;
_endp=endp;
@ -157,9 +157,9 @@ public class WebSocketParserD10 implements WebSocketParser
// System.err.printf("%s %s %s >>\n",TypeUtil.toHexString(_flags),TypeUtil.toHexString(_opcode),data.length());
events++;
_bytesNeeded-=data.length();
_handler.onFrame((byte)(_flags&(0xff^WebSocketConnectionD10.FLAG_FIN)), _opcode, data);
_handler.onFrame((byte)(_flags&(0xff^WebSocketConnectionD11.FLAG_FIN)), _opcode, data);
_opcode=WebSocketConnectionD10.OP_CONTINUATION;
_opcode=WebSocketConnectionD11.OP_CONTINUATION;
}
if (_buffer.space() == 0)
@ -202,11 +202,11 @@ public class WebSocketParserD10 implements WebSocketParser
_opcode=(byte)(b&0xf);
_flags=(byte)(0xf&(b>>4));
if (WebSocketConnectionD10.isControlFrame(_opcode)&&!WebSocketConnectionD10.isLastFrame(_flags))
if (WebSocketConnectionD11.isControlFrame(_opcode)&&!WebSocketConnectionD11.isLastFrame(_flags))
{
events++;
Log.warn("Fragmented Control from "+_endp);
_handler.close(WebSocketConnectionD10.CLOSE_PROTOCOL,"Fragmented control");
_handler.close(WebSocketConnectionD11.CLOSE_PROTOCOL,"Fragmented control");
_skip=true;
}
@ -247,7 +247,7 @@ public class WebSocketParserD10 implements WebSocketParser
if (_length>_buffer.capacity() && !_fakeFragments)
{
events++;
_handler.close(WebSocketConnectionD10.CLOSE_LARGE,"frame size "+_length+">"+_buffer.capacity());
_handler.close(WebSocketConnectionD11.CLOSE_LARGE,"frame size "+_length+">"+_buffer.capacity());
_skip=true;
}
@ -266,7 +266,7 @@ public class WebSocketParserD10 implements WebSocketParser
if (_length>=_buffer.capacity())
{
events++;
_handler.close(WebSocketConnectionD10.CLOSE_LARGE,"frame size "+_length+">"+_buffer.capacity());
_handler.close(WebSocketConnectionD11.CLOSE_LARGE,"frame size "+_length+">"+_buffer.capacity());
_skip=true;
}
@ -309,7 +309,7 @@ public class WebSocketParserD10 implements WebSocketParser
_buffer.skip(_bytesNeeded);
_state=State.START;
events++;
_handler.close(WebSocketConnectionD10.CLOSE_PROTOCOL,"bad mask");
_handler.close(WebSocketConnectionD11.CLOSE_PROTOCOL,"bad mask");
}
else
{

View File

@ -110,7 +110,7 @@ public class WebSocketClientTest
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD10.CLOSE_NOCLOSE,close.get());
Assert.assertEquals(WebSocketConnectionD11.CLOSE_NOCLOSE,close.get());
Assert.assertTrue(error instanceof ConnectException);
}
@ -151,7 +151,7 @@ public class WebSocketClientTest
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD10.CLOSE_NOCLOSE,close.get());
Assert.assertEquals(WebSocketConnectionD11.CLOSE_NOCLOSE,close.get());
Assert.assertTrue(error instanceof TimeoutException);
}
@ -191,7 +191,7 @@ public class WebSocketClientTest
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD10.CLOSE_NOCLOSE,close.get());
Assert.assertEquals(WebSocketConnectionD11.CLOSE_NOCLOSE,close.get());
Assert.assertTrue(error instanceof TimeoutException);
}
@ -233,7 +233,7 @@ public class WebSocketClientTest
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD10.CLOSE_PROTOCOL,close.get());
Assert.assertEquals(WebSocketConnectionD11.CLOSE_PROTOCOL,close.get());
Assert.assertTrue(error instanceof IOException);
Assert.assertTrue(error.getMessage().indexOf("404 NOT FOUND")>0);
@ -277,7 +277,7 @@ public class WebSocketClientTest
error=e.getCause();
}
Assert.assertFalse(open.get());
Assert.assertEquals(WebSocketConnectionD10.CLOSE_PROTOCOL,close.get());
Assert.assertEquals(WebSocketConnectionD11.CLOSE_PROTOCOL,close.get());
Assert.assertTrue(error instanceof IOException);
Assert.assertTrue(error.getMessage().indexOf("Bad Sec-WebSocket-Accept")>=0);
}
@ -316,7 +316,7 @@ public class WebSocketClientTest
socket.close();
_latch.await(10,TimeUnit.SECONDS);
Assert.assertEquals(WebSocketConnectionD10.CLOSE_NOCLOSE,close.get());
Assert.assertEquals(WebSocketConnectionD11.CLOSE_NOCLOSE,close.get());
}
@ -355,7 +355,7 @@ public class WebSocketClientTest
long start=System.currentTimeMillis();
_latch.await(10,TimeUnit.SECONDS);
Assert.assertTrue(System.currentTimeMillis()-start<5000);
Assert.assertEquals(WebSocketConnectionD10.CLOSE_NORMAL,close.get());
Assert.assertEquals(WebSocketConnectionD11.CLOSE_NORMAL,close.get());
}
@ -482,7 +482,7 @@ public class WebSocketClientTest
}
connection.getOutputStream().write((
"HTTP/1.1 101 Upgrade\r\n" +
"Sec-WebSocket-Accept: "+ WebSocketConnectionD10.hashKey(key) +"\r\n" +
"Sec-WebSocket-Accept: "+ WebSocketConnectionD11.hashKey(key) +"\r\n" +
"\r\n").getBytes());
}
}

View File

@ -11,7 +11,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketGeneratorD10Test
public class WebSocketGeneratorD11Test
{
private ByteArrayBuffer _out;
private WebSocketGenerator _generator;
@ -20,7 +20,7 @@ public class WebSocketGeneratorD10Test
byte[] _mask = new byte[4];
int _m;
public WebSocketGeneratorD10.MaskGen _maskGen = new WebSocketGeneratorD10.FixedMaskGen(
public WebSocketGeneratorD11.MaskGen _maskGen = new WebSocketGeneratorD11.FixedMaskGen(
new byte[]{(byte)0x00,(byte)0x00,(byte)0x0f,(byte)0xff});
@Before
@ -42,7 +42,7 @@ public class WebSocketGeneratorD10Test
@Test
public void testOneString() throws Exception
{
_generator = new WebSocketGeneratorD10(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorD11(_buffers, _endPoint,null);
byte[] data = "Hell\uFF4F W\uFF4Frld".getBytes(StringUtil.__UTF8);
_generator.addFrame((byte)0x8,(byte)0x04,data,0,data.length);
@ -69,7 +69,7 @@ public class WebSocketGeneratorD10Test
@Test
public void testOneBuffer() throws Exception
{
_generator = new WebSocketGeneratorD10(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorD11(_buffers, _endPoint,null);
String string = "Hell\uFF4F W\uFF4Frld";
byte[] bytes=string.getBytes(StringUtil.__UTF8);
@ -97,7 +97,7 @@ public class WebSocketGeneratorD10Test
@Test
public void testOneLongBuffer() throws Exception
{
_generator = new WebSocketGeneratorD10(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorD11(_buffers, _endPoint,null);
byte[] b=new byte[150];
for (int i=0;i<b.length;i++)
@ -118,7 +118,7 @@ public class WebSocketGeneratorD10Test
@Test
public void testOneStringMasked() throws Exception
{
_generator = new WebSocketGeneratorD10(_buffers, _endPoint,_maskGen);
_generator = new WebSocketGeneratorD11(_buffers, _endPoint,_maskGen);
byte[] data = "Hell\uFF4F W\uFF4Frld".getBytes(StringUtil.__UTF8);
_generator.addFrame((byte)0x8,(byte)0x04,data,0,data.length);
@ -147,7 +147,7 @@ public class WebSocketGeneratorD10Test
@Test
public void testOneBufferMasked() throws Exception
{
_generator = new WebSocketGeneratorD10(_buffers, _endPoint,_maskGen);
_generator = new WebSocketGeneratorD11(_buffers, _endPoint,_maskGen);
String string = "Hell\uFF4F W\uFF4Frld";
byte[] bytes=string.getBytes(StringUtil.__UTF8);
@ -177,7 +177,7 @@ public class WebSocketGeneratorD10Test
@Test
public void testOneLongBufferMasked() throws Exception
{
_generator = new WebSocketGeneratorD10(_buffers, _endPoint,_maskGen);
_generator = new WebSocketGeneratorD11(_buffers, _endPoint,_maskGen);
byte[] b=new byte[150];
for (int i=0;i<b.length;i++)

View File

@ -33,7 +33,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketLoadD10Test
public class WebSocketLoadD11Test
{
private static Server _server;
private static Connector _connector;
@ -142,8 +142,8 @@ public class WebSocketLoadD10Test
private final int iterations;
private final CountDownLatch latch;
private final SocketEndPoint _endp;
private final WebSocketGeneratorD10 _generator;
private final WebSocketParserD10 _parser;
private final WebSocketGeneratorD11 _generator;
private final WebSocketParserD11 _parser;
private final WebSocketParser.FrameHandler _handler = new WebSocketParser.FrameHandler()
{
public void onFrame(byte flags, byte opcode, Buffer buffer)
@ -167,8 +167,8 @@ public class WebSocketLoadD10Test
this.iterations = iterations;
_endp=new SocketEndPoint(socket);
_generator = new WebSocketGeneratorD10(new WebSocketBuffers(32*1024),_endp,new WebSocketGeneratorD10.FixedMaskGen());
_parser = new WebSocketParserD10(new WebSocketBuffers(32*1024),_endp,_handler,false);
_generator = new WebSocketGeneratorD11(new WebSocketBuffers(32*1024),_endp,new WebSocketGeneratorD11.FixedMaskGen());
_parser = new WebSocketParserD11(new WebSocketBuffers(32*1024),_endp,_handler,false);
}
@ -202,7 +202,7 @@ public class WebSocketLoadD10Test
for (int i = 0; i < iterations; ++i)
{
byte[] data = message.getBytes(StringUtil.__UTF8);
_generator.addFrame((byte)0x8,WebSocketConnectionD10.OP_TEXT,data,0,data.length);
_generator.addFrame((byte)0x8,WebSocketConnectionD11.OP_TEXT,data,0,data.length);
_generator.flush();
//System.err.println("-> "+message);

View File

@ -33,7 +33,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketMessageD10Test
public class WebSocketMessageD11Test
{
private static Server _server;
private static Connector _connector;
@ -74,7 +74,7 @@ public class WebSocketMessageD10Test
@Test
public void testHash()
{
assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",WebSocketConnectionD10.hashKey("dGhlIHNhbXBsZSBub25jZQ=="));
assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",WebSocketConnectionD11.hashKey("dGhlIHNhbXBsZSBub25jZQ=="));
}
@Test
@ -115,7 +115,7 @@ public class WebSocketMessageD10Test
String data=message.toString();
_serverWebSocket.connection.sendMessage(data);
assertEquals(WebSocketConnectionD10.OP_TEXT,input.read());
assertEquals(WebSocketConnectionD11.OP_TEXT,input.read());
assertEquals(0x7e,input.read());
assertEquals(0x1f,input.read());
assertEquals(0xf6,input.read());
@ -321,7 +321,7 @@ public class WebSocketMessageD10Test
output.write(buf,0,l+3);
output.flush();
assertEquals(0x40+WebSocketConnectionD10.OP_TEXT,input.read());
assertEquals(0x40+WebSocketConnectionD11.OP_TEXT,input.read());
assertEquals(0x20+3,input.read());
assertEquals(0x7e,input.read());
assertEquals(0x02,input.read());
@ -489,7 +489,7 @@ public class WebSocketMessageD10Test
output.write(bytes[i]^0xff);
output.flush();
assertEquals(0x80|WebSocketConnectionD10.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionD11.OP_CLOSE,input.read());
assertEquals(30,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(1004,code);
@ -540,7 +540,7 @@ public class WebSocketMessageD10Test
assertEquals(0x80|WebSocketConnectionD10.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionD11.OP_CLOSE,input.read());
assertEquals(30,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(1004,code);
@ -576,7 +576,7 @@ public class WebSocketMessageD10Test
assertNotNull(_serverWebSocket.connection);
_serverWebSocket.getConnection().setMaxBinaryMessageSize(1024);
output.write(WebSocketConnectionD10.OP_BINARY);
output.write(WebSocketConnectionD11.OP_BINARY);
output.write(0x8a);
output.write(0xff);
output.write(0xff);
@ -597,7 +597,7 @@ public class WebSocketMessageD10Test
output.write(bytes[i]^0xff);
output.flush();
assertEquals(0x80+WebSocketConnectionD10.OP_BINARY,input.read());
assertEquals(0x80+WebSocketConnectionD11.OP_BINARY,input.read());
assertEquals(20,input.read());
lookFor("01234567890123456789",input);
}
@ -654,7 +654,7 @@ public class WebSocketMessageD10Test
output.flush();
assertEquals(0x80|WebSocketConnectionD10.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionD11.OP_CLOSE,input.read());
assertEquals(19,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(1004,code);
@ -703,7 +703,7 @@ public class WebSocketMessageD10Test
output.write(bytes[i]^0xff);
output.flush();
assertEquals(0x80|WebSocketConnectionD10.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionD11.OP_CLOSE,input.read());
assertEquals(19,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(1004,code);
@ -829,14 +829,14 @@ public class WebSocketMessageD10Test
final AtomicReference<String> received = new AtomicReference<String>();
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
WebSocketGeneratorD10 gen = new WebSocketGeneratorD10(new WebSocketBuffers(8096),endp,null);
WebSocketGeneratorD11 gen = new WebSocketGeneratorD11(new WebSocketBuffers(8096),endp,null);
byte[] data = message.getBytes(StringUtil.__UTF8);
gen.addFrame((byte)0x8,(byte)0x4,data,0,data.length);
endp = new ByteArrayEndPoint(endp.getOut().asArray(),4096);
WebSocketParserD10 parser = new WebSocketParserD10(new WebSocketBuffers(8096),endp,new WebSocketParser.FrameHandler()
WebSocketParserD11 parser = new WebSocketParserD11(new WebSocketBuffers(8096),endp,new WebSocketParser.FrameHandler()
{
public void onFrame(byte flags, byte opcode, Buffer buffer)
{
@ -861,15 +861,15 @@ public class WebSocketMessageD10Test
final AtomicReference<String> received = new AtomicReference<String>();
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
WebSocketGeneratorD10.MaskGen maskGen = new WebSocketGeneratorD10.RandomMaskGen();
WebSocketGeneratorD11.MaskGen maskGen = new WebSocketGeneratorD11.RandomMaskGen();
WebSocketGeneratorD10 gen = new WebSocketGeneratorD10(new WebSocketBuffers(8096),endp,maskGen);
WebSocketGeneratorD11 gen = new WebSocketGeneratorD11(new WebSocketBuffers(8096),endp,maskGen);
byte[] data = message.getBytes(StringUtil.__UTF8);
gen.addFrame((byte)0x8,(byte)0x1,data,0,data.length);
endp = new ByteArrayEndPoint(endp.getOut().asArray(),4096);
WebSocketParserD10 parser = new WebSocketParserD10(new WebSocketBuffers(8096),endp,new WebSocketParser.FrameHandler()
WebSocketParserD11 parser = new WebSocketParserD11(new WebSocketBuffers(8096),endp,new WebSocketParser.FrameHandler()
{
public void onFrame(byte flags, byte opcode, Buffer buffer)
{
@ -992,9 +992,9 @@ public class WebSocketMessageD10Test
{
switch(opcode)
{
case WebSocketConnectionD10.OP_CLOSE:
case WebSocketConnectionD10.OP_PING:
case WebSocketConnectionD10.OP_PONG:
case WebSocketConnectionD11.OP_CLOSE:
case WebSocketConnectionD11.OP_PING:
case WebSocketConnectionD11.OP_PONG:
break;
default:

View File

@ -20,11 +20,11 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketParserD10Test
public class WebSocketParserD11Test
{
private MaskedByteArrayBuffer _in;
private Handler _handler;
private WebSocketParserD10 _parser;
private WebSocketParserD11 _parser;
private byte[] _mask = new byte[] {(byte)0x00,(byte)0xF0,(byte)0x0F,(byte)0xFF};
private int _m;
@ -87,7 +87,7 @@ public class WebSocketParserD10Test
ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
endPoint.setNonBlocking(true);
_handler = new Handler();
_parser=new WebSocketParserD10(buffers, endPoint,_handler,true);
_parser=new WebSocketParserD11(buffers, endPoint,_handler,true);
_parser.setFakeFragments(false);
_in = new MaskedByteArrayBuffer();
@ -188,7 +188,7 @@ public class WebSocketParserD10Test
{
WebSocketBuffers buffers = new WebSocketBuffers(0x20000);
ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
WebSocketParser parser=new WebSocketParserD10(buffers, endPoint,_handler,false);
WebSocketParser parser=new WebSocketParserD11(buffers, endPoint,_handler,false);
ByteArrayBuffer in = new ByteArrayBuffer(0x20000);
endPoint.setIn(in);
@ -263,7 +263,7 @@ public class WebSocketParserD10Test
assertTrue(progress>0);
assertEquals(WebSocketConnectionD10.CLOSE_LARGE,_handler._code);
assertEquals(WebSocketConnectionD11.CLOSE_LARGE,_handler._code);
for (int i=0;i<2048;i++)
_in.put((byte)'a');
progress =_parser.parseNext();
@ -307,7 +307,7 @@ public class WebSocketParserD10Test
assertTrue(progress>0);
assertEquals(2,_handler._frames);
assertEquals(WebSocketConnectionD10.OP_CONTINUATION,_handler._opcode);
assertEquals(WebSocketConnectionD11.OP_CONTINUATION,_handler._opcode);
}
private class Handler implements WebSocketParser.FrameHandler