From 1b07c846c6bcca81f11f662c746d5cf52fd77353 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 15 Oct 2020 16:15:20 +1100 Subject: [PATCH] Issue #5320 - use HttpClient classloader to load jetty-websocket-httpclient.xml Signed-off-by: Lachlan Roberts --- jetty-websocket/websocket-client/pom.xml | 5 ----- .../client/XmlBasedHttpClientProvider.java | 19 ++++++------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/jetty-websocket/websocket-client/pom.xml b/jetty-websocket/websocket-client/pom.xml index 9e4608bd5226..14cad877ad8b 100644 --- a/jetty-websocket/websocket-client/pom.xml +++ b/jetty-websocket/websocket-client/pom.xml @@ -24,11 +24,6 @@ org.eclipse.jetty jetty-xml ${project.version} - - - org.eclipse.jetty - jetty-webapp - ${project.version} true diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/XmlBasedHttpClientProvider.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/XmlBasedHttpClientProvider.java index 44b21f01e33c..93e347c66c9e 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/XmlBasedHttpClientProvider.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/XmlBasedHttpClientProvider.java @@ -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; @@ -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; }