fix the websocket configuration problems shown by ClientConfigTest
correctly detect when a message has exceeded the max size in the sink forward changes to the input buffer size to the connection in WSChannel Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
7019c18117
commit
c68a1b6066
|
@ -18,13 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.common.message;
|
||||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.common.AbstractMessageSink;
|
||||
import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.MessageTooLargeException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
@ -32,6 +25,13 @@ import java.nio.ByteBuffer;
|
|||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.common.AbstractMessageSink;
|
||||
import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.MessageTooLargeException;
|
||||
|
||||
public class ByteArrayMessageSink extends AbstractMessageSink
|
||||
{
|
||||
private static final byte EMPTY_BUFFER[] = new byte[0];
|
||||
|
@ -63,10 +63,9 @@ public class ByteArrayMessageSink extends AbstractMessageSink
|
|||
if (frame.hasPayload())
|
||||
{
|
||||
ByteBuffer payload = frame.getPayload();
|
||||
int nextSize = size + payload.remaining();
|
||||
size = size + payload.remaining();
|
||||
if (maxMessageSize > 0 && size > maxMessageSize)
|
||||
throw new MessageTooLargeException("Message size [" + size + "] exceeds maximum size [" + maxMessageSize + "]");
|
||||
size = nextSize;
|
||||
|
||||
if (out == null)
|
||||
out = new ByteArrayOutputStream(BUFFER_SIZE);
|
||||
|
|
|
@ -18,13 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.common.message;
|
||||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.common.AbstractMessageSink;
|
||||
import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.MessageTooLargeException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
@ -32,6 +25,13 @@ import java.nio.ByteBuffer;
|
|||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.common.AbstractMessageSink;
|
||||
import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.MessageTooLargeException;
|
||||
|
||||
public class ByteBufferMessageSink extends AbstractMessageSink
|
||||
{
|
||||
private static final int BUFFER_SIZE = 65535;
|
||||
|
@ -62,10 +62,9 @@ public class ByteBufferMessageSink extends AbstractMessageSink
|
|||
if (frame.hasPayload())
|
||||
{
|
||||
ByteBuffer payload = frame.getPayload();
|
||||
int nextSize = size + payload.remaining();
|
||||
size = size + payload.remaining();
|
||||
if (maxMessageSize > 0 && size > maxMessageSize)
|
||||
throw new MessageTooLargeException("Message size [" + size + "] exceeds maximum size [" + maxMessageSize + "]");
|
||||
size = nextSize;
|
||||
|
||||
if (out == null)
|
||||
out = new ByteArrayOutputStream(BUFFER_SIZE);
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.common.message;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.Utf8StringBuilder;
|
||||
|
@ -28,12 +34,6 @@ import org.eclipse.jetty.websocket.common.invoke.InvalidSignatureException;
|
|||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.MessageTooLargeException;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class StringMessageSink extends AbstractMessageSink
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(StringMessageSink.class);
|
||||
|
@ -66,10 +66,9 @@ public class StringMessageSink extends AbstractMessageSink
|
|||
if (frame.hasPayload())
|
||||
{
|
||||
ByteBuffer payload = frame.getPayload();
|
||||
int nextSize = size + payload.remaining();
|
||||
size = size + payload.remaining();
|
||||
if (maxMessageSize > 0 && size > maxMessageSize)
|
||||
throw new MessageTooLargeException("Message size [" + size + "] exceeds maximum size [" + maxMessageSize + "]");
|
||||
size = nextSize;
|
||||
|
||||
if (utf == null)
|
||||
utf = new Utf8StringBuilder(1024);
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WriteCallback;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
|
||||
@WebSocket
|
||||
|
@ -31,4 +33,11 @@ public class EchoSocket extends EventSocket
|
|||
super.onMessage(message);
|
||||
session.getRemote().sendString(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(byte[] buf, int offset, int len)
|
||||
{
|
||||
super.onMessage(buf, offset, len);
|
||||
session.getRemote().sendBytes(ByteBuffer.wrap(buf, offset, len), WriteCallback.NOOP);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
|
@ -42,6 +43,7 @@ public class EventSocket
|
|||
private String behavior;
|
||||
|
||||
public BlockingQueue<String> messageQueue = new BlockingArrayQueue<>();
|
||||
public BlockingQueue<ByteBuffer> binaryMessageQueue = new BlockingArrayQueue<>();
|
||||
public volatile int statusCode = StatusCode.UNDEFINED;
|
||||
public volatile String reason;
|
||||
public volatile Throwable error = null;
|
||||
|
@ -66,6 +68,15 @@ public class EventSocket
|
|||
messageQueue.offer(message);
|
||||
}
|
||||
|
||||
|
||||
@OnWebSocketMessage
|
||||
public void onMessage(byte buf[], int offset, int len)
|
||||
{
|
||||
ByteBuffer message = ByteBuffer.wrap(buf, offset, len);
|
||||
LOG.info("{} onMessage(): {}", toString(), message);
|
||||
binaryMessageQueue.offer(message);
|
||||
}
|
||||
|
||||
@OnWebSocketClose
|
||||
public void onClose(int statusCode, String reason)
|
||||
{
|
||||
|
|
|
@ -117,7 +117,7 @@ public class ClientConfigTest
|
|||
@Test
|
||||
public void testMaxBinaryMessageSize() throws Exception
|
||||
{
|
||||
client.setMaxTextMessageSize(maxMessageSize);
|
||||
client.setMaxBinaryMessageSize(maxMessageSize);
|
||||
|
||||
URI uri = URI.create("ws://localhost:8080/");
|
||||
EventSocket clientEndpoint = new EventSocket();
|
||||
|
|
|
@ -637,6 +637,8 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio
|
|||
public void setInputBufferSize(int inputBufferSize)
|
||||
{
|
||||
this.inputBufferSize = inputBufferSize;
|
||||
if (connection != null)
|
||||
connection.setInputBufferSize(inputBufferSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue