Skip to content

Commit

Permalink
Issue #5320 - use HttpClient classloader to load jetty-websocket-http…
Browse files Browse the repository at this point in the history
…client.xml

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Oct 15, 2020
1 parent 6cd70ce commit 1b07c84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
5 changes: 0 additions & 5 deletions jetty-websocket/websocket-client/pom.xml
Expand Up @@ -24,11 +24,6 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
Expand Down
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppClassLoader;
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
import org.eclipse.jetty.xml.XmlConfiguration;

Expand All @@ -42,25 +41,19 @@ public static HttpClient get(@SuppressWarnings("unused") WebSocketContainerScope
if (resource == null)
return null;

// Try to load a HttpClient from a jetty-websocket-httpclient.xml configuration file.
// If WebAppClassLoader run with server class access, otherwise run normally.
try
{
try
{
return WebAppClassLoader.runWithServerClassAccess(() -> newHttpClient(resource));
}
catch (NoClassDefFoundError | ClassNotFoundException e)
{
if (LOG.isDebugEnabled())
LOG.debug("Could not use WebAppClassLoader to run with Server class access", e);
return newHttpClient(resource);
}
Thread.currentThread().setContextClassLoader(HttpClient.class.getClassLoader());
return newHttpClient(resource);
}
catch (Throwable t)
{
LOG.warn("Failure to load HttpClient from XML", t);
}
finally
{
Thread.currentThread().setContextClassLoader(contextClassLoader);
}

return null;
}
Expand Down

0 comments on commit 1b07c84

Please sign in to comment.