Renaming .frames.BaseFrame to .protocols.WebSocketFrame

This commit is contained in:
Joakim Erdfelt 2012-07-06 11:33:26 -07:00
parent dfc9315bc7
commit c2872ff556
22 changed files with 125 additions and 128 deletions

View File

@ -7,17 +7,17 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
/**
* (ADVANCED) Annotation for tagging methods to receive frame events.
* <p>
* Note: any frame derived from {@link BaseFrame} is acceptable to use as the last parameter here.
* Note: any frame derived from {@link WebSocketFrame} is acceptable to use as the last parameter here.
* <p>
* Acceptable method patterns.<br>
* Note: <code>methodName</code> can be any name you want to use.
* <ol>
* <li><code>public void methodName({@link BaseFrame} frame)</code></li>
* <li><code>public void methodName({@link WebSocketFrame} frame)</code></li>
* <li><code>public void methodName(BinaryFrame frame)</code></li>
* <li><code>public void methodName(CloseFrame frame)</code></li>
* <li><code>public void methodName(ControlFrame frame)</code></li>
@ -25,7 +25,7 @@ import org.eclipse.jetty.websocket.frames.BaseFrame;
* <li><code>public void methodName(PingFrame frame)</code></li>
* <li><code>public void methodName(PongFrame frame)</code></li>
* <li><code>public void methodName(TextFrame frame)</code></li>
* <li><code>public void methodName({@link WebSocketConnection} conn, {@link BaseFrame} frame)</code></li>
* <li><code>public void methodName({@link WebSocketConnection} conn, {@link WebSocketFrame} frame)</code></li>
* <li><code>public void methodName({@link WebSocketConnection} conn, BinaryFrame frame)</code></li>
* <li><code>public void methodName({@link WebSocketConnection} conn, CloseFrame frame)</code></li>
* <li><code>public void methodName({@link WebSocketConnection} conn, ControlFrame frame)</code></li>

View File

@ -8,10 +8,10 @@ import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.generator.Generator;
import org.eclipse.jetty.websocket.io.RawConnection;
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
/**
* For working with the {@link WebSocketConnection} in a blocking technique.
@ -47,7 +47,7 @@ public class WebSocketBlockingConnection
*/
public void write(byte[] data, int offset, int length) throws IOException
{
BaseFrame frame = FrameBuilder.binary(data,offset,length).asFrame();
WebSocketFrame frame = FrameBuilder.binary(data,offset,length).asFrame();
ByteBuffer buf = bufferPool.acquire(policy.getBufferSize(),false);
try
{
@ -77,7 +77,7 @@ public class WebSocketBlockingConnection
*/
public void write(String message) throws IOException
{
BaseFrame frame = FrameBuilder.text(message).asFrame();
WebSocketFrame frame = FrameBuilder.text(message).asFrame();
ByteBuffer buf = bufferPool.acquire(policy.getBufferSize(),false);
try
{

View File

@ -8,10 +8,10 @@ import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.generator.Generator;
import org.eclipse.jetty.websocket.io.RawConnection;
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
public class WebSocketPing
{
@ -37,7 +37,7 @@ public class WebSocketPing
public void sendPing(byte data[]) throws IOException
{
BaseFrame frame = FrameBuilder.ping().payload(data).asFrame();
WebSocketFrame frame = FrameBuilder.ping().payload(data).asFrame();
ByteBuffer buf = bufferPool.acquire(policy.getBufferSize(),false);
try
{

View File

@ -15,12 +15,12 @@ import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.io.MessageInputStream;
import org.eclipse.jetty.websocket.io.MessageReader;
import org.eclipse.jetty.websocket.io.StreamAppender;
import org.eclipse.jetty.websocket.parser.Parser;
import org.eclipse.jetty.websocket.protocol.Frame;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.util.CloseUtil;
/**
@ -108,7 +108,7 @@ public class WebSocketEventDriver implements Parser.Listener
* the frame that appeared
*/
@Override
public void onFrame(BaseFrame frame)
public void onFrame(WebSocketFrame frame)
{
if (LOG.isDebugEnabled())
{
@ -312,9 +312,9 @@ public class WebSocketEventDriver implements Parser.Listener
if (StringUtil.isNotBlank(reason))
{
// Trim big exception messages here.
if (reason.length() > (BaseFrame.MAX_CONTROL_PAYLOAD - 2))
if (reason.length() > (WebSocketFrame.MAX_CONTROL_PAYLOAD - 2))
{
reason = reason.substring(0,BaseFrame.MAX_CONTROL_PAYLOAD - 2);
reason = reason.substring(0,WebSocketFrame.MAX_CONTROL_PAYLOAD - 2);
}
}
LOG.debug("terminateConnection({},{})",statusCode,rawreason);

View File

@ -3,7 +3,7 @@ package org.eclipse.jetty.websocket.generator;
import java.nio.ByteBuffer;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.util.CloseUtil;
public class CloseFrameGenerator extends FrameGenerator
@ -14,7 +14,7 @@ public class CloseFrameGenerator extends FrameGenerator
}
@Override
public void fillPayload(ByteBuffer buffer, BaseFrame close)
public void fillPayload(ByteBuffer buffer, WebSocketFrame close)
{
CloseUtil.assertValidPayload(close.getPayload());
super.fillPayload(buffer,close);

View File

@ -7,8 +7,8 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.PolicyViolationException;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.protocol.OpCode;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
/**
* <pre>
@ -49,12 +49,12 @@ public class FrameGenerator
this.policy = policy;
}
public void fillPayload(ByteBuffer buffer, BaseFrame frame)
public void fillPayload(ByteBuffer buffer, WebSocketFrame frame)
{
BufferUtil.put(frame.getPayload(),buffer);
}
public ByteBuffer generate(ByteBuffer buffer, BaseFrame frame)
public ByteBuffer generate(ByteBuffer buffer, WebSocketFrame frame)
{
LOG.debug(String.format("Generate.Frame[opcode=%s,fin=%b,cont=%b,rsv1=%b,rsv2=%b,rsv3=%b,mask=%b,plength=%d]",frame.getOpCode().toString(),
frame.isFin(),frame.isContinuation(),frame.isRsv1(),frame.isRsv2(),frame.isRsv3(),frame.isMasked(),frame.getPayloadLength()));

View File

@ -7,8 +7,8 @@ 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.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.protocol.OpCode;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
/**
* Generating a frame in WebSocket land.
@ -47,7 +47,7 @@ public class Generator
basicGenerator = new FrameGenerator(policy);
}
public ByteBuffer generate(ByteBuffer buffer, BaseFrame frame)
public ByteBuffer generate(ByteBuffer buffer, WebSocketFrame frame)
{
if (LOG.isDebugEnabled())
{

View File

@ -20,12 +20,12 @@ import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.callbacks.WebSocketCloseCallback;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.generator.FrameGenerator;
import org.eclipse.jetty.websocket.generator.Generator;
import org.eclipse.jetty.websocket.parser.Parser;
import org.eclipse.jetty.websocket.protocol.ExtensionConfig;
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
/**
* Provides the implementation of {@link WebSocketConnection} within the framework of the new {@link AsyncConnection} framework of jetty-io
@ -220,7 +220,7 @@ public class WebSocketAsyncConnection extends AbstractAsyncConnection implements
*/
private void terminateConnection(int statusCode, String reason)
{
BaseFrame close = FrameBuilder.close(statusCode,reason).asFrame();
WebSocketFrame close = FrameBuilder.close(statusCode,reason).asFrame();
// fire and forget -> close frame
ByteBuffer buf = bufferPool.acquire(policy.getBufferSize(),false);
@ -254,7 +254,7 @@ public class WebSocketAsyncConnection extends AbstractAsyncConnection implements
ByteBuffer raw = bufferPool.acquire(len + FrameGenerator.OVERHEAD,false);
BufferUtil.clearToFill(raw);
BaseFrame frame = FrameBuilder.binary(buf,offset,len).fin(true).asFrame();
WebSocketFrame frame = FrameBuilder.binary(buf,offset,len).fin(true).asFrame();
generator.generate(raw,frame);
BufferUtil.flipToFlush(raw,0);
writeRaw(context,callback,raw);
@ -279,7 +279,7 @@ public class WebSocketAsyncConnection extends AbstractAsyncConnection implements
ByteBuffer raw[] = new ByteBuffer[messages.length];
for (int i = 0; i < len; i++)
{
BaseFrame frame = FrameBuilder.text(messages[i]).fin(true).asFrame();
WebSocketFrame frame = FrameBuilder.text(messages[i]).fin(true).asFrame();
raw[i] = bufferPool.acquire(policy.getBufferSize(),false);
BufferUtil.clearToFill(raw[i]);

View File

@ -5,8 +5,8 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.protocol.OpCode;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
/**
* Base Framing Protocol handling
@ -50,7 +50,7 @@ public class FrameParser
private long length = 0;
private int cursor = 0;
// Frame
private BaseFrame frame;
private WebSocketFrame frame;
// payload specific
private ByteBuffer payload;
private int payloadLength;
@ -99,7 +99,7 @@ public class FrameParser
*
* @return the frame that is being parsed. should always return an object (never null)
*/
public BaseFrame getFrame()
public WebSocketFrame getFrame()
{
return frame;
}
@ -120,7 +120,7 @@ public class FrameParser
*/
public final void initFrame(boolean fin, boolean rsv1, boolean rsv2, boolean rsv3, OpCode opcode)
{
BaseFrame frame = new BaseFrame();
WebSocketFrame frame = new WebSocketFrame();
frame.setFin(fin);
frame.setRsv1(rsv1);
frame.setRsv2(rsv2);

View File

@ -10,8 +10,8 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.ProtocolException;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.protocol.OpCode;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.util.CloseUtil;
/**
@ -21,7 +21,7 @@ public class Parser
{
public interface Listener extends EventListener
{
public void onFrame(final BaseFrame frame);
public void onFrame(final WebSocketFrame frame);
public void onWebSocketException(WebSocketException e);
}
@ -66,7 +66,7 @@ public class Parser
return policy;
}
protected void notifyFrame(final BaseFrame f)
protected void notifyFrame(final WebSocketFrame f)
{
LOG.debug("Notify Frame: {}",f);
for (Listener listener : listeners)

View File

@ -5,24 +5,23 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.api.PolicyViolationException;
import org.eclipse.jetty.websocket.frames.BaseFrame;
public class FrameBuilder
{
public static FrameBuilder binary()
{
return new FrameBuilder(new BaseFrame(OpCode.BINARY));
return new FrameBuilder(new WebSocketFrame(OpCode.BINARY));
}
public static FrameBuilder binary(byte[] payload)
{
return new FrameBuilder(new BaseFrame(OpCode.BINARY)).payload(payload);
return new FrameBuilder(new WebSocketFrame(OpCode.BINARY)).payload(payload);
}
public static FrameBuilder binary(byte[] payload, int offset, int length)
{
return new FrameBuilder(new BaseFrame(OpCode.BINARY)).payload(payload,offset,length);
return new FrameBuilder(new WebSocketFrame(OpCode.BINARY)).payload(payload,offset,length);
}
public static FrameBuilder close()
@ -39,56 +38,56 @@ public class FrameBuilder
{
if (statusCode != (-1))
{
ByteBuffer buf = ByteBuffer.allocate(BaseFrame.MAX_CONTROL_PAYLOAD);
ByteBuffer buf = ByteBuffer.allocate(WebSocketFrame.MAX_CONTROL_PAYLOAD);
buf.putChar((char)statusCode);
if (StringUtil.isNotBlank(reason))
{
byte utf[] = StringUtil.getUtf8Bytes(reason);
buf.put(utf,0,utf.length);
}
return new FrameBuilder(new BaseFrame(OpCode.CLOSE)).payload(buf);
return new FrameBuilder(new WebSocketFrame(OpCode.CLOSE)).payload(buf);
}
return new FrameBuilder(new BaseFrame(OpCode.CLOSE));
return new FrameBuilder(new WebSocketFrame(OpCode.CLOSE));
}
public static FrameBuilder continuation()
{
return new FrameBuilder(new BaseFrame(OpCode.CONTINUATION));
return new FrameBuilder(new WebSocketFrame(OpCode.CONTINUATION));
}
public static FrameBuilder continuation(byte[] payload)
{
return new FrameBuilder(new BaseFrame(OpCode.CONTINUATION)).payload(payload);
return new FrameBuilder(new WebSocketFrame(OpCode.CONTINUATION)).payload(payload);
}
public static FrameBuilder continuation(String payload)
{
return new FrameBuilder(new BaseFrame(OpCode.CONTINUATION)).payload(payload);
return new FrameBuilder(new WebSocketFrame(OpCode.CONTINUATION)).payload(payload);
}
public static FrameBuilder ping()
{
return new FrameBuilder(new BaseFrame(OpCode.PING));
return new FrameBuilder(new WebSocketFrame(OpCode.PING));
}
public static FrameBuilder pong()
{
return new FrameBuilder(new BaseFrame(OpCode.PONG));
return new FrameBuilder(new WebSocketFrame(OpCode.PONG));
}
public static FrameBuilder text()
{
return new FrameBuilder(new BaseFrame(OpCode.TEXT));
return new FrameBuilder(new WebSocketFrame(OpCode.TEXT));
}
public static FrameBuilder text(String text)
{
return new FrameBuilder(new BaseFrame(OpCode.TEXT)).payload(text.getBytes());
return new FrameBuilder(new WebSocketFrame(OpCode.TEXT)).payload(text.getBytes());
}
private BaseFrame frame;
private WebSocketFrame frame;
public FrameBuilder(BaseFrame frame)
public FrameBuilder(WebSocketFrame frame)
{
this.frame = frame;
this.frame.setFin(true); // default
@ -106,7 +105,7 @@ public class FrameBuilder
return buffer;
}
public BaseFrame asFrame()
public WebSocketFrame asFrame()
{
return frame;
}

View File

@ -1,12 +1,10 @@
package org.eclipse.jetty.websocket.frames;
package org.eclipse.jetty.websocket.protocol;
import java.nio.ByteBuffer;
import javax.xml.ws.ProtocolException;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.protocol.Frame;
import org.eclipse.jetty.websocket.protocol.OpCode;
/**
* A Base Frame as seen in <a href="https://tools.ietf.org/html/rfc6455#section-5.2">RFC 6455. Sec 5.2</a>
@ -32,7 +30,7 @@ import org.eclipse.jetty.websocket.protocol.OpCode;
* +---------------------------------------------------------------+
* </pre>
*/
public class BaseFrame implements Frame
public class WebSocketFrame implements Frame
{
/** Maximum size of Control frame, per RFC 6455 */
public static final int MAX_CONTROL_PAYLOAD = 125;
@ -53,7 +51,7 @@ public class BaseFrame implements Frame
/**
* Default constructor
*/
public BaseFrame()
public WebSocketFrame()
{
reset();
}
@ -61,7 +59,7 @@ public class BaseFrame implements Frame
/**
* Construct form opcode
*/
public BaseFrame(OpCode opcode)
public WebSocketFrame(OpCode opcode)
{
reset();
this.opcode = opcode;
@ -71,7 +69,7 @@ public class BaseFrame implements Frame
{
if (opcode.isControlFrame())
{
if (payloadLength > BaseFrame.MAX_CONTROL_PAYLOAD)
if (payloadLength > WebSocketFrame.MAX_CONTROL_PAYLOAD)
{
throw new ProtocolException("Desired payload length [" + payloadLength + "] exceeds maximum control payload length [" + MAX_CONTROL_PAYLOAD
+ "]");
@ -105,7 +103,7 @@ public class BaseFrame implements Frame
}
@Override
public BaseFrame clone()
public WebSocketFrame clone()
{
// TODO: impl
return null;
@ -263,7 +261,7 @@ public class BaseFrame implements Frame
{
if (opcode.isControlFrame())
{
if (buf.length > BaseFrame.MAX_CONTROL_PAYLOAD)
if (buf.length > WebSocketFrame.MAX_CONTROL_PAYLOAD)
{
throw new ProtocolException("Control Payloads can not exceed 125 bytes in length.");
}
@ -285,7 +283,7 @@ public class BaseFrame implements Frame
{
if (opcode.isControlFrame())
{
if (len > BaseFrame.MAX_CONTROL_PAYLOAD)
if (len > WebSocketFrame.MAX_CONTROL_PAYLOAD)
{
throw new ProtocolException("Control Payloads can not exceed 125 bytes in length.");
}
@ -307,7 +305,7 @@ public class BaseFrame implements Frame
{
if (opcode.isControlFrame())
{
if (payload.position() > BaseFrame.MAX_CONTROL_PAYLOAD)
if (payload.position() > WebSocketFrame.MAX_CONTROL_PAYLOAD)
{
throw new ProtocolException("Control Payloads can not exceed 125 bytes in length.");
}

View File

@ -7,12 +7,12 @@ 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.BaseFrame;
import org.eclipse.jetty.websocket.frames.DataFrame.TextFrame;
import org.eclipse.jetty.websocket.generator.Generator;
import org.eclipse.jetty.websocket.parser.FrameParseCapture;
import org.eclipse.jetty.websocket.parser.Parser;
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.junit.Assert;
import org.junit.Test;
@ -35,7 +35,7 @@ public class TestABCase1_1
builder.append("*");
}
BaseFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
WebSocketFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(length + 16);
@ -74,7 +74,7 @@ public class TestABCase1_1
builder.append("*");
}
BaseFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
WebSocketFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(length + 16);
@ -117,7 +117,7 @@ public class TestABCase1_1
builder.append("*");
}
BaseFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
WebSocketFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(length + 16);
@ -160,7 +160,7 @@ public class TestABCase1_1
builder.append("*");
}
BaseFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
WebSocketFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(length + 16);
@ -203,7 +203,7 @@ public class TestABCase1_1
builder.append("*");
}
BaseFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
WebSocketFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(length + 16);
@ -244,7 +244,7 @@ public class TestABCase1_1
builder.append("*");
}
BaseFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
WebSocketFrame textFrame = FrameBuilder.text(builder.toString()).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(length + 16);

View File

@ -8,12 +8,12 @@ import org.eclipse.jetty.util.BufferUtil;
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.BaseFrame;
import org.eclipse.jetty.websocket.frames.DataFrame.BinaryFrame;
import org.eclipse.jetty.websocket.generator.Generator;
import org.eclipse.jetty.websocket.parser.FrameParseCapture;
import org.eclipse.jetty.websocket.parser.Parser;
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.junit.Assert;
import org.junit.Test;
@ -38,7 +38,7 @@ public class TestABCase1_2
bb.flip();
BaseFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
WebSocketFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
Generator generator = new Generator(policy);
@ -81,7 +81,7 @@ public class TestABCase1_2
bb.flip();
BaseFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
WebSocketFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
Generator generator = new Generator(policy);
@ -129,7 +129,7 @@ public class TestABCase1_2
bb.flip();
BaseFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
WebSocketFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
Generator generator = new Generator(policy);
@ -175,7 +175,7 @@ public class TestABCase1_2
}
bb.flip();
BaseFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
WebSocketFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(length + 11);
@ -221,7 +221,7 @@ public class TestABCase1_2
bb.flip();
BaseFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
WebSocketFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(length + 11);
@ -264,7 +264,7 @@ public class TestABCase1_2
bb.flip();
BaseFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
WebSocketFrame binaryFrame = FrameBuilder.binary(BufferUtil.toArray(bb)).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(length + 32);
@ -296,7 +296,7 @@ public class TestABCase1_2
@Test
public void testGenerateEmptyBinaryCase1_2_1()
{
BaseFrame binaryFrame = FrameBuilder.binary(new byte[] {}).asFrame();
WebSocketFrame binaryFrame = FrameBuilder.binary(new byte[] {}).asFrame();
Generator generator = new Generator(policy);
ByteBuffer actual = ByteBuffer.allocate(32);

View File

@ -7,10 +7,10 @@ import org.eclipse.jetty.util.StringUtil;
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.BaseFrame;
import org.eclipse.jetty.websocket.frames.PingFrame;
import org.eclipse.jetty.websocket.frames.PongFrame;
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.junit.Test;
public class RFC6455ExamplesGeneratorTest
@ -19,8 +19,8 @@ public class RFC6455ExamplesGeneratorTest
public void testFragmentedUnmaskedTextMessage()
{
BaseFrame text1 = FrameBuilder.text("Hel").fin(false).asFrame();
BaseFrame text2 = FrameBuilder.continuation("lo").asFrame();
WebSocketFrame text1 = FrameBuilder.text("Hel").fin(false).asFrame();
WebSocketFrame text2 = FrameBuilder.continuation("lo").asFrame();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
@ -83,7 +83,7 @@ public class RFC6455ExamplesGeneratorTest
@Test
public void testSingleMaskedTextMessage()
{
BaseFrame text = FrameBuilder.text("Hello").mask(new byte[]
WebSocketFrame text = FrameBuilder.text("Hello").mask(new byte[]
{ 0x37, (byte)0xfa, 0x21, 0x3d }).asFrame();
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
@ -112,7 +112,7 @@ public class RFC6455ExamplesGeneratorTest
{
int dataSize = 256;
BaseFrame binary = FrameBuilder.binary().asFrame();
WebSocketFrame binary = FrameBuilder.binary().asFrame();
ByteBuffer payload = ByteBuffer.allocate(dataSize);
for (int i = 0; i < dataSize; i++)
{
@ -149,7 +149,7 @@ public class RFC6455ExamplesGeneratorTest
{
int dataSize = 1024 * 64;
BaseFrame binary = FrameBuilder.binary().asFrame();
WebSocketFrame binary = FrameBuilder.binary().asFrame();
ByteBuffer payload = ByteBuffer.allocate(dataSize);
for (int i = 0; i < dataSize; i++)
{
@ -223,7 +223,7 @@ public class RFC6455ExamplesGeneratorTest
@Test
public void testSingleUnmaskedTextMessage()
{
BaseFrame text = FrameBuilder.text("Hello").asFrame();
WebSocketFrame text = FrameBuilder.text("Hello").asFrame();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);

View File

@ -8,13 +8,13 @@ import java.util.List;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.junit.Assert;
public class FrameParseCapture implements Parser.Listener
{
private static final Logger LOG = Log.getLogger(FrameParseCapture.class);
private List<BaseFrame> frames = new ArrayList<>();
private List<WebSocketFrame> frames = new ArrayList<>();
private List<WebSocketException> errors = new ArrayList<>();
public void assertHasErrors(Class<? extends WebSocketException> errorType, int expectedCount)
@ -22,12 +22,12 @@ public class FrameParseCapture implements Parser.Listener
Assert.assertThat(errorType.getSimpleName(),getErrorCount(errorType),is(expectedCount));
}
public void assertHasFrame(Class<? extends BaseFrame> frameType)
public void assertHasFrame(Class<? extends WebSocketFrame> frameType)
{
Assert.assertThat(frameType.getSimpleName(),getFrameCount(frameType),greaterThanOrEqualTo(1));
}
public void assertHasFrame(Class<? extends BaseFrame> frameType, int expectedCount)
public void assertHasFrame(Class<? extends WebSocketFrame> frameType, int expectedCount)
{
Assert.assertThat(frameType.getSimpleName(),getFrameCount(frameType),is(expectedCount));
}
@ -59,10 +59,10 @@ public class FrameParseCapture implements Parser.Listener
return errors;
}
public int getFrameCount(Class<? extends BaseFrame> frameType)
public int getFrameCount(Class<? extends WebSocketFrame> frameType)
{
int count = 0;
for(BaseFrame frame: frames) {
for(WebSocketFrame frame: frames) {
if (frameType.isInstance(frame))
{
count++;
@ -71,13 +71,13 @@ public class FrameParseCapture implements Parser.Listener
return count;
}
public List<BaseFrame> getFrames()
public List<WebSocketFrame> getFrames()
{
return frames;
}
@Override
public void onFrame(BaseFrame frame)
public void onFrame(WebSocketFrame frame)
{
frames.add(frame);
}

View File

@ -40,10 +40,10 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
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.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.TextFrame;
import org.eclipse.jetty.websocket.generator.Generator;
import org.eclipse.jetty.websocket.parser.Parser;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.server.examples.MyEchoSocket;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -71,7 +71,7 @@ public class WebSocketLoadRFC6455Test
*/
@Override
public void onFrame(BaseFrame frame)
public void onFrame(WebSocketFrame frame)
{
// TODO Auto-generated method stub
}

View File

@ -15,10 +15,10 @@ import org.eclipse.jetty.websocket.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.BinaryFrame;
import org.eclipse.jetty.websocket.frames.CloseFrame;
import org.eclipse.jetty.websocket.frames.TextFrame;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.junit.AfterClass;
import org.junit.Assert;
@ -154,7 +154,7 @@ public class WebSocketServletRFCTest
client.write(bin); // write buf3 (fin=true)
// Read frame echo'd back (hopefully a single binary frame)
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,1000);
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,1000);
BinaryFrame binmsg = (BinaryFrame)frames.remove();
int expectedSize = buf1.length + buf2.length + buf3.length;
Assert.assertThat("BinaryFrame.payloadLength",binmsg.getPayloadLength(),is(expectedSize));
@ -209,7 +209,7 @@ public class WebSocketServletRFCTest
client.write(frame);
// Read frame (hopefully text frame)
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
TextFrame tf = (TextFrame)frames.remove();
Assert.assertThat("Text Frame.status code",tf.getPayloadUTF8(),is("Hello World"));
}
@ -239,7 +239,7 @@ public class WebSocketServletRFCTest
client.write(frame);
// Read frame (hopefully close frame)
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
CloseFrame cf = (CloseFrame)frames.remove();
Assert.assertThat("Close Frame.status code",cf.getStatusCode(),is(StatusCode.SERVER_ERROR));
}

View File

@ -12,13 +12,13 @@ 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.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.CloseFrame;
import org.eclipse.jetty.websocket.frames.DataFrame.TextFrame;
import org.eclipse.jetty.websocket.frames.PongFrame;
import org.eclipse.jetty.websocket.generator.FrameGenerator;
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
import org.eclipse.jetty.websocket.protocol.OpCode;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.server.ByteBufferAssert;
import org.eclipse.jetty.websocket.server.SimpleServletServer;
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
@ -126,8 +126,8 @@ public class TestABCase5
client.writeRaw(buf2);
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
WebSocketFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);
@ -159,8 +159,8 @@ public class TestABCase5
client.writeRaw(frame2);
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
WebSocketFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);
@ -212,8 +212,8 @@ public class TestABCase5
client.writeRaw(buf2);
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
WebSocketFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);
@ -249,8 +249,8 @@ public class TestABCase5
client.writeRaw(frame2);
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
WebSocketFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);
@ -303,8 +303,8 @@ public class TestABCase5
client.writeRaw(buf2);
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
WebSocketFrame frame = frames.remove();
Assert.assertTrue("frame should be text frame",frame instanceof TextFrame);
@ -378,8 +378,8 @@ public class TestABCase5
client.writeRaw(buf2);
// Should be 2 frames, pong frame followed by combined echo'd text frame
Queue<BaseFrame> frames = client.readFrames(2,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Queue<WebSocketFrame> frames = client.readFrames(2,TimeUnit.MILLISECONDS,500);
WebSocketFrame frame = frames.remove();
Assert.assertTrue("first frame should be pong frame",frame instanceof PongFrame);
@ -435,8 +435,8 @@ public class TestABCase5
client.writeRaw(frame3);
// Should be 2 frames, pong frame followed by combined echo'd text frame
Queue<BaseFrame> frames = client.readFrames(2,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Queue<WebSocketFrame> frames = client.readFrames(2,TimeUnit.MILLISECONDS,500);
WebSocketFrame frame = frames.remove();
Assert.assertTrue("first frame should be pong frame",frame instanceof PongFrame);
@ -488,8 +488,8 @@ public class TestABCase5
client.writeRaw(buf);
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
WebSocketFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);

View File

@ -15,11 +15,11 @@ 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.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.CloseFrame;
import org.eclipse.jetty.websocket.generator.FrameGenerator;
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
import org.eclipse.jetty.websocket.protocol.OpCode;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.eclipse.jetty.websocket.server.SimpleServletServer;
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
import org.eclipse.jetty.websocket.server.WebSocketServlet;
@ -160,7 +160,7 @@ public class TestABCase7_9
client.writeRaw(buf);
// Read frame (hopefully text frame)
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
CloseFrame closeFrame = (CloseFrame)frames.remove();
Assert.assertThat("CloseFrame.status code",closeFrame.getStatusCode(),is(1002));
}
@ -202,7 +202,7 @@ public class TestABCase7_9
client.writeRaw(buf);
// Read frame (hopefully text frame)
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
Queue<WebSocketFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
CloseFrame closeFrame = (CloseFrame)frames.remove();
Assert.assertThat("CloseFrame.status code",closeFrame.getStatusCode(),is(1002));
}

View File

@ -32,9 +32,9 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.generator.Generator;
import org.eclipse.jetty.websocket.parser.Parser;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.junit.Assert;
/**
@ -56,7 +56,7 @@ public class BlockheadClient implements Parser.Listener
private final WebSocketPolicy policy;
private final Generator generator;
private final Parser parser;
private final LinkedBlockingDeque<BaseFrame> incomingFrameQueue;
private final LinkedBlockingDeque<WebSocketFrame> incomingFrameQueue;
private Socket socket;
private OutputStream out;
@ -176,7 +176,7 @@ public class BlockheadClient implements Parser.Listener
}
@Override
public void onFrame(BaseFrame frame)
public void onFrame(WebSocketFrame frame)
{
LOG.debug("onFrame({})",frame);
if (!incomingFrameQueue.offerLast(frame))
@ -202,7 +202,7 @@ public class BlockheadClient implements Parser.Listener
return len;
}
public Queue<BaseFrame> readFrames(int expectedCount, TimeUnit timeoutUnit, int timeoutDuration) throws IOException, TimeoutException
public Queue<WebSocketFrame> readFrames(int expectedCount, TimeUnit timeoutUnit, int timeoutDuration) throws IOException, TimeoutException
{
int startCount = incomingFrameQueue.size();
@ -336,7 +336,7 @@ public class BlockheadClient implements Parser.Listener
}
}
public void write(BaseFrame frame) throws IOException
public void write(WebSocketFrame frame) throws IOException
{
LOG.debug("write(BaseFrame->{})",frame);
ByteBuffer buf = bufferPool.acquire(policy.getBufferSize(),false);

View File

@ -8,14 +8,14 @@ import java.util.List;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.parser.Parser;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.junit.Assert;
public class FrameParseCapture implements Parser.Listener
{
private static final Logger LOG = Log.getLogger(FrameParseCapture.class);
private List<BaseFrame> frames = new ArrayList<>();
private List<WebSocketFrame> frames = new ArrayList<>();
private List<WebSocketException> errors = new ArrayList<>();
public void assertHasErrors(Class<? extends WebSocketException> errorType, int expectedCount)
@ -23,12 +23,12 @@ public class FrameParseCapture implements Parser.Listener
Assert.assertThat(errorType.getSimpleName(),getErrorCount(errorType),is(expectedCount));
}
public void assertHasFrame(Class<? extends BaseFrame> frameType)
public void assertHasFrame(Class<? extends WebSocketFrame> frameType)
{
Assert.assertThat(frameType.getSimpleName(),getFrameCount(frameType),greaterThanOrEqualTo(1));
}
public void assertHasFrame(Class<? extends BaseFrame> frameType, int expectedCount)
public void assertHasFrame(Class<? extends WebSocketFrame> frameType, int expectedCount)
{
Assert.assertThat(frameType.getSimpleName(),getFrameCount(frameType),is(expectedCount));
}
@ -61,10 +61,10 @@ public class FrameParseCapture implements Parser.Listener
return errors;
}
public int getFrameCount(Class<? extends BaseFrame> frameType)
public int getFrameCount(Class<? extends WebSocketFrame> frameType)
{
int count = 0;
for (BaseFrame frame : frames)
for (WebSocketFrame frame : frames)
{
if (frameType.isInstance(frame))
{
@ -74,13 +74,13 @@ public class FrameParseCapture implements Parser.Listener
return count;
}
public List<BaseFrame> getFrames()
public List<WebSocketFrame> getFrames()
{
return frames;
}
@Override
public void onFrame(BaseFrame frame)
public void onFrame(WebSocketFrame frame)
{
frames.add(frame);
}