Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #5320 - using jetty-websocket-httpclient.xml within webapp Jetty 10 #5563

Merged
merged 12 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions jetty-home/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,11 @@
<artifactId>websocket-jetty-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jetty-client</artifactId>
<version>${project.version}</version>
</dependency>
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-server</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,15 @@

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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,35 @@ class XmlHttpClientProvider implements HttpClientProvider
@Override
public HttpClient newHttpClient()
{
URL resource = Thread.currentThread().getContextClassLoader().getResource("jetty-websocket-httpclient.xml");
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));
return (HttpClient)configuration.configure();
}
catch (Throwable t)
{
LOG.warn("Unable to load: {}", resource, t);
LOG.warn("Failure to load HttpClient from XML {}", resource, t);
}

return null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lib/websocket/websocket-util-${jetty.version}.jar
lib/websocket/websocket-util-server-${jetty.version}.jar
lib/websocket/websocket-jetty-api-${jetty.version}.jar
lib/websocket/websocket-jetty-common-${jetty.version}.jar
lib/websocket/websocket-jetty-client-${jetty.version}.jar
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
lib/websocket/websocket-jetty-server-${jetty.version}.jar

[jpms]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
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;
Expand Down Expand Up @@ -376,7 +375,6 @@ public void testLog4j2ModuleWithSimpleWebAppWithJSP() throws Exception
}
}

@Disabled
@ParameterizedTest
@ValueSource(strings = {"http", "https"})
public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Exception
Expand All @@ -389,11 +387,12 @@ public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Ex
.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,
};
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
try (JettyHomeTester.Run run1 = distribution.start(args1))
{
assertTrue(run1.awaitFor(5, TimeUnit.SECONDS));
Expand All @@ -406,6 +405,9 @@ public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Ex
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.",
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
// "jetty.server.dumpAfterStart=true",
};

Expand All @@ -425,7 +427,6 @@ public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Ex
}
}

@Disabled
@ParameterizedTest
@ValueSource(strings = {"http", "https"})
public void testWebsocketClientInWebapp(String scheme) throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
9 changes: 9 additions & 0 deletions tests/test-webapps/test-websocket-client-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down