Issue #5320 - fix the XmlHttpClientProvider for jetty 10, re-enable tests

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-11-03 17:17:27 +11:00
parent 64655f7b7e
commit 8d21bb7b63
5 changed files with 48 additions and 22 deletions

View File

@ -20,23 +20,15 @@ package org.eclipse.jetty.websocket.core.client;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.slf4j.LoggerFactory;
public interface HttpClientProvider public interface HttpClientProvider
{ {
static HttpClient get() static HttpClient get()
{ {
try HttpClientProvider xmlProvider = new XmlHttpClientProvider();
{ HttpClient client = xmlProvider.newHttpClient();
HttpClientProvider xmlProvider = new XmlHttpClientProvider(); if (client != null)
HttpClient client = xmlProvider.newHttpClient(); return client;
if (client != null)
return client;
}
catch (Throwable x)
{
LoggerFactory.getLogger(HttpClientProvider.class).trace("IGNORED", x);
}
return HttpClientProvider.newDefaultHttpClient(); return HttpClientProvider.newDefaultHttpClient();
} }

View File

@ -33,12 +33,27 @@ class XmlHttpClientProvider implements HttpClientProvider
@Override @Override
public HttpClient newHttpClient() public HttpClient newHttpClient()
{ {
URL resource = Thread.currentThread().getContextClassLoader().getResource("jetty-websocket-httpclient.xml"); ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (resource == null) if (contextClassLoader == null)
{
return null; return null;
}
URL resource = contextClassLoader.getResource("jetty-websocket-httpclient.xml");
if (resource == null)
return null;
try
{
Thread.currentThread().setContextClassLoader(HttpClient.class.getClassLoader());
return newHttpClient(resource);
}
finally
{
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
private static HttpClient newHttpClient(URL resource)
{
try try
{ {
XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(resource)); XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(resource));
@ -46,7 +61,7 @@ class XmlHttpClientProvider implements HttpClientProvider
} }
catch (Throwable t) catch (Throwable t)
{ {
LOG.warn("Unable to load: {}", resource, t); LOG.warn("Failure to load HttpClient from XML {}", resource, t);
} }
return null; return null;

View File

@ -47,7 +47,6 @@ import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketListener; import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre; import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.DisabledOnOs;
@ -376,7 +375,6 @@ public class DistributionTests extends AbstractJettyHomeTest
} }
} }
@Disabled
@ParameterizedTest @ParameterizedTest
@ValueSource(strings = {"http", "https"}) @ValueSource(strings = {"http", "https"})
public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Exception public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Exception
@ -389,11 +387,12 @@ public class DistributionTests extends AbstractJettyHomeTest
.mavenLocalRepository(System.getProperty("mavenRepoPath")) .mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build(); .build();
String module = "https".equals(scheme) ? "test-keystore," + scheme : scheme;
String[] args1 = { String[] args1 = {
"--create-startd", "--create-startd",
"--approve-all-licenses", "--approve-all-licenses",
"--add-to-start=resources,server,webapp,deploy,jsp,jmx,servlet,servlets,websocket,test-keystore," + scheme "--add-to-start=resources,server,webapp,deploy,jsp,jmx,servlet,servlets,websocket," + module,
}; };
try (JettyHomeTester.Run run1 = distribution.start(args1)) try (JettyHomeTester.Run run1 = distribution.start(args1))
{ {
assertTrue(run1.awaitFor(5, TimeUnit.SECONDS)); assertTrue(run1.awaitFor(5, TimeUnit.SECONDS));
@ -406,6 +405,9 @@ public class DistributionTests extends AbstractJettyHomeTest
String[] args2 = { String[] args2 = {
"jetty.http.port=" + port, "jetty.http.port=" + port,
"jetty.ssl.port=" + port, "jetty.ssl.port=" + port,
// We need to expose the websocket client classes to the webapp for this to work.
"jetty.webapp.addServerClasses+=,-org.eclipse.jetty.websocket.client.",
"jetty.webapp.addSystemClasses+=,+org.eclipse.jetty.websocket.client.",
// "jetty.server.dumpAfterStart=true", // "jetty.server.dumpAfterStart=true",
}; };
@ -425,7 +427,6 @@ public class DistributionTests extends AbstractJettyHomeTest
} }
} }
@Disabled
@ParameterizedTest @ParameterizedTest
@ValueSource(strings = {"http", "https"}) @ValueSource(strings = {"http", "https"})
public void testWebsocketClientInWebapp(String scheme) throws Exception public void testWebsocketClientInWebapp(String scheme) throws Exception

View File

@ -13,6 +13,15 @@
<name>Test :: Jetty Websocket Simple Webapp with WebSocketClient</name> <name>Test :: Jetty Websocket Simple Webapp with WebSocketClient</name>
<dependencies> <dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-servlet-api</artifactId> <artifactId>jetty-servlet-api</artifactId>

View File

@ -13,6 +13,15 @@
<name>Test :: Jetty Websocket Simple Webapp with WebSocketClient</name> <name>Test :: Jetty Websocket Simple Webapp with WebSocketClient</name>
<dependencies> <dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-servlet-api</artifactId> <artifactId>jetty-servlet-api</artifactId>