From 17f518ffb19d781718da61ccea30bcaf2e689a44 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 31 Jan 2018 15:05:18 +0100 Subject: [PATCH] Issue #2164 Update websocket manifests for osgi and add test in osgi Signed-off-by: Jan Bartel --- jetty-osgi/test-jetty-osgi/pom.xml | 8 + .../etc/jetty-http-boot-with-websocket.xml | 47 ++++++ .../jetty/osgi/test/SimpleEchoSocket.java | 87 ++++++++++ .../test/TestJettyOSGiBootWithWebSocket.java | 155 ++++++++++++++++++ .../javax-websocket-client-impl/pom.xml | 2 + jetty-websocket/websocket-api/pom.xml | 10 ++ jetty-websocket/websocket-common/pom.xml | 12 ++ pom.xml | 5 +- 8 files changed, 324 insertions(+), 2 deletions(-) create mode 100644 jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-http-boot-with-websocket.xml create mode 100644 jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SimpleEchoSocket.java create mode 100644 jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithWebSocket.java diff --git a/jetty-osgi/test-jetty-osgi/pom.xml b/jetty-osgi/test-jetty-osgi/pom.xml index fc5a711affd..8e7cbea4000 100644 --- a/jetty-osgi/test-jetty-osgi/pom.xml +++ b/jetty-osgi/test-jetty-osgi/pom.xml @@ -263,6 +263,12 @@ ${project.version} runtime + + org.eclipse.jetty.websocket + javax-websocket-client-impl + ${project.version} + runtime + org.eclipse.jetty.websocket websocket-servlet @@ -390,11 +396,13 @@ org.ow2.asm asm + ${asm.version} test org.ow2.asm asm-commons + ${asm.version} test diff --git a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-http-boot-with-websocket.xml b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-http-boot-with-websocket.xml new file mode 100644 index 00000000000..ecab2fe4198 --- /dev/null +++ b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-http-boot-with-websocket.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + boot.websocket.port + + + + + + + + + + diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SimpleEchoSocket.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SimpleEchoSocket.java new file mode 100644 index 00000000000..3c21433eb9e --- /dev/null +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SimpleEchoSocket.java @@ -0,0 +1,87 @@ +// +// ======================================================================== +// 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.osgi.test; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.StatusCode; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; + +/** + * Basic Echo Client Socket + */ +@WebSocket(maxTextMessageSize = 64 * 1024) +public class SimpleEchoSocket +{ + private final CountDownLatch closeLatch; + @SuppressWarnings("unused") + private Session session; + + public SimpleEchoSocket() + { + this.closeLatch = new CountDownLatch(1); + } + + public boolean awaitClose(int duration, TimeUnit unit) throws InterruptedException + { + return this.closeLatch.await(duration,unit); + } + + @OnWebSocketClose + public void onClose(int statusCode, String reason) + { + //System.out.printf("Connection closed: %d - %s%n",statusCode,reason); + this.session = null; + this.closeLatch.countDown(); // trigger latch + } + + @OnWebSocketConnect + public void onConnect(Session session) + { + //System.out.printf("Got connect: %s%n",session); + this.session = session; + try + { + Future fut; + //System.err.println("Sending Foo!"); + fut = session.getRemote().sendStringByFuture("Foo"); + + fut.get(2,TimeUnit.SECONDS); // wait for send to complete. + //System.err.println("Foo complete"); + + session.close(StatusCode.NORMAL,"I'm done"); + } + catch (Throwable t) + { + t.printStackTrace(); + } + } + + @OnWebSocketMessage + public void onMessage(String msg) + { + //System.out.printf("Got msg: %s%n",msg); + } +} diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithWebSocket.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithWebSocket.java new file mode 100644 index 00000000000..558bb8127e0 --- /dev/null +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithWebSocket.java @@ -0,0 +1,155 @@ +// +// ======================================================================== +// 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.osgi.test; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; + +import java.io.File; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; + +import org.eclipse.jetty.osgi.boot.OSGiServerConstants; +import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; +import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.CoreOptions; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.osgi.framework.BundleContext; + +/** + */ +@RunWith(PaxExam.class) + +public class TestJettyOSGiBootWithWebSocket +{ + private static final String LOG_LEVEL = "WARN"; + + @Inject + BundleContext bundleContext = null; + + @Configuration + public static Option[] configure() + { + ArrayList