Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2767 - WebSocket Policy on JSR356 ClientContainer not represen…
…ted correctly + Added Client unit tests for large messages + Re-enabled Server unit tests for large messages + Added more Server unit tests for large messages + In case of JSR356 Server with policy (and Behavior of SERVER) is controlling javax.websocker.server.ServerContainer and a user chooses to use that ServerContainer to connect to a remote websocket endpoint (using ServerContainer as a client), then the policy is delegated down to the Client Container with a different behavior (only). Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
- Loading branch information
Showing
18 changed files
with
1,053 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...socket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/LargeMessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.websocket.jsr356; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.websocket.ContainerProvider; | ||
import javax.websocket.Session; | ||
import javax.websocket.WebSocketContainer; | ||
|
||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.ServerConnector; | ||
import org.eclipse.jetty.server.handler.ContextHandler; | ||
import org.eclipse.jetty.websocket.api.WebSocketBehavior; | ||
import org.eclipse.jetty.websocket.api.WebSocketPolicy; | ||
import org.eclipse.jetty.websocket.api.util.WSURI; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class LargeMessageTest | ||
{ | ||
private static final int LARGER_THAN_DEFAULT_SIZE; | ||
private Server server; | ||
|
||
static | ||
{ | ||
WebSocketPolicy defaultPolicy = new WebSocketPolicy(WebSocketBehavior.CLIENT); | ||
LARGER_THAN_DEFAULT_SIZE = defaultPolicy.getMaxTextMessageSize() * 3; | ||
} | ||
|
||
@Before | ||
public void startServer() throws Exception | ||
{ | ||
server = new Server(); | ||
ServerConnector connector = new ServerConnector(server); | ||
connector.setPort(0); | ||
server.addConnector(connector); | ||
|
||
// This handler is expected to handle echoing of 2MB messages (max) | ||
EchoHandler echoHandler = new EchoHandler(); | ||
|
||
ContextHandler context = new ContextHandler(); | ||
context.setContextPath("/"); | ||
context.setHandler(echoHandler); | ||
server.setHandler(context); | ||
|
||
server.start(); | ||
} | ||
|
||
@After | ||
public void stopServer() throws Exception | ||
{ | ||
server.stop(); | ||
} | ||
|
||
@SuppressWarnings("Duplicates") | ||
@Test | ||
public void testLargeEcho_AsEndpointInstance() throws Exception | ||
{ | ||
WebSocketContainer container = ContainerProvider.getWebSocketContainer(); | ||
server.addBean(container); // allow to shutdown with server | ||
|
||
container.setDefaultMaxTextMessageBufferSize(LARGER_THAN_DEFAULT_SIZE); | ||
|
||
EndpointEchoClient echoer = new EndpointEchoClient(); | ||
Assert.assertThat(echoer,instanceOf(javax.websocket.Endpoint.class)); | ||
|
||
URI wsUri = WSURI.toWebsocket(server.getURI()).resolve("/"); | ||
|
||
// Issue connect using instance of class that extends Endpoint | ||
Session session = container.connectToServer(echoer,wsUri); | ||
byte buf[] = new byte[LARGER_THAN_DEFAULT_SIZE]; | ||
Arrays.fill(buf, (byte)'x'); | ||
String message = new String(buf, UTF_8); | ||
session.getBasicRemote().sendText(message); | ||
|
||
String echoed = echoer.textCapture.messages.poll(1, TimeUnit.SECONDS); | ||
assertThat("Echoed", echoed, is(message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...a/org/eclipse/jetty/websocket/jsr356/server/LargeClientContainerInitAsServerListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.websocket.jsr356.server; | ||
|
||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
|
||
import org.eclipse.jetty.websocket.jsr356.JettyClientContainerProvider; | ||
|
||
public class LargeClientContainerInitAsServerListener implements ServletContextListener | ||
{ | ||
@Override | ||
public void contextInitialized(ServletContextEvent sce) | ||
{ | ||
JettyClientContainerProvider.useServerContainer(true); | ||
} | ||
|
||
@Override | ||
public void contextDestroyed(ServletContextEvent sce) | ||
{ | ||
/* ignore */ | ||
} | ||
} |
Oops, something went wrong.