Issue #5320 - use HttpClient classloader to load jetty-websocket-httpclient.xml

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-10-15 16:15:20 +11:00
parent 6cd70ce136
commit 1b07c846c6
2 changed files with 6 additions and 18 deletions

View File

@ -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>

View File

@ -24,7 +24,6 @@ import org.eclipse.jetty.client.HttpClient;
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;
@ -42,25 +41,19 @@ class XmlBasedHttpClientProvider
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;
}