Merge remote-tracking branch 'origin/jetty-9.4.x'

This commit is contained in:
Joakim Erdfelt 2017-06-09 09:17:43 -07:00
commit 76ace004b6
25 changed files with 442 additions and 108 deletions

View File

@ -1,6 +1,32 @@
jetty-10.0.0-SNAPSHOT
jetty-9.4.5-SNAPSHOT
jetty-9.4.6.v20170531 - 31 May 2017
+ 523 TLS close behaviour breaking session resumption
+ 1108 Please improve logging in SslContextFactory when there are no approved
cipher suites
+ 1505 Adding jetty.base.uri and jetty.home.uri
+ 1514 websocket dump badly formatted
+ 1516 Delay starting of WebSocketClient until an attempt to connect is made
+ 1520 PropertyUserStore should extract packed config file
+ 1526 MongoSessionDataStore old session scavenging is broken due to the
missing $ sign in "and" operation
+ 1527 Jetty BOM should not depend on jetty-parent
+ 1528 Internal HttpClient usages should have common configurable technique
+ 1536 Jetty BOM should include more artifacts
+ 1538 NPE in Response.putHeaders
+ 1539 JarFileResource mishandles paths with spaces
+ 1544 Disabling JSR-356 doesn't indicate context it was disabled for
+ 1546 Improve handling of quotes in cookies
+ 1553 X509.isCertSign() can throw ArrayIndexOutOfBoundsException on
non-standard implementations
+ 1556 A timing channel in Password.java
+ 1558 When creating WebAppContext without session-config and with NO_SESSIONS
throws NPE
+ 1567 XmlConfiguration will start the same object multiple times
+ 1568 ServletUpgradeRequest mangles query strings containing percent-escapes
by re-escaping them
+ 1569 Allow setting of maxBinaryMessageSize to 0 in WebSocketPolicy
+ 1579 NPE in Quoted Quality CSV
jetty-9.4.4.v20170414 - 14 April 2017
+ 612 Support HTTP Trailer

View File

@ -37,22 +37,26 @@ Some user-agents might be excluded from compression to avoid common browser bugs
The `GzipHandler` is added to the entire server by the `etc/jetty-gzip.xml` file from the `gzip.mod` module.
It may also be added to individual contexts in a context xml file.
____
[NOTE]
Jetty 9 only compresses using GZip.
Using deflate http compression is not supported and will not function.
____
[[gzip-filter-rules]]
==== Gzip Rules
`GzipHandler` will gzip or deflate the content of a response if:
`GzipHandler` will gzip the content of a response if:
* It is mapped to a matching path
* The request method is configured to support gzip
* The request is not from an excluded User-Agent
* accept-encoding header is set to either gzip, deflate or a combination of those
* accept-encoding header is set to gzip
* The response status code is >=200 and <300
* The content length is unknown or more than the minGzipSize initParameter or the minGzipSize is 0(default)
* The content-type does not match an excluded mime-type
* No content-encoding is specified by the resource
If both gzip and deflate are specified in the accept-encoding header, then gzip will be used.
Compressing the content can greatly improve the network bandwidth usage, but at the cost of memory and CPU cycles.
The link:#default-servlet[DefaultServlet] is capable of serving pre-compressed static content, which saves memory and CPU.
By default, the `GzipHandler` will check to see if pre-compressed content exists, and pass the request through to be handled by the `DefaultServlet`.
@ -65,8 +69,6 @@ Content will only be compressed if content length is either unknown or greater t
checkGzExists::
True by default.
If set to false, the handler will not check for pre-compressed content.
compressionLevel::
The compression level used for deflate compression. (0-9).
includedMethods::
List of HTTP methods to compress.
If not set, only `GET` requests are compressed.

View File

@ -0,0 +1,5 @@
[description]
This module causes jetty to stop immediately after starting. This is good for testing configuration and/or precompiling quickstart webapps
[xml]
etc/jetty-stop.xml

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>config</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>jar</format>
</formats>
<dependencySets>
<dependencySet>
<scope>provided</scope>
<outputDirectory>lib/mail</outputDirectory>
<includes>
<include>org.eclipse.jetty.orbit:javax.mail.glassfish</include>
</includes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/jndi-config</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**</include>
</includes>
</fileSet>
</fileSets>
</assembly>

View File

@ -3,6 +3,7 @@ Adds the Jetty JNDI implementation to the classpath.
[depend]
server
mail
[lib]
lib/jetty-jndi-${jetty.version}.jar

View File

@ -0,0 +1,8 @@
[description]
Adds the javax.mail implementation to the classpath.
[name]
mail
[lib]
lib/mail/*.jar

View File

@ -102,7 +102,6 @@ public class TestJettyOSGiBootCore
res.add(mavenBundle().groupId( "javax.servlet" ).artifactId( "javax.servlet-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "javax.annotation" ).artifactId( "javax.annotation-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.apache.geronimo.specs" ).artifactId( "geronimo-jta_1.1_spec" ).version("1.1.1").noStart());
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" ).artifactId( "jetty-util" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-deploy" ).versionAsInProject().noStart());

View File

@ -111,6 +111,7 @@ public class TestJettyOSGiBootWithAnnotations
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-container-initializer").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.jetty.tests").artifactId("test-mock-resources").versionAsInProject());
//test webapp bundle
@ -129,15 +130,6 @@ public class TestJettyOSGiBootWithAnnotations
TestOSGiUtil.debugBundles(bundleContext);
}
// at the moment can't run httpservice with jsp at the same time.
// that is a regression in jetty-9
@Ignore
@Test
public void testHttpService() throws Exception
{
TestOSGiUtil.testHttpServiceGreetings(bundleContext, "http", TestJettyOSGiBootCore.DEFAULT_HTTP_PORT);
}
@Test

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>config</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>jar</format>
</formats>
<dependencySets>
<dependencySet>
<scope>provided</scope>
<outputDirectory>lib/transactions</outputDirectory>
<includes>
<include>javax.transaction:javax.transaction-api</include>
</includes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/plus-config</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**</include>
</includes>
</fileSet>
</fileSets>
</assembly>

View File

@ -8,6 +8,7 @@ server
security
jndi
webapp
transactions
[lib]
lib/jetty-plus-${jetty.version}.jar

View File

@ -0,0 +1,8 @@
[description]
Puts javax.transaction api on the classpath
[name]
transactions
[lib]
lib/transactions/*.jar

View File

@ -23,43 +23,115 @@ import java.lang.reflect.Method;
import javax.websocket.ContainerProvider;
import javax.websocket.WebSocketContainer;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ShutdownThread;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope;
/**
* Client {@link ContainerProvider} implementation.
* <p>
* <p>
* Created by a {@link java.util.ServiceLoader} call in the
* {@link javax.websocket.ContainerProvider#getWebSocketContainer()} call.
* </p>
*/
public class JettyClientContainerProvider extends ContainerProvider
{
private static Object lock = new Object();
private static ClientContainer INSTANCE;
private static final Logger LOG = Log.getLogger(JettyClientContainerProvider.class);
public static ClientContainer getInstance()
private static boolean useSingleton = false;
private static WebSocketContainer INSTANCE;
private static boolean useServerContainer = false;
private static Object lock = new Object();
/**
* Change calls to {@link ContainerProvider#getWebSocketContainer()} to always
* return a singleton instance of the same {@link WebSocketContainer}
*
* @param flag true to use a singleton instance of {@link WebSocketContainer} for all
* calls to {@link ContainerProvider#getWebSocketContainer()}
*/
@SuppressWarnings("unused")
public static void useSingleton(boolean flag)
{
return INSTANCE;
JettyClientContainerProvider.useSingleton = flag;
}
public static void stop() throws Exception
/**
* Test if {@link ContainerProvider#getWebSocketContainer()} will always
* return a singleton instance of the same {@link WebSocketContainer}
*
* @return true if using a singleton instance of {@link WebSocketContainer} for all
* calls to {@link ContainerProvider#getWebSocketContainer()}
*/
@SuppressWarnings("unused")
public static boolean willUseSingleton()
{
synchronized (lock)
{
if (INSTANCE == null)
{
return;
}
return useSingleton;
}
try
{
INSTANCE.stop();
}
finally
{
INSTANCE = null;
}
/**
* Add ability of calls to {@link ContainerProvider#getWebSocketContainer()} to
* find and return the {@link javax.websocket.server.ServerContainer} from the
* active {@code javax.servlet.ServletContext}.
* <p>
* <p>
* This will only work if the call to {@link ContainerProvider#getWebSocketContainer()}
* occurs within a thread being processed by the Servlet container.
* </p>
*
* @param flag true to to use return the {@link javax.websocket.server.ServerContainer}
* from the active {@code javax.servlet.ServletContext} for all calls to
* {@link ContainerProvider#getWebSocketContainer()} from within a Servlet thread.
*/
@SuppressWarnings("unused")
public static void useServerContainer(boolean flag)
{
JettyClientContainerProvider.useServerContainer = flag;
}
/**
* Test if {@link ContainerProvider#getWebSocketContainer()} has the ability to
* find and return the {@link javax.websocket.server.ServerContainer} from the
* active {@code javax.servlet.ServletContext}, before creating a new client based
* {@link WebSocketContainer}.
*
* @return true if {@link WebSocketContainer} returned from
* calls to {@link ContainerProvider#getWebSocketContainer()} could be the
* {@link javax.websocket.server.ServerContainer}
* from the active {@code javax.servlet.ServletContext}
*/
@SuppressWarnings("unused")
public static boolean willUseServerContainer()
{
return useServerContainer;
}
public Object getContextHandler()
{
try
{
// Equiv of: ContextHandler.Context context = ContextHandler.getCurrentContext()
Class<?> clazzContextHandler = Class.forName("org.eclipse.jetty.server.handler.ContextHandler");
Method methodGetContext = clazzContextHandler.getMethod("getCurrentContext");
Object objContext = methodGetContext.invoke(null);
if (objContext == null)
return null;
// Equiv of: ContextHandler handler = ContextHandler.getContextHandler(context);
Class<?> clazzServletContext = Class.forName("javax.servlet.ServletContext");
Method methodGetContextHandler = clazzContextHandler.getMethod("getContextHandler", clazzServletContext);
return methodGetContextHandler.invoke(null, objContext);
}
catch (Throwable ignore)
{
LOG.ignore(ignore);
return null;
}
}
@ -72,22 +144,43 @@ public class JettyClientContainerProvider extends ContainerProvider
{
synchronized (lock)
{
try
WebSocketContainer webSocketContainer = null;
Object contextHandler = getContextHandler();
if (useServerContainer && contextHandler != null)
{
Class<?> clazzServerContainer = Class.forName("org.eclipse.jetty.websocket.jsr356.server.ServerContainer");
Method method = clazzServerContainer.getMethod("getWebSocketContainer");
WebSocketContainer container = (WebSocketContainer) method.invoke(null);
if (container != null)
try
{
return container;
// Attempt to use the ServerContainer attribute.
Method methodGetServletContext = contextHandler.getClass().getMethod("getServletContext");
Object objServletContext = methodGetServletContext.invoke(contextHandler);
if (objServletContext != null)
{
Method methodGetAttribute = objServletContext.getClass().getMethod("getAttribute", String.class);
Object objServerContainer = methodGetAttribute.invoke(objServletContext, "javax.websocket.server.ServerContainer");
if (objServerContainer != null && objServerContainer instanceof WebSocketContainer)
{
webSocketContainer = (WebSocketContainer) objServerContainer;
}
}
}
catch (Throwable ignore)
{
LOG.ignore(ignore);
// continue, without server container
}
}
catch (Throwable ignore)
if (useSingleton && INSTANCE != null)
{
return INSTANCE;
}
if (INSTANCE == null)
// Still no instance?
if (webSocketContainer == null)
{
// TODO: use cached Executor, ByteBufferPool, and HttpClient here
SimpleContainerScope containerScope = new SimpleContainerScope(WebSocketPolicy.newClientPolicy());
QueuedThreadPool threadPool= new QueuedThreadPool();
String name = "Jsr356Client@" + hashCode();
@ -95,23 +188,42 @@ public class JettyClientContainerProvider extends ContainerProvider
threadPool.setDaemon(true);
containerScope.setExecutor(threadPool);
containerScope.addBean(threadPool);
INSTANCE = new ClientContainer(containerScope);
ClientContainer clientContainer = new ClientContainer(containerScope);
if (contextHandler != null && contextHandler instanceof ContainerLifeCycle)
{
// Add as bean to contextHandler
// Allow startup to follow Jetty lifecycle
((ContainerLifeCycle) contextHandler).addBean(clientContainer);
}
else
{
// Static Initialization
// register JVM wide shutdown thread
ShutdownThread.register(clientContainer);
}
if (!clientContainer.isStarted())
{
try
{
clientContainer.start();
}
catch (Exception e)
{
throw new RuntimeException("Unable to start Client Container", e);
}
}
webSocketContainer = clientContainer;
}
if (!INSTANCE.isStarted())
if (useSingleton)
{
try
{
// We need to start this container properly.
INSTANCE.start();
}
catch (Exception e)
{
throw new RuntimeException("Unable to start Client Container", e);
}
INSTANCE = webSocketContainer;
}
return INSTANCE;
return webSocketContainer;
}
}
}

View File

@ -138,22 +138,17 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
private WebSocketServerFactory(ServletContext context, WebSocketPolicy policy, DecoratedObjectFactory objectFactory, Executor executor, ByteBufferPool bufferPool)
{
this.context = context;
this.containerPolicy = policy;
this.objectFactory = objectFactory;
this.executor = executor;
handshakes.put(HandshakeRFC6455.VERSION, new HandshakeRFC6455());
addBean(scheduler);
addBean(bufferPool);
this.contextClassloader = Thread.currentThread().getContextClassLoader();
this.containerPolicy = policy;
this.bufferPool = bufferPool;
this.creator = this;
this.contextClassloader = Thread.currentThread().getContextClassLoader();
this.extensionFactory = new WebSocketExtensionFactory(this);
this.handshakes.put(HandshakeRFC6455.VERSION, new HandshakeRFC6455());
this.sessionFactories.add(new WebSocketSessionFactory(this));
this.creator = this;
// Create supportedVersions
List<Integer> versions = new ArrayList<>();
@ -172,6 +167,9 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
rv.append(v);
}
supportedVersions = rv.toString();
addBean(scheduler);
addBean(bufferPool);
}
public void addSessionListener(WebSocketSession.Listener listener)

View File

@ -0,0 +1,77 @@
//
// ========================================================================
// Copyright (c) 1995-2017 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.server;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import java.util.concurrent.Executor;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.junit.Test;
public class WebSocketServerFactoryTest
{
private int setLogLevel(Class<?> clazz, int newLevel)
{
int oldLevel = StdErrLog.LEVEL_DEFAULT;
Logger logger = Log.getLogger(clazz);
if (logger instanceof StdErrLog)
{
StdErrLog stdErrLog = (StdErrLog) logger;
oldLevel = stdErrLog.getLevel();
stdErrLog.setLevel(newLevel);
}
return oldLevel;
}
@Test
public void testInit()
{
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
Executor executor = new QueuedThreadPool();
ByteBufferPool bufferPool = new MappedByteBufferPool();
int wsFactoryLevel = setLogLevel(WebSocketServerFactory.class, StdErrLog.LEVEL_DEBUG);
int abstractLifecycleLevel = setLogLevel(AbstractLifeCycle.class, StdErrLog.LEVEL_DEBUG);
int containerLifecycleLevel = setLogLevel(ContainerLifeCycle.class, StdErrLog.LEVEL_DEBUG);
try
{
WebSocketServerFactory wsFactory = new WebSocketServerFactory(policy, executor, bufferPool);
// The above init caused NPE due to bad constructor initialization order with debug active
assertThat("wsFactory.toString()", wsFactory.toString(), notNullValue());
}
finally
{
setLogLevel(WebSocketServerFactory.class, wsFactoryLevel);
setLogLevel(AbstractLifeCycle.class, abstractLifecycleLevel);
setLogLevel(ContainerLifeCycle.class, containerLifecycleLevel);
}
}
}

View File

@ -54,6 +54,7 @@ public class AnnotatedEchoTest
public void testEcho() throws Exception
{
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
server.addBean(container); // allow to shutdown with server Session session = null;
Session session = null;
try
{

View File

@ -129,6 +129,7 @@ public class AnnotatedEndpointConfigTest
// Connect client
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
server.addBean(container); // allow to shutdown with server
socket = new AnnotatedEndpointClient();
session = container.connectToServer(socket,serverUri);

View File

@ -81,6 +81,7 @@ public class ConfiguratorTest
public void testEndpointHandshakeInfo() throws Exception
{
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
server.addBean(container); // allow to shutdown with server
JsrTrackingEndpoint clientSocket = new JsrTrackingEndpoint();
// Build Config

View File

@ -45,7 +45,6 @@ import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class CookiesTest
@ -73,12 +72,6 @@ public class CookiesTest
server.stop();
}
@Before
public void resetClientContainer() throws Exception
{
JettyClientContainerProvider.stop();
}
@Test
public void testCookiesAreSentToServer() throws Exception
{
@ -111,6 +104,7 @@ public class CookiesTest
});
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
server.addBean(container); // allow it to stop
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
builder.configurator(new ClientEndpointConfig.Configurator()
@ -154,6 +148,7 @@ public class CookiesTest
});
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
server.addBean(container); // allow it to stop
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
builder.configurator(new ClientEndpointConfig.Configurator()

View File

@ -24,33 +24,88 @@ import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import javax.websocket.ContainerProvider;
import javax.websocket.WebSocketContainer;
import org.eclipse.jetty.websocket.jsr356.JettyClientContainerProvider;
import org.eclipse.jetty.websocket.tests.server.jsr356.DelayedStartClientOnServerTest;
import org.junit.Before;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.After;
import org.junit.Test;
public class DelayedStartClientTest
{
@Before
public void stopClientContainer() throws Exception
WebSocketContainer container;
@After
public void stopContainer() throws Exception
{
JettyClientContainerProvider.stop();
((LifeCycle)container).stop();
}
@Test
public void testNoExtraHttpClientThreads()
{
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container = ContainerProvider.getWebSocketContainer();
assertThat("Container", container, notNullValue());
List<String> threadNames = DelayedStartClientOnServerTest.getThreadNames(JettyClientContainerProvider.getInstance());
List<String> threadNames = getThreadNames((ContainerLifeCycle)container);
assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@"))));
assertThat("Threads", threadNames, not(hasItem(containsString("HttpClient@"))));
assertThat("Threads", threadNames, not(hasItem(containsString("Jsr356Client@"))));
}
public static List<String> getThreadNames(ContainerLifeCycle... containers)
{
List<String> threadNames = new ArrayList<>();
Set<Object> seen = new HashSet<>();
for (ContainerLifeCycle container : containers)
{
if (container == null)
{
continue;
}
findConfiguredThreadNames(seen, threadNames, container);
}
seen.clear();
// System.out.println("Threads: " + threadNames.stream().collect(Collectors.joining(", ", "[", "]")));
return threadNames;
}
private static void findConfiguredThreadNames(Set<Object> seen, List<String> threadNames, ContainerLifeCycle container)
{
if (seen.contains(container))
{
// skip
return;
}
seen.add(container);
Collection<Executor> executors = container.getBeans(Executor.class);
for (Executor executor : executors)
{
if (executor instanceof QueuedThreadPool)
{
QueuedThreadPool qtp = (QueuedThreadPool) executor;
threadNames.add(qtp.getName());
}
else
{
System.err.println("### Executor: " + executor);
}
}
for (ContainerLifeCycle child : container.getBeans(ContainerLifeCycle.class))
{
findConfiguredThreadNames(seen, threadNames, child);
}
}
}

View File

@ -41,8 +41,10 @@ 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.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
@ -102,10 +104,16 @@ public class MessageReceivingTest {
}
@Before
public void configureTest() {
public void initClient() {
container = ContainerProvider.getWebSocketContainer();
}
@After
public void stopClient() throws Exception
{
((LifeCycle)container).stop();
}
/**
* Method tests receiving of text messages at once.
*

View File

@ -96,6 +96,7 @@ public class MisbehavingClassTest
public void testEndpointRuntimeOnOpen() throws Exception
{
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
server.addBean(container); // allow to shutdown with server
EndpointRuntimeOnOpen socket = new EndpointRuntimeOnOpen();
try (StacklessLogging ignored = new StacklessLogging(EndpointRuntimeOnOpen.class, WebSocketSession.class))
@ -118,6 +119,7 @@ public class MisbehavingClassTest
public void testAnnotatedRuntimeOnOpen() throws Exception
{
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
server.addBean(container); // allow to shutdown with server
AnnotatedRuntimeOnOpen socket = new AnnotatedRuntimeOnOpen();
try (StacklessLogging ignored = new StacklessLogging(AnnotatedRuntimeOnOpen.class, WebSocketSession.class))

View File

@ -58,10 +58,9 @@ import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.websocket.api.util.WSURI;
import org.eclipse.jetty.websocket.jsr356.JettyClientContainerProvider;
import org.eclipse.jetty.websocket.jsr356.ClientContainer;
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@ -77,12 +76,6 @@ public class DelayedStartClientOnServerTest
}
}
@Before
public void stopClientContainer() throws Exception
{
JettyClientContainerProvider.stop();
}
/**
* Using the Client specific techniques of JSR356, connect to the echo socket
* and perform an echo request.
@ -228,9 +221,7 @@ public class DelayedStartClientOnServerTest
try
{
server.start();
List<String> threadNames = getThreadNames(server);
assertNoHttpClientPoolThreads(threadNames);
assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@"))));
assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketClient@"))));
@ -259,9 +250,9 @@ public class DelayedStartClientOnServerTest
String response = GET(server.getURI().resolve("/connect"));
assertThat("Response", response, startsWith("Connected to ws://"));
List<String> threadNames = getThreadNames(server, JettyClientContainerProvider.getInstance());
List<String> threadNames = getThreadNames(server, (ContainerLifeCycle)container);
assertNoHttpClientPoolThreads(threadNames);
assertThat("Threads", threadNames, hasItem(containsString("WebSocketClient@")));
assertThat("Threads", threadNames, hasItem(containsString("WebSocketContainer@")));
}
finally
{
@ -284,8 +275,7 @@ public class DelayedStartClientOnServerTest
server.start();
String response = GET(server.getURI().resolve("/connect"));
assertThat("Response", response, startsWith("Connected to ws://"));
List<String> threadNames = getThreadNames(server, JettyClientContainerProvider.getInstance());
List<String> threadNames = getThreadNames((ContainerLifeCycle)container, server);
assertNoHttpClientPoolThreads(threadNames);
assertThat("Threads", threadNames, hasItem(containsString("WebSocketClient@")));
}
@ -309,9 +299,8 @@ public class DelayedStartClientOnServerTest
{
server.start();
String response = GET(server.getURI().resolve("/configure"));
assertThat("Response", response, startsWith("Configured " + ServerContainer.class.getName()));
List<String> threadNames = getThreadNames(server, JettyClientContainerProvider.getInstance());
assertThat("Response", response, startsWith("Configured " + ClientContainer.class.getName()));
List<String> threadNames = getThreadNames((ContainerLifeCycle)container, server);
assertNoHttpClientPoolThreads(threadNames);
assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@"))));
assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketClient@"))));
@ -338,8 +327,7 @@ public class DelayedStartClientOnServerTest
server.start();
String response = GET(server.getURI().resolve("/configure"));
assertThat("Response", response, startsWith("Configured " + ServerContainer.class.getName()));
List<String> threadNames = getThreadNames(server, JettyClientContainerProvider.getInstance());
List<String> threadNames = getThreadNames((ContainerLifeCycle)container, server);
assertNoHttpClientPoolThreads(threadNames);
assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@"))));
assertThat("Threads", threadNames, not(hasItem(containsString("Jsr356Client@"))));