Removing CloseUtil in favor of CloseInfo
This commit is contained in:
parent
cefeab8a65
commit
cd27d7bf29
|
@ -20,9 +20,9 @@ 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.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.protocol.Frame;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.util.CloseUtil;
|
||||
|
||||
/**
|
||||
* Responsible for routing the internally generated events destined for a specific WebSocket instance to whatever choice of development style the developer has
|
||||
|
@ -134,10 +134,8 @@ public class WebSocketEventDriver implements Parser.Listener
|
|||
// not interested in close events
|
||||
return;
|
||||
}
|
||||
byte payload[] = frame.getPayloadData();
|
||||
int statusCode = CloseUtil.getStatusCode(payload);
|
||||
String reason = CloseUtil.getReason(payload);
|
||||
events.onClose.call(websocket,connection,statusCode,reason);
|
||||
CloseInfo close = new CloseInfo(frame);
|
||||
events.onClose.call(websocket,connection,close.getStatusCode(),close.getReason());
|
||||
return;
|
||||
}
|
||||
case BINARY:
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
package org.eclipse.jetty.websocket.util;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.api.ProtocolException;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
|
||||
public class CloseUtil
|
||||
{
|
||||
public static void assertValidPayload(WebSocketFrame frame)
|
||||
{
|
||||
byte payload[] = frame.getPayloadData();
|
||||
|
||||
if (payload.length < 2)
|
||||
{
|
||||
return; // no status code
|
||||
}
|
||||
|
||||
int statusCode = getStatusCode(payload);
|
||||
|
||||
// Validate value
|
||||
if ((statusCode < StatusCode.NORMAL) || (statusCode == StatusCode.UNDEFINED) || (statusCode == StatusCode.NO_CLOSE)
|
||||
|| (statusCode == StatusCode.NO_CODE) || ((statusCode > 1011) && (statusCode <= 2999)) || (statusCode >= 5000))
|
||||
{
|
||||
throw new ProtocolException("Invalid close code: " + statusCode);
|
||||
}
|
||||
|
||||
// validate reason
|
||||
getReason(payload);
|
||||
}
|
||||
|
||||
public static String getReason(byte[] payload)
|
||||
{
|
||||
if (payload.length <= 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ByteBuffer bb = ByteBuffer.wrap(payload);
|
||||
int len = payload.length - 2;
|
||||
byte utf[] = new byte[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
utf[i] = bb.get(i + 2);
|
||||
}
|
||||
return StringUtil.toUTF8String(utf,0,utf.length);
|
||||
}
|
||||
|
||||
public static int getStatusCode(byte[] payload)
|
||||
{
|
||||
|
||||
int statusCode = 0;
|
||||
ByteBuffer bb = ByteBuffer.wrap(payload);
|
||||
statusCode |= (bb.get(0) & 0xFF) << 8;
|
||||
statusCode |= (bb.get(1) & 0xFF);
|
||||
return statusCode;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue