Issue #2164 Update websocket manifests for osgi and add test in osgi
Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
parent
df012bb0a3
commit
17f518ffb1
|
@ -263,6 +263,12 @@
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||||
|
<artifactId>javax-websocket-client-impl</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||||
<artifactId>websocket-servlet</artifactId>
|
<artifactId>websocket-servlet</artifactId>
|
||||||
|
@ -390,11 +396,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.ow2.asm</groupId>
|
<groupId>org.ow2.asm</groupId>
|
||||||
<artifactId>asm</artifactId>
|
<artifactId>asm</artifactId>
|
||||||
|
<version>${asm.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.ow2.asm</groupId>
|
<groupId>org.ow2.asm</groupId>
|
||||||
<artifactId>asm-commons</artifactId>
|
<artifactId>asm-commons</artifactId>
|
||||||
|
<version>${asm.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||||
|
|
||||||
|
<!-- ============================================================= -->
|
||||||
|
<!-- Configure the Jetty Server instance with an ID "Server" -->
|
||||||
|
<!-- by adding a HTTP connector. -->
|
||||||
|
<!-- This configuration must be used in conjunction with jetty.xml -->
|
||||||
|
<!-- ============================================================= -->
|
||||||
|
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||||
|
|
||||||
|
<!-- =========================================================== -->
|
||||||
|
<!-- Add a HTTP Connector. -->
|
||||||
|
<!-- Configure an o.e.j.server.ServerConnector with a single -->
|
||||||
|
<!-- HttpConnectionFactory instance using the common httpConfig -->
|
||||||
|
<!-- instance defined in jetty.xml -->
|
||||||
|
<!-- -->
|
||||||
|
<!-- Consult the javadoc of o.e.j.server.ServerConnector and -->
|
||||||
|
<!-- o.e.j.server.HttpConnectionFactory for all configuration -->
|
||||||
|
<!-- that may be set here. -->
|
||||||
|
<!-- =========================================================== -->
|
||||||
|
<Call name="addConnector">
|
||||||
|
<Arg>
|
||||||
|
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||||
|
<Arg name="server"><Ref refid="Server" /></Arg>
|
||||||
|
<Arg name="factories">
|
||||||
|
<Array type="org.eclipse.jetty.server.ConnectionFactory">
|
||||||
|
<Item>
|
||||||
|
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
|
||||||
|
<Arg name="config"><Ref refid="httpConfig" /></Arg>
|
||||||
|
</New>
|
||||||
|
</Item>
|
||||||
|
</Array>
|
||||||
|
</Arg>
|
||||||
|
<Call name="addLifeCycleListener">
|
||||||
|
<Arg>
|
||||||
|
<New class="org.eclipse.jetty.osgi.boot.utils.ServerConnectorListener">
|
||||||
|
<Set name="sysPropertyName">boot.websocket.port</Set>
|
||||||
|
</New>
|
||||||
|
</Arg>
|
||||||
|
</Call>
|
||||||
|
<Set name="host"><Property name="jetty.http.host" /></Set>
|
||||||
|
<Set name="port"><Property name="jetty.http.port" default="80" /></Set>
|
||||||
|
<Set name="idleTimeout"><Property name="jetty.http.idleTimeout" default="30000"/></Set>
|
||||||
|
</New>
|
||||||
|
</Arg>
|
||||||
|
</Call>
|
||||||
|
</Configure>
|
|
@ -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<Void> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Option> options = new ArrayList<Option>();
|
||||||
|
options.add(CoreOptions.junitBundles());
|
||||||
|
options.addAll(configureJettyHomeAndPort("jetty-http-boot-with-websocket.xml"));
|
||||||
|
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.sql.*","javax.xml.*", "javax.activation.*"));
|
||||||
|
options.add(CoreOptions.systemPackages("com.sun.org.apache.xalan.internal.res","com.sun.org.apache.xml.internal.utils",
|
||||||
|
"com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xpath.internal",
|
||||||
|
"com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects"));
|
||||||
|
|
||||||
|
options.addAll(TestOSGiUtil.coreJettyDependencies());
|
||||||
|
options.add(systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(LOG_LEVEL));
|
||||||
|
options.add(systemProperty("org.eclipse.jetty.LEVEL").value(LOG_LEVEL));
|
||||||
|
options.addAll(jspDependencies());
|
||||||
|
options.addAll(annotationDependencies());
|
||||||
|
return options.toArray(new Option[options.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Option> configureJettyHomeAndPort(String jettySelectorFileName)
|
||||||
|
{
|
||||||
|
File etc = new File("src/test/config/etc");
|
||||||
|
|
||||||
|
List<Option> options = new ArrayList<Option>();
|
||||||
|
StringBuffer xmlConfigs = new StringBuffer();
|
||||||
|
xmlConfigs.append(new File(etc, "jetty.xml").toURI());
|
||||||
|
xmlConfigs.append(";");
|
||||||
|
xmlConfigs.append(new File(etc,jettySelectorFileName).toURI());
|
||||||
|
xmlConfigs.append(";");
|
||||||
|
xmlConfigs.append(new File(etc, "jetty-ssl.xml").toURI());
|
||||||
|
xmlConfigs.append(";");
|
||||||
|
xmlConfigs.append(new File(etc, "jetty-https.xml").toURI());
|
||||||
|
xmlConfigs.append(";");
|
||||||
|
xmlConfigs.append(new File(etc, "jetty-deployer.xml").toURI());
|
||||||
|
xmlConfigs.append(";");
|
||||||
|
xmlConfigs.append(new File(etc, "jetty-testrealm.xml").toURI());
|
||||||
|
|
||||||
|
options.add(systemProperty(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS).value(xmlConfigs.toString()));
|
||||||
|
options.add(systemProperty("jetty.http.port").value("0"));
|
||||||
|
options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestOSGiUtil.DEFAULT_SSL_PORT)));
|
||||||
|
options.add(systemProperty("jetty.home").value(etc.getParentFile().getAbsolutePath()));
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Option> jspDependencies()
|
||||||
|
{
|
||||||
|
return TestOSGiUtil.jspDependencies();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Option> annotationDependencies()
|
||||||
|
{
|
||||||
|
List<Option> res = new ArrayList<Option>();
|
||||||
|
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.mail.glassfish" ).version( "1.4.1.v201005082020" ).noStart());
|
||||||
|
res.add(mavenBundle().groupId("org.eclipse.jetty.tests").artifactId("test-mock-resources").versionAsInProject());
|
||||||
|
//test webapp bundle
|
||||||
|
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("test-jetty-webapp").classifier("webbundle").versionAsInProject());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public void assertAllBundlesActiveOrResolved()
|
||||||
|
{
|
||||||
|
TestOSGiUtil.assertAllBundlesActiveOrResolved(bundleContext);
|
||||||
|
TestOSGiUtil.debugBundles(bundleContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWebsocket() throws Exception
|
||||||
|
{
|
||||||
|
String tmp = System.getProperty("boot.websocket.port");
|
||||||
|
assertNotNull(tmp);
|
||||||
|
int port = Integer.valueOf(tmp.trim()).intValue();
|
||||||
|
|
||||||
|
URI uri = new URI("ws://127.0.0.1:" + port+"/ws/foo");
|
||||||
|
|
||||||
|
WebSocketClient client = new WebSocketClient();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
SimpleEchoSocket socket = new SimpleEchoSocket();
|
||||||
|
|
||||||
|
client.start();
|
||||||
|
|
||||||
|
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||||
|
request.setSubProtocols("chat");
|
||||||
|
client.connect(socket,uri,request);
|
||||||
|
// wait for closed socket connection.
|
||||||
|
assertTrue(socket.awaitClose(5,TimeUnit.SECONDS));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
client.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,6 +65,8 @@
|
||||||
<instructions>
|
<instructions>
|
||||||
<Bundle-Description>javax.websocket.client Implementation</Bundle-Description>
|
<Bundle-Description>javax.websocket.client Implementation</Bundle-Description>
|
||||||
<Export-Package>org.eclipse.jetty.websocket.jsr356.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}"</Export-Package>
|
<Export-Package>org.eclipse.jetty.websocket.jsr356.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}"</Export-Package>
|
||||||
|
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</Require-Capability>
|
||||||
|
<Provide-Capability>osgi.serviceloader;osgi.serviceloader=javax.websocket.ContainerProvider</Provide-Capability>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
|
|
@ -53,6 +53,16 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Require-Capability>osgi.serviceloader; filter:="(osgi.serviceloader=org.eclipse.jetty.websocket.api.extensions.Extension)";resolution:=optional;cardinality:=multiple, osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)"</Require-Capability>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -64,6 +64,18 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</Require-Capability>
|
||||||
|
<Provide-Capability>osgi.serviceloader;osgi.serviceloader=org.eclipse.jetty.websocket.api.extensions.Extension</Provide-Capability>
|
||||||
|
<_nouses>true</_nouses>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
|
5
pom.xml
5
pom.xml
|
@ -24,6 +24,7 @@
|
||||||
<!-- default values are unsupported, but required to be defined for reactor sanity reasons -->
|
<!-- default values are unsupported, but required to be defined for reactor sanity reasons -->
|
||||||
<alpn.version>undefined</alpn.version>
|
<alpn.version>undefined</alpn.version>
|
||||||
<conscrypt.version>1.0.0.RC11</conscrypt.version>
|
<conscrypt.version>1.0.0.RC11</conscrypt.version>
|
||||||
|
<asm.version>6.0</asm.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
|
@ -895,12 +896,12 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.ow2.asm</groupId>
|
<groupId>org.ow2.asm</groupId>
|
||||||
<artifactId>asm</artifactId>
|
<artifactId>asm</artifactId>
|
||||||
<version>6.0</version>
|
<version>${asm.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.ow2.asm</groupId>
|
<groupId>org.ow2.asm</groupId>
|
||||||
<artifactId>asm-commons</artifactId>
|
<artifactId>asm-commons</artifactId>
|
||||||
<version>6.0</version>
|
<version>${asm.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||||
|
|
Loading…
Reference in New Issue