diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java
index 6fb48df9deb..48dab02ad91 100644
--- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java
+++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java
@@ -1,9 +1,14 @@
package org.eclipse.jetty.websocket.frames;
+import java.nio.ByteBuffer;
+
import org.eclipse.jetty.websocket.api.OpCode;
+import org.eclipse.jetty.websocket.api.WebSocketException;
public abstract class ControlFrame extends BaseFrame
{
+ private ByteBuffer payload = null; // TODO decide if payload needs to go all the way down to baseframe
+
public ControlFrame()
{
super();
@@ -18,4 +23,27 @@ public abstract class ControlFrame extends BaseFrame
{
super(opcode);
}
+
+ public ByteBuffer getPayload()
+ {
+ return payload;
+ }
+
+ public void setPayload(ByteBuffer payload)
+ {
+ if ( payload.array().length >= 126 )
+ {
+ this.payload = payload;
+ setPayloadLength(payload.array().length);
+ }
+ else
+ {
+ throw new WebSocketException("too long, catch this better");
+ }
+ }
+
+ public boolean hasPayload()
+ {
+ return payload != null;
+ }
}
diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/PingFrame.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/PingFrame.java
index 5d87b9f9133..3fef0bf3ca9 100644
--- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/PingFrame.java
+++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/PingFrame.java
@@ -3,15 +3,12 @@ package org.eclipse.jetty.websocket.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.websocket.api.OpCode;
-import org.eclipse.jetty.websocket.api.WebSocketException;
/**
* Representation of a Ping Frame (0x09).
*/
public class PingFrame extends ControlFrame
{
- private ByteBuffer payload;
-
/**
* Default constructor
*/
@@ -37,27 +34,9 @@ public class PingFrame extends ControlFrame
return OpCode.PING;
}
- public ByteBuffer getPayload()
- {
- return payload;
- }
-
- public void setPayload(ByteBuffer payload)
- {
- if ( payload.array().length >= 126 )
- {
- this.payload = payload;
- setPayloadLength(payload.array().length);
- }
- else
- {
- throw new WebSocketException("too long, catch this better");
- }
- }
-
@Override
public String toString()
{
- return String.format("%s ping", super.toString());
+ return String.format("%s ping, payload=%s", super.toString(), hasPayload());
}
}
diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/PongFrame.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/PongFrame.java
index c4078e6f534..0046e3f56f9 100644
--- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/PongFrame.java
+++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/PongFrame.java
@@ -3,17 +3,14 @@ package org.eclipse.jetty.websocket.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.websocket.api.OpCode;
-import org.eclipse.jetty.websocket.api.WebSocketException;
/**
* Representation of a Pong Frame (0x0A).
*/
public class PongFrame extends ControlFrame
{
- private ByteBuffer payload;
-
/**
- * Default contructor
+ * Default constructor
*/
public PongFrame()
{
@@ -38,7 +35,7 @@ public class PongFrame extends ControlFrame
public PongFrame(PingFrame ping)
{
this();
- // TODO: set appropriate pong from ping frame payload + masking
+ setPayload(ping.getPayload());
}
@Override
@@ -47,27 +44,9 @@ public class PongFrame extends ControlFrame
return OpCode.PONG;
}
- public ByteBuffer getPayload()
- {
- return payload;
- }
-
- public void setPayload(ByteBuffer payload)
- {
- if (payload.array().length >= 126)
- {
- this.payload = payload;
- setPayloadLength(payload.array().length);
- }
- else
- {
- throw new WebSocketException("too long, catch this better");
- }
- }
-
@Override
public String toString()
{
- return String.format("%s pong",super.toString());
+ return String.format("%s pong, payload=%s",super.toString(), hasPayload());
}
}