empty frames with no constructor will generate correctly

This commit is contained in:
Jesse McConnell 2012-06-27 08:16:27 -05:00
parent 888314e08a
commit a0516774c0
4 changed files with 44 additions and 5 deletions

View File

@ -36,7 +36,7 @@ public class BaseFrame
private boolean rsv3 = false;
private OpCode opcode = null;
private boolean masked = false;
private int payloadLength;
private int payloadLength = 0;
private byte mask[];
private ByteBuffer payload = null;
@ -132,7 +132,7 @@ public class BaseFrame
rsv3 = false;
opcode = null;
masked = false;
payloadLength = -1;
payloadLength = 0;
mask = null;
}

View File

@ -19,11 +19,11 @@ public class PingFrame extends ControlFrame
}
/**
* Construct Ping Frame from known bytebuffer
* Construct Ping Frame from known byte[]
*
* @param payload
*/
public PingFrame(ByteBuffer payload)
public PingFrame(byte[] payload)
{
this();
setPayload(payload);

View File

@ -16,6 +16,9 @@ public class PingFrameGenerator extends FrameGenerator<PingFrame>
@Override
public void fillPayload(ByteBuffer buffer, PingFrame ping)
{
BufferUtil.put(ping.getPayload(),buffer);
if ( ping.hasPayload() )
{
BufferUtil.put(ping.getPayload(),buffer);
}
}
}

View File

@ -0,0 +1,36 @@
package org.eclipse.jetty.websocket.ab;
import java.nio.ByteBuffer;
import org.eclipse.jetty.websocket.ByteBufferAssert;
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.PingFrame;
import org.eclipse.jetty.websocket.generator.Generator;
import org.junit.Test;
public class ABCase2
{
@Test
public void testGenerateEmptyPingCase2_1()
{
PingFrame pingFrame = new PingFrame();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(32);
generator.generate(actual, pingFrame);
ByteBuffer expected = ByteBuffer.allocate(5);
expected.put(new byte[]
{ (byte)0x89, (byte)0x00 });
actual.flip();
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
}
}