Merge branch 'jetty-9' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project into jetty-9

This commit is contained in:
Joakim Erdfelt 2012-06-19 11:14:05 -07:00
commit 114ff6878b
3 changed files with 32 additions and 46 deletions

View File

@ -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;
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}