move maxMessageSize configuration from javax framehandler to session
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
455cc3d2e2
commit
a115e92029
|
@ -46,7 +46,6 @@ import org.eclipse.jetty.websocket.core.Frame;
|
|||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.core.ProtocolException;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketConstants;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryMessageSink;
|
||||
|
@ -111,8 +110,6 @@ public class JavaxWebSocketFrameHandler implements FrameHandler
|
|||
private MessageSink textSink;
|
||||
private MessageSink binarySink;
|
||||
private MessageSink activeMessageSink;
|
||||
private int maxTextMessageBufferSize = WebSocketConstants.DEFAULT_MAX_TEXT_MESSAGE_SIZE;
|
||||
private int maxBinaryMessageBufferSize = WebSocketConstants.DEFAULT_MAX_BINARY_MESSAGE_SIZE;
|
||||
private JavaxWebSocketSession session;
|
||||
private Map<Byte, RegisteredMessageHandler> messageHandlerMap;
|
||||
private CoreSession coreSession;
|
||||
|
@ -171,26 +168,6 @@ public class JavaxWebSocketFrameHandler implements FrameHandler
|
|||
return session;
|
||||
}
|
||||
|
||||
public int getMaxTextMessageBufferSize()
|
||||
{
|
||||
return maxTextMessageBufferSize;
|
||||
}
|
||||
|
||||
public void setMaxTextMessageBufferSize(int maxTextMessageBufferSize)
|
||||
{
|
||||
this.maxTextMessageBufferSize = maxTextMessageBufferSize;
|
||||
}
|
||||
|
||||
public int getMaxBinaryMessageBufferSize()
|
||||
{
|
||||
return maxBinaryMessageBufferSize;
|
||||
}
|
||||
|
||||
public void setMaxBinaryMessageBufferSize(int maxBinaryMessageBufferSize)
|
||||
{
|
||||
this.maxBinaryMessageBufferSize = maxBinaryMessageBufferSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CoreSession coreSession, Callback callback)
|
||||
{
|
||||
|
@ -210,6 +187,9 @@ public class JavaxWebSocketFrameHandler implements FrameHandler
|
|||
|
||||
if (actualTextMetadata != null)
|
||||
{
|
||||
if (actualTextMetadata.isMaxMessageSizeSet())
|
||||
session.setMaxTextMessageBufferSize(actualTextMetadata.maxMessageSize);
|
||||
|
||||
actualTextMetadata.handle = InvokerUtils.bindTo(actualTextMetadata.handle, endpointInstance, endpointConfig, session);
|
||||
actualTextMetadata.handle = JavaxWebSocketFrameHandlerFactory.wrapNonVoidReturnType(actualTextMetadata.handle, session);
|
||||
textSink = JavaxWebSocketFrameHandlerFactory.createMessageSink(session, actualTextMetadata);
|
||||
|
@ -219,6 +199,9 @@ public class JavaxWebSocketFrameHandler implements FrameHandler
|
|||
|
||||
if (actualBinaryMetadata != null)
|
||||
{
|
||||
if (actualBinaryMetadata.isMaxMessageSizeSet())
|
||||
session.setMaxBinaryMessageBufferSize(actualBinaryMetadata.maxMessageSize);
|
||||
|
||||
actualBinaryMetadata.handle = InvokerUtils.bindTo(actualBinaryMetadata.handle, endpointInstance, endpointConfig, session);
|
||||
actualBinaryMetadata.handle = JavaxWebSocketFrameHandlerFactory.wrapNonVoidReturnType(actualBinaryMetadata.handle, session);
|
||||
binarySink = JavaxWebSocketFrameHandlerFactory.createMessageSink(session, actualBinaryMetadata);
|
||||
|
|
|
@ -179,11 +179,6 @@ public abstract class JavaxWebSocketFrameHandlerFactory
|
|||
config,
|
||||
future);
|
||||
|
||||
if (metadata.hasTextMetdata() && metadata.getTextMetadata().isMaxMessageSizeSet())
|
||||
frameHandler.setMaxTextMessageBufferSize(metadata.getTextMetadata().maxMessageSize);
|
||||
if (metadata.hasBinaryMetadata() && metadata.getBinaryMetadata().isMaxMessageSizeSet())
|
||||
frameHandler.setMaxBinaryMessageBufferSize(metadata.getBinaryMetadata().maxMessageSize);
|
||||
|
||||
return frameHandler;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.Extension;
|
||||
|
@ -319,7 +320,8 @@ public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.we
|
|||
@Override
|
||||
public int getMaxBinaryMessageBufferSize()
|
||||
{
|
||||
return frameHandler.getMaxBinaryMessageBufferSize();
|
||||
long maxBinaryMsgSize = coreSession.getMaxBinaryMessageSize();
|
||||
return (maxBinaryMsgSize > (long)Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)maxBinaryMsgSize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -332,7 +334,7 @@ public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.we
|
|||
@Override
|
||||
public void setMaxBinaryMessageBufferSize(int length)
|
||||
{
|
||||
frameHandler.setMaxBinaryMessageBufferSize(length);
|
||||
coreSession.setMaxBinaryMessageSize(length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -368,7 +370,8 @@ public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.we
|
|||
@Override
|
||||
public int getMaxTextMessageBufferSize()
|
||||
{
|
||||
return frameHandler.getMaxTextMessageBufferSize();
|
||||
long maxTextMsgSize = coreSession.getMaxTextMessageSize();
|
||||
return (maxTextMsgSize > (long)Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)maxTextMsgSize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -381,7 +384,7 @@ public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.we
|
|||
@Override
|
||||
public void setMaxTextMessageBufferSize(int length)
|
||||
{
|
||||
frameHandler.setMaxTextMessageBufferSize(length);
|
||||
coreSession.setMaxTextMessageSize(length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -502,6 +502,9 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio
|
|||
@Override
|
||||
public void onFrame(Frame frame, Callback callback)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("onFrame({})", frame);
|
||||
|
||||
try
|
||||
{
|
||||
assertValidIncoming(frame);
|
||||
|
@ -587,6 +590,9 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio
|
|||
@Override
|
||||
public void abort()
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("abort(): {}", this);
|
||||
|
||||
connection.cancelDemand();
|
||||
connection.getEndPoint().close();
|
||||
}
|
||||
|
@ -673,8 +679,7 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio
|
|||
try
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("receiveFrame({}, {}) - connectionState={}, handler={}",
|
||||
frame, callback, channelState, handler);
|
||||
LOG.debug("receiveFrame({}, {}) - connectionState={}, handler={}", frame, callback, channelState, handler);
|
||||
|
||||
boolean closeConnection = channelState.onIncomingFrame(frame);
|
||||
|
||||
|
|
Loading…
Reference in New Issue