knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [knox] branch master updated: KNOX-1828 Fix Websocket Message Size (#75)
Date Tue, 19 Mar 2019 15:30:07 GMT
This is an automated email from the ASF dual-hosted git repository.

more pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new b3963eb  KNOX-1828 Fix Websocket Message Size (#75)
b3963eb is described below

commit b3963eb33a3bc664214a16c2c16f04de8d777078
Author: Shawn Weeks <sweeks@weeksconsulting.us>
AuthorDate: Tue Mar 19 10:29:59 2019 -0500

    KNOX-1828 Fix Websocket Message Size (#75)
    
    Resolves issue with Zeppelin and websocket messages being capped at 65,536 bytes.
---
 .../gateway/websockets/ProxyInboundClient.java     |  4 --
 .../gateway/websockets/ProxyWebSocketAdapter.java  |  4 ++
 .../gateway/websockets/BigEchoSocketHandler.java   |  4 +-
 .../gateway/websockets/MessageFailureTest.java     | 25 ++++++++++-
 .../gateway/websockets/ProxyInboundClientTest.java | 50 ----------------------
 5 files changed, 30 insertions(+), 57 deletions(-)

diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyInboundClient.java
b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyInboundClient.java
index 8cd4023..7cb1c00 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyInboundClient.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyInboundClient.java
@@ -55,10 +55,6 @@ public class ProxyInboundClient extends Endpoint {
     this.session = backendSession;
     this.config = config;
 
-    /* Set the max message size */
-    session.setMaxBinaryMessageBufferSize(Integer.MAX_VALUE);
-    session.setMaxTextMessageBufferSize(Integer.MAX_VALUE);
-
     /* Add message handler for binary data */
     session.addMessageHandler(new MessageHandler.Whole<byte[]>() {
 
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java
b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java
index 82a711f..4c345cb 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java
@@ -81,6 +81,10 @@ public class ProxyWebSocketAdapter extends WebSocketAdapter {
      * plumbing takes place
      */
     container = ContainerProvider.getWebSocketContainer();
+    container.setDefaultMaxTextMessageBufferSize(frontEndSession.getPolicy().getMaxTextMessageBufferSize());
+    container.setDefaultMaxBinaryMessageBufferSize(frontEndSession.getPolicy().getMaxBinaryMessageBufferSize());
+    container.setAsyncSendTimeout(frontEndSession.getPolicy().getAsyncWriteTimeout());
+    container.setDefaultMaxSessionIdleTimeout(frontEndSession.getPolicy().getIdleTimeout());
 
     final ProxyInboundClient backendSocket = new ProxyInboundClient(getMessageCallback());
 
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BigEchoSocketHandler.java
b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BigEchoSocketHandler.java
index 080a5a1..58ecec0 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BigEchoSocketHandler.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BigEchoSocketHandler.java
@@ -36,8 +36,8 @@ class BigEchoSocketHandler extends WebSocketHandler implements WebSocketCreator
 
   @Override
   public void configure(WebSocketServletFactory factory) {
-    factory.getPolicy().setMaxTextMessageSize(10);
-    factory.getPolicy().setMaxBinaryMessageSize(10);
+    factory.getPolicy().setMaxTextMessageSize(66000);
+    factory.getPolicy().setMaxTextMessageBufferSize(66000);
     factory.setCreator(this);
   }
 
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/MessageFailureTest.java
b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/MessageFailureTest.java
index a265f65..bccd359 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/MessageFailureTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/MessageFailureTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.knox.gateway.websockets;
 
+import org.apache.commons.lang.RandomStringUtils;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.server.handler.ContextHandler;
@@ -69,7 +70,7 @@ public class MessageFailureTest {
    */
   @Test(timeout = 8000)
   public void testMessageTooBig() throws Exception {
-    final String bigMessage = "Echooooooooooooo";
+    final String bigMessage = RandomStringUtils.randomAscii(66001);
 
     WebSocketContainer container = ContainerProvider.getWebSocketContainer();
 
@@ -84,6 +85,28 @@ public class MessageFailureTest {
     Assert.assertThat(client.close.getCloseCode().getCode(), CoreMatchers.is(CloseReason.CloseCodes.TOO_BIG.getCode()));
   }
 
+  /**
+   * Test for a message that bigger than Jetty default but smaller than limit
+   * @throws Exception
+   */
+  @Test(timeout = 8000)
+  public void testMessageBiggerThanDefault() throws Exception {
+    final String bigMessage = RandomStringUtils.randomAscii(66000);
+
+    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
+
+    WebsocketClient client = new WebsocketClient();
+    javax.websocket.Session session = container.connectToServer(client,
+            proxyUri);
+    session.getBasicRemote().sendText(bigMessage);
+
+    client.awaitClose(CloseReason.CloseCodes.TOO_BIG.getCode(), 1000,
+            TimeUnit.MILLISECONDS);
+
+    Assert.assertThat(client.close.getCloseCode().getCode(), CoreMatchers.is(CloseReason.CloseCodes.TOO_BIG.getCode()));
+
+  }
+
   /*
    * Test for a message within limit.
    */
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/ProxyInboundClientTest.java
b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/ProxyInboundClientTest.java
index e812c13..dd5001f 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/ProxyInboundClientTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/ProxyInboundClientTest.java
@@ -16,7 +16,6 @@
  */
 package org.apache.knox.gateway.websockets;
 
-import org.apache.commons.lang.RandomStringUtils;
 import org.eclipse.jetty.server.Handler;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
@@ -192,53 +191,4 @@ public class ProxyInboundClientTest {
     Assert.assertEquals("Binary message does not match", textMessage, new String(receivedBinaryMessage,
StandardCharsets.UTF_8));
   }
 
-  @Test(timeout = 3000)
-  public void testTextMaxBufferLimit() throws IOException, DeploymentException {
-    final String longMessage = RandomStringUtils.random(100000);
-
-    final AtomicBoolean isTestComplete = new AtomicBoolean(false);
-
-    final WebSocketContainer container = ContainerProvider.getWebSocketContainer();
-    final ProxyInboundClient client = new ProxyInboundClient( new MessageEventCallback()
{
-      @Override
-      public void doCallback(String message) {
-      }
-
-      @Override
-      public void onConnectionOpen(Object session) {
-      }
-
-      @Override
-      public void onConnectionClose(CloseReason reason) {
-        isTestComplete.set(true);
-      }
-
-      @Override
-      public void onError(Throwable cause) {
-        isTestComplete.set(true);
-      }
-
-      @Override
-      public void onMessageText(String message, Object session) {
-        receivedMessage = message;
-        isTestComplete.set(true);
-      }
-
-      @Override
-      public void onMessageBinary(byte[] message, boolean last, Object session) {
-      }
-    });
-
-    Assert.assertThat(client, instanceOf(javax.websocket.Endpoint.class));
-
-    Session session = container.connectToServer(client, serverUri);
-
-    session.getBasicRemote().sendText(longMessage);
-
-    while(!isTestComplete.get()) { // NOPMD
-      /* just wait for the test to finish */
-    }
-
-    Assert.assertEquals(longMessage, receivedMessage);
-  }
 }


Mime
View raw message