Refactoring WebSocketSettings to WebSocketPolicy to better conform to naming in use within RFC 6455 spec (discussed with jesse over phone)
This commit is contained in:
parent
d675be84ba
commit
2e6c307adc
|
@ -0,0 +1,31 @@
|
|||
package org.eclipse.jetty.websocket.api;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class CloseException extends WebSocketException
|
||||
{
|
||||
private short closeCode;
|
||||
|
||||
public CloseException(short closeCode, String message)
|
||||
{
|
||||
super(message);
|
||||
this.closeCode = closeCode;
|
||||
}
|
||||
|
||||
public CloseException(short closeCode, String message, Throwable cause)
|
||||
{
|
||||
super(message,cause);
|
||||
this.closeCode = closeCode;
|
||||
}
|
||||
|
||||
public CloseException(short closeCode, Throwable cause)
|
||||
{
|
||||
super(cause);
|
||||
this.closeCode = closeCode;
|
||||
}
|
||||
|
||||
public short getCloseCode()
|
||||
{
|
||||
return closeCode;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.eclipse.jetty.websocket.api;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PolicyViolationException extends CloseException
|
||||
{
|
||||
public PolicyViolationException(String message)
|
||||
{
|
||||
super(WebSocket.CLOSE_POLICY_VIOLATION,message);
|
||||
}
|
||||
|
||||
public PolicyViolationException(String message, Throwable t)
|
||||
{
|
||||
super(WebSocket.CLOSE_POLICY_VIOLATION,message,t);
|
||||
}
|
||||
|
||||
public PolicyViolationException(Throwable t)
|
||||
{
|
||||
super(WebSocket.CLOSE_POLICY_VIOLATION,t);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package org.eclipse.jetty.websocket.api;
|
||||
|
||||
/**
|
||||
* Behavior for how the WebSocket should operate.
|
||||
* <p>
|
||||
* This dictated by the <a href="https://tools.ietf.org/html/rfc6455">RFC 6455</a> spec in various places, where certain behavior must be performed depending on
|
||||
* operation as a <a href="https://tools.ietf.org/html/rfc6455#section-4.1">CLIENT</a> vs a <a href="https://tools.ietf.org/html/rfc6455#section-4.2">SERVER</a>
|
||||
*/
|
||||
public enum WebSocketBehavior
|
||||
{
|
||||
CLIENT,
|
||||
SERVER;
|
||||
}
|
|
@ -5,7 +5,7 @@ import org.eclipse.jetty.websocket.masks.Masker;
|
|||
/**
|
||||
* Settings for WebSocket operations.
|
||||
*/
|
||||
public class WebSocketSettings
|
||||
public class WebSocketPolicy
|
||||
{
|
||||
/**
|
||||
* The maximum size of a text message during parsing/generating
|
||||
|
@ -20,7 +20,22 @@ public class WebSocketSettings
|
|||
* The implementation for masking
|
||||
*/
|
||||
private Masker masker = null;
|
||||
|
||||
|
||||
/**
|
||||
* Behavior of the websockets
|
||||
*/
|
||||
private WebSocketBehavior behavior = WebSocketBehavior.SERVER; // TODO: Review default
|
||||
|
||||
public WebSocketBehavior getBehavior()
|
||||
{
|
||||
return behavior;
|
||||
}
|
||||
|
||||
public Masker getMasker()
|
||||
{
|
||||
return masker;
|
||||
}
|
||||
|
||||
public int getMaxBinaryMessageSize()
|
||||
{
|
||||
return maxBinaryMessageSize;
|
||||
|
@ -31,6 +46,16 @@ public class WebSocketSettings
|
|||
return maxTextMessageSize;
|
||||
}
|
||||
|
||||
public void setBehavior(WebSocketBehavior behavior)
|
||||
{
|
||||
this.behavior = behavior;
|
||||
}
|
||||
|
||||
public void setMasker(Masker masker)
|
||||
{
|
||||
this.masker = masker;
|
||||
}
|
||||
|
||||
public void setMaxBinaryMessageSize(int maxBinaryMessageSize)
|
||||
{
|
||||
this.maxBinaryMessageSize = maxBinaryMessageSize;
|
||||
|
@ -41,14 +66,4 @@ public class WebSocketSettings
|
|||
this.maxTextMessageSize = maxTextMessageSize;
|
||||
}
|
||||
|
||||
public Masker getMaskGen()
|
||||
{
|
||||
return masker;
|
||||
}
|
||||
|
||||
public void setMaskGen(Masker masker)
|
||||
{
|
||||
this.masker = masker;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,13 +3,13 @@ package org.eclipse.jetty.websocket.generator;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.CloseFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
|
||||
public class CloseFrameGenerator extends FrameGenerator<CloseFrame>
|
||||
{
|
||||
public CloseFrameGenerator(ByteBufferPool bufferPool, WebSocketSettings settings)
|
||||
public CloseFrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
{
|
||||
super(bufferPool, settings);
|
||||
}
|
||||
|
|
|
@ -3,15 +3,15 @@ package org.eclipse.jetty.websocket.generator;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BaseFrame;
|
||||
|
||||
public abstract class FrameGenerator<T extends BaseFrame>
|
||||
{
|
||||
private final ByteBufferPool bufferPool;
|
||||
private final WebSocketSettings settings;
|
||||
private final WebSocketPolicy settings;
|
||||
|
||||
protected FrameGenerator(ByteBufferPool bufferPool, WebSocketSettings settings)
|
||||
protected FrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
{
|
||||
this.bufferPool = bufferPool;
|
||||
this.settings = settings;
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.EnumMap;
|
|||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.api.OpCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BaseFrame;
|
||||
import org.eclipse.jetty.websocket.masks.Masker;
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class Generator {
|
|||
private final EnumMap<OpCode, FrameGenerator<?>> generators = new EnumMap<>(OpCode.class);
|
||||
private Masker maskgen = null;
|
||||
|
||||
public Generator(ByteBufferPool bufferPool, WebSocketSettings settings)
|
||||
public Generator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
{
|
||||
generators.put(OpCode.PING,new PingFrameGenerator(bufferPool, settings));
|
||||
generators.put(OpCode.PONG,new PongFrameGenerator(bufferPool, settings));
|
||||
|
|
|
@ -3,12 +3,12 @@ package org.eclipse.jetty.websocket.generator;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
|
||||
public class PingFrameGenerator extends FrameGenerator<PingFrame>
|
||||
{
|
||||
public PingFrameGenerator(ByteBufferPool bufferPool, WebSocketSettings settings)
|
||||
public PingFrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
{
|
||||
super(bufferPool, settings);
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ package org.eclipse.jetty.websocket.generator;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PongFrame;
|
||||
|
||||
public class PongFrameGenerator extends FrameGenerator<PongFrame>
|
||||
{
|
||||
public PongFrameGenerator(ByteBufferPool bufferPool, WebSocketSettings settings)
|
||||
public PongFrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
{
|
||||
super(bufferPool, settings);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.eclipse.jetty.websocket.parser;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BinaryFrame;
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@ public class BinaryPayloadParser extends FrameParser<BinaryFrame>
|
|||
private ByteBuffer payload;
|
||||
private int payloadLength;
|
||||
|
||||
public BinaryPayloadParser(WebSocketSettings settings)
|
||||
public BinaryPayloadParser(WebSocketPolicy settings)
|
||||
{
|
||||
super(settings);
|
||||
frame = new BinaryFrame();
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.eclipse.jetty.websocket.parser;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.CloseFrame;
|
||||
|
||||
/**
|
||||
|
@ -12,7 +12,7 @@ public class ClosePayloadParser extends FrameParser<CloseFrame>
|
|||
{
|
||||
private CloseFrame frame;
|
||||
|
||||
public ClosePayloadParser(WebSocketSettings settings)
|
||||
public ClosePayloadParser(WebSocketPolicy settings)
|
||||
{
|
||||
super(settings);
|
||||
frame = new CloseFrame();
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.nio.ByteBuffer;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.OpCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BaseFrame;
|
||||
|
||||
/**
|
||||
|
@ -44,12 +44,12 @@ public abstract class FrameParser<T extends BaseFrame>
|
|||
}
|
||||
|
||||
private static final Logger LOG = Log.getLogger(FrameParser.class);
|
||||
private WebSocketSettings settings;
|
||||
private WebSocketPolicy settings;
|
||||
private State state = State.PAYLOAD_LEN;
|
||||
private int length = 0;
|
||||
private int cursor = 0;
|
||||
|
||||
public FrameParser(WebSocketSettings settings)
|
||||
public FrameParser(WebSocketPolicy settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public abstract class FrameParser<T extends BaseFrame>
|
|||
*/
|
||||
public abstract T getFrame();
|
||||
|
||||
protected WebSocketSettings getSettings()
|
||||
protected WebSocketPolicy getSettings()
|
||||
{
|
||||
return settings;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.OpCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BaseFrame;
|
||||
|
||||
/**
|
||||
|
@ -36,16 +36,16 @@ public class Parser
|
|||
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
||||
private final EnumMap<OpCode, FrameParser<?>> parsers = new EnumMap<>(OpCode.class);
|
||||
private FrameParser<?> parser;
|
||||
private WebSocketSettings settings;
|
||||
private WebSocketPolicy settings;
|
||||
private State state = State.FINOP;
|
||||
private int currentContinuationIndex = 0;
|
||||
|
||||
public Parser()
|
||||
{
|
||||
this(new WebSocketSettings());
|
||||
this(new WebSocketPolicy());
|
||||
}
|
||||
|
||||
public Parser(WebSocketSettings settings)
|
||||
public Parser(WebSocketPolicy settings)
|
||||
{
|
||||
/*
|
||||
* TODO: Investigate addition of decompression factory similar to SPDY work in situation of negotiated deflate extension?
|
||||
|
@ -67,7 +67,7 @@ public class Parser
|
|||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public WebSocketSettings getSettings()
|
||||
public WebSocketPolicy getSettings()
|
||||
{
|
||||
return settings;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.eclipse.jetty.websocket.parser;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@ public class PingPayloadParser extends FrameParser<PingFrame>
|
|||
private ByteBuffer payload;
|
||||
private int payloadLength;
|
||||
|
||||
public PingPayloadParser(WebSocketSettings settings)
|
||||
public PingPayloadParser(WebSocketPolicy settings)
|
||||
{
|
||||
super(settings);
|
||||
frame = new PingFrame();
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.eclipse.jetty.websocket.parser;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PongFrame;
|
||||
|
||||
public class PongPayloadParser extends FrameParser<PongFrame>
|
||||
|
@ -11,7 +11,7 @@ public class PongPayloadParser extends FrameParser<PongFrame>
|
|||
private ByteBuffer payload;
|
||||
private int payloadLength;
|
||||
|
||||
public PongPayloadParser(WebSocketSettings settings)
|
||||
public PongPayloadParser(WebSocketPolicy settings)
|
||||
{
|
||||
super(settings);
|
||||
frame = new PongFrame();
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.nio.ByteBuffer;
|
|||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.TextFrame;
|
||||
|
||||
public class TextPayloadParser extends FrameParser<TextFrame>
|
||||
|
@ -13,7 +13,7 @@ public class TextPayloadParser extends FrameParser<TextFrame>
|
|||
private ByteBuffer payload;
|
||||
private int payloadLength;
|
||||
|
||||
public TextPayloadParser(WebSocketSettings settings)
|
||||
public TextPayloadParser(WebSocketPolicy settings)
|
||||
{
|
||||
super(settings);
|
||||
frame = new TextFrame();
|
||||
|
|
|
@ -2,14 +2,14 @@ package org.eclipse.jetty.websocket.parser;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BaseFrame;
|
||||
|
||||
public class UnknownPayloadParser extends FrameParser<BaseFrame>
|
||||
{
|
||||
private BaseFrame frame;
|
||||
|
||||
public UnknownPayloadParser(WebSocketSettings settings)
|
||||
public UnknownPayloadParser(WebSocketPolicy settings)
|
||||
{
|
||||
super(settings);
|
||||
frame = new BaseFrame();
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.nio.ByteBuffer;
|
|||
import org.eclipse.jetty.io.StandardByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.ByteBufferAssert;
|
||||
import org.eclipse.jetty.websocket.Debug;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketSettings;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PongFrame;
|
||||
import org.eclipse.jetty.websocket.masks.FixedMasker;
|
||||
|
@ -34,7 +34,7 @@ public class RFC6455ExamplesGeneratorTest
|
|||
payload.put("Hello".getBytes(), 0, 5);
|
||||
ping.setPayload(payload);
|
||||
|
||||
PingFrameGenerator generator = new PingFrameGenerator(bufferPool, new WebSocketSettings());
|
||||
PingFrameGenerator generator = new PingFrameGenerator(bufferPool, new WebSocketPolicy());
|
||||
|
||||
ByteBuffer generatedPing = generator.generate(ping);
|
||||
|
||||
|
@ -61,8 +61,8 @@ public class RFC6455ExamplesGeneratorTest
|
|||
payload.put("Hello".getBytes(), 0, 5);
|
||||
pong.setPayload(payload);
|
||||
|
||||
WebSocketSettings settings = new WebSocketSettings();
|
||||
settings.setMaskGen(new FixedMasker());
|
||||
WebSocketPolicy settings = new WebSocketPolicy();
|
||||
settings.setMasker(new FixedMasker());
|
||||
|
||||
PongFrameGenerator generator = new PongFrameGenerator(bufferPool, settings);
|
||||
|
||||
|
|
Loading…
Reference in New Issue