move payload into control frame, not doing close frame's reason and status code since we can
't create bytebuffers in the frames atm
This commit is contained in:
parent
993c3788b9
commit
289fb7c395
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">Ping Frame (0x09)</a>.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">Pong Frame (0x0A)</a>.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue