mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-01 11:29:29 +00:00
Issue #5320 - fix the XmlHttpClientProvider for jetty 10, re-enable tests
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
64655f7b7e
commit
8d21bb7b63
@ -20,23 +20,15 @@ package org.eclipse.jetty.websocket.core.client;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public interface HttpClientProvider
|
||||
{
|
||||
static HttpClient get()
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpClientProvider xmlProvider = new XmlHttpClientProvider();
|
||||
HttpClient client = xmlProvider.newHttpClient();
|
||||
if (client != null)
|
||||
return client;
|
||||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
LoggerFactory.getLogger(HttpClientProvider.class).trace("IGNORED", x);
|
||||
}
|
||||
HttpClientProvider xmlProvider = new XmlHttpClientProvider();
|
||||
HttpClient client = xmlProvider.newHttpClient();
|
||||
if (client != null)
|
||||
return client;
|
||||
|
||||
return HttpClientProvider.newDefaultHttpClient();
|
||||
}
|
||||
|
@ -33,12 +33,27 @@ class XmlHttpClientProvider implements HttpClientProvider
|
||||
@Override
|
||||
public HttpClient newHttpClient()
|
||||
{
|
||||
URL resource = Thread.currentThread().getContextClassLoader().getResource("jetty-websocket-httpclient.xml");
|
||||
if (resource == null)
|
||||
{
|
||||
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (contextClassLoader == 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
|
||||
{
|
||||
XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(resource));
|
||||
@ -46,7 +61,7 @@ class XmlHttpClientProvider implements HttpClientProvider
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
LOG.warn("Unable to load: {}", resource, t);
|
||||
LOG.warn("Failure to load HttpClient from XML {}", resource, t);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -47,7 +47,6 @@ import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketListener;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledOnJre;
|
||||
import org.junit.jupiter.api.condition.DisabledOnOs;
|
||||
@ -376,7 +375,6 @@ public class DistributionTests extends AbstractJettyHomeTest
|
||||
}
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"http", "https"})
|
||||
public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Exception
|
||||
@ -389,11 +387,12 @@ public class DistributionTests extends AbstractJettyHomeTest
|
||||
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
|
||||
.build();
|
||||
|
||||
String module = "https".equals(scheme) ? "test-keystore," + scheme : scheme;
|
||||
String[] args1 = {
|
||||
"--create-startd",
|
||||
"--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))
|
||||
{
|
||||
assertTrue(run1.awaitFor(5, TimeUnit.SECONDS));
|
||||
@ -406,6 +405,9 @@ public class DistributionTests extends AbstractJettyHomeTest
|
||||
String[] args2 = {
|
||||
"jetty.http.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",
|
||||
};
|
||||
|
||||
@ -425,7 +427,6 @@ public class DistributionTests extends AbstractJettyHomeTest
|
||||
}
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"http", "https"})
|
||||
public void testWebsocketClientInWebapp(String scheme) throws Exception
|
||||
|
@ -13,6 +13,15 @@
|
||||
<name>Test :: Jetty Websocket Simple Webapp with WebSocketClient</name>
|
||||
|
||||
<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>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-servlet-api</artifactId>
|
||||
|
@ -13,6 +13,15 @@
|
||||
<name>Test :: Jetty Websocket Simple Webapp with WebSocketClient</name>
|
||||
|
||||
<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>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-servlet-api</artifactId>
|
||||
|
Loading…
x
Reference in New Issue
Block a user