diff --git a/jetty-home/pom.xml b/jetty-home/pom.xml index 54e2be936e09..0397b02b90cf 100644 --- a/jetty-home/pom.xml +++ b/jetty-home/pom.xml @@ -655,6 +655,11 @@ websocket-jetty-server ${project.version} + + org.eclipse.jetty.websocket + websocket-jetty-client + ${project.version} + org.eclipse.jetty.websocket websocket-javax-server diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java index 8db88e052e85..b303f9fba118 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java @@ -30,6 +30,7 @@ import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.statistic.CounterStatistic; +import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppContext; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; @@ -74,6 +75,12 @@ public AnnotationConfiguration() { } + @Override + public Class replaces() + { + return org.eclipse.jetty.annotations.AnnotationConfiguration.class; + } + /** * This parser scans the bundles using the OSGi APIs instead of assuming a jar. */ diff --git a/jetty-websocket/websocket-core-client/src/main/config/modules/websocket.mod b/jetty-websocket/websocket-core-client/src/main/config/modules/websocket.mod deleted file mode 100644 index bc693b7e3d1a..000000000000 --- a/jetty-websocket/websocket-core-client/src/main/config/modules/websocket.mod +++ /dev/null @@ -1,11 +0,0 @@ -# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Enables both Jetty and javax websocket modules for deployed web applications. - -[tags] -websocket - -[depend] -websocket-jetty -websocket-javax diff --git a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpClientProvider.java b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpClientProvider.java index 194cddab347d..935e768482e9 100644 --- a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpClientProvider.java +++ b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/HttpClientProvider.java @@ -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(); } diff --git a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/XmlHttpClientProvider.java b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/XmlHttpClientProvider.java index 266613853000..af9962bc3d36 100644 --- a/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/XmlHttpClientProvider.java +++ b/jetty-websocket/websocket-core-client/src/main/java/org/eclipse/jetty/websocket/core/client/XmlHttpClientProvider.java @@ -33,12 +33,27 @@ 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)); @@ -46,7 +61,7 @@ public HttpClient newHttpClient() } catch (Throwable t) { - LOG.warn("Unable to load: {}", resource, t); + LOG.warn("Failure to load HttpClient from XML {}", resource, t); } return null; diff --git a/jetty-websocket/websocket-core-common/src/main/config/modules/websocket.mod b/jetty-websocket/websocket-core-common/src/main/config/modules/websocket.mod deleted file mode 100644 index 97974ff6319e..000000000000 --- a/jetty-websocket/websocket-core-common/src/main/config/modules/websocket.mod +++ /dev/null @@ -1,11 +0,0 @@ -# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Enable both Jetty and javax websocket modules for deployed web applications. - -[tags] -websocket - -[depend] -websocket-jetty -websocket-javax diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketConfiguration.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketConfiguration.java index 6075eeb66e34..a6ab2692f04e 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketConfiguration.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketConfiguration.java @@ -28,8 +28,7 @@ /** *

Websocket Configuration

*

This configuration configures the WebAppContext server/system classes to - * be able to see the org.eclipse.jetty.websocket package. - *

+ * be able to see the {@code org.eclipse.jetty.websocket.javax} packages.

*/ public class JavaxWebSocketConfiguration extends AbstractConfiguration { @@ -37,6 +36,7 @@ public JavaxWebSocketConfiguration() { addDependencies(WebXmlConfiguration.class, MetaInfConfiguration.class, WebInfConfiguration.class, FragmentConfiguration.class); addDependents("org.eclipse.jetty.annotations.AnnotationConfiguration", WebAppConfiguration.class.getName()); + protectAndExpose("org.eclipse.jetty.websocket.util.server."); // For WebSocketUpgradeFilter protectAndExpose("org.eclipse.jetty.websocket.javax.server.config."); protectAndExpose("org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainerProvider"); diff --git a/jetty-websocket/websocket-jetty-client/pom.xml b/jetty-websocket/websocket-jetty-client/pom.xml index cc3c39db8324..c4226c69b7bd 100644 --- a/jetty-websocket/websocket-jetty-client/pom.xml +++ b/jetty-websocket/websocket-jetty-client/pom.xml @@ -35,6 +35,12 @@ jetty-client ${project.version}
+ + org.eclipse.jetty + jetty-webapp + ${project.version} + true + org.slf4j slf4j-api diff --git a/jetty-websocket/websocket-jetty-client/src/main/config/modules/websocket-jetty-client.mod b/jetty-websocket/websocket-jetty-client/src/main/config/modules/websocket-jetty-client.mod new file mode 100644 index 000000000000..0e35bf32ce45 --- /dev/null +++ b/jetty-websocket/websocket-jetty-client/src/main/config/modules/websocket-jetty-client.mod @@ -0,0 +1,24 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Expose the Jetty WebSocket Client classes to deployed web applications. + +[tags] +websocket + +[depend] +client +annotations + +[lib] +lib/websocket/websocket-core-common-${jetty.version}.jar +lib/websocket/websocket-core-client-${jetty.version}.jar +lib/websocket/websocket-util-${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 + +[jpms] +# The implementation needs to access method handles in +# classes that are in the web application classloader. +add-reads: org.eclipse.jetty.websocket.jetty.common=ALL-UNNAMED diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/module-info.java b/jetty-websocket/websocket-jetty-client/src/main/java/module-info.java index 27c6f8600c36..9481ff8b0c34 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/module-info.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/module-info.java @@ -20,6 +20,7 @@ { exports org.eclipse.jetty.websocket.client; + requires static org.eclipse.jetty.webapp; requires org.eclipse.jetty.websocket.core.client; requires org.eclipse.jetty.websocket.jetty.common; requires org.slf4j; diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/config/JettyWebSocketClientConfiguration.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/config/JettyWebSocketClientConfiguration.java new file mode 100644 index 000000000000..ec754ec93174 --- /dev/null +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/config/JettyWebSocketClientConfiguration.java @@ -0,0 +1,49 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.client.config; + +import org.eclipse.jetty.webapp.AbstractConfiguration; +import org.eclipse.jetty.webapp.FragmentConfiguration; +import org.eclipse.jetty.webapp.MetaInfConfiguration; +import org.eclipse.jetty.webapp.WebAppConfiguration; +import org.eclipse.jetty.webapp.WebInfConfiguration; +import org.eclipse.jetty.webapp.WebXmlConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *

Websocket Configuration

+ *

This configuration configures the WebAppContext server/system classes to + * be able to see the {@code org.eclipse.jetty.websocket.client} package.

+ */ +public class JettyWebSocketClientConfiguration extends AbstractConfiguration +{ + private static final Logger LOG = LoggerFactory.getLogger(JettyWebSocketClientConfiguration.class); + + public JettyWebSocketClientConfiguration() + { + addDependencies(WebXmlConfiguration.class, MetaInfConfiguration.class, WebInfConfiguration.class, FragmentConfiguration.class); + addDependents("org.eclipse.jetty.annotations.AnnotationConfiguration", WebAppConfiguration.class.getName()); + + protectAndExpose("org.eclipse.jetty.websocket.api."); + protectAndExpose("org.eclipse.jetty.websocket.client."); + hide("org.eclipse.jetty.client.impl."); + hide("org.eclipse.jetty.client.config."); + } +} diff --git a/jetty-websocket/websocket-jetty-client/src/main/resources/META-INF/services/org.eclipse.jetty.webapp.Configuration b/jetty-websocket/websocket-jetty-client/src/main/resources/META-INF/services/org.eclipse.jetty.webapp.Configuration new file mode 100644 index 000000000000..376b7dbf6edc --- /dev/null +++ b/jetty-websocket/websocket-jetty-client/src/main/resources/META-INF/services/org.eclipse.jetty.webapp.Configuration @@ -0,0 +1 @@ +org.eclipse.jetty.websocket.client.config.JettyWebSocketClientConfiguration \ No newline at end of file diff --git a/jetty-websocket/websocket-jetty-server/src/main/config/modules/websocket-jetty.mod b/jetty-websocket/websocket-jetty-server/src/main/config/modules/websocket-jetty.mod index 5c24a906fb5a..8194e1e74889 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/config/modules/websocket-jetty.mod +++ b/jetty-websocket/websocket-jetty-server/src/main/config/modules/websocket-jetty.mod @@ -7,12 +7,10 @@ Enable the Jetty WebSocket API for deployed web applications. websocket [depend] -client annotations [lib] lib/websocket/websocket-core-common-${jetty.version}.jar -lib/websocket/websocket-core-client-${jetty.version}.jar lib/websocket/websocket-core-server-${jetty.version}.jar lib/websocket/websocket-util-${jetty.version}.jar lib/websocket/websocket-util-server-${jetty.version}.jar diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketConfiguration.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketConfiguration.java index a2caa2480b28..5115c0005e0c 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketConfiguration.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketConfiguration.java @@ -18,11 +18,7 @@ package org.eclipse.jetty.websocket.server.config; -import java.util.ServiceLoader; - -import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.webapp.AbstractConfiguration; -import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.FragmentConfiguration; import org.eclipse.jetty.webapp.MetaInfConfiguration; import org.eclipse.jetty.webapp.WebAppConfiguration; @@ -34,12 +30,8 @@ /** *

Websocket Configuration

*

This configuration configures the WebAppContext server/system classes to - * be able to see the org.eclipse.jetty.websocket package. - * This class is defined in the webapp package, as it implements the {@link Configuration} interface, - * which is unknown to the websocket package. However, the corresponding {@link ServiceLoader} - * resource is defined in the websocket package, so that this configuration only be - * loaded if the jetty-websocket jars are on the classpath. - *

+ * be able to see the {@code org.eclipse.jetty.websocket.api}, {@code org.eclipse.jetty.websocket.server} and + * {@code org.eclipse.jetty.websocket.util.server} packages.

*/ public class JettyWebSocketConfiguration extends AbstractConfiguration { @@ -48,39 +40,12 @@ public class JettyWebSocketConfiguration extends AbstractConfiguration public JettyWebSocketConfiguration() { addDependencies(WebXmlConfiguration.class, MetaInfConfiguration.class, WebInfConfiguration.class, FragmentConfiguration.class); + addDependents("org.eclipse.jetty.annotations.AnnotationConfiguration", WebAppConfiguration.class.getName()); - if (isAvailable("org.eclipse.jetty.osgi.annotations.AnnotationConfiguration")) - addDependents("org.eclipse.jetty.osgi.annotations.AnnotationConfiguration", WebAppConfiguration.class.getName()); - else if (isAvailable("org.eclipse.jetty.annotations.AnnotationConfiguration")) - addDependents("org.eclipse.jetty.annotations.AnnotationConfiguration", WebAppConfiguration.class.getName()); - else - throw new RuntimeException("Unable to add AnnotationConfiguration dependent (not present in classpath)"); - - protectAndExpose( - "org.eclipse.jetty.websocket.api.", - "org.eclipse.jetty.websocket.server.", - "org.eclipse.jetty.websocket.util.server."); // For WebSocketUpgradeFilter - - hide("org.eclipse.jetty.server.internal.", - "org.eclipse.jetty.server.config."); - } - - @Override - public boolean isAvailable() - { - return isAvailable("org.eclipse.jetty.websocket.common.JettyWebSocketFrame"); - } - - private boolean isAvailable(String classname) - { - try - { - return Loader.loadClass(classname) != null; - } - catch (Throwable e) - { - LOG.trace("IGNORED", e); - return false; - } + protectAndExpose("org.eclipse.jetty.websocket.api."); + protectAndExpose("org.eclipse.jetty.websocket.server."); + protectAndExpose("org.eclipse.jetty.websocket.util.server."); // For WebSocketUpgradeFilter + hide("org.eclipse.jetty.server.internal."); + hide("org.eclipse.jetty.server.config."); } } diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java index 64ae2dc689b6..cd84e13f3972 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java @@ -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; @@ -129,7 +128,7 @@ public void testQuickStartGenerationAndRun() throws Exception Path quickstartWebXml = webInf.resolve("quickstart-web.xml"); assertTrue(Files.exists(quickstartWebXml)); assertNotEquals(0, Files.size(quickstartWebXml)); - + int port = distribution.freePort(); try (JettyHomeTester.Run run3 = distribution.start("jetty.http.port=" + port, "jetty.quickstart.mode=QUICKSTART")) @@ -145,7 +144,7 @@ public void testQuickStartGenerationAndRun() throws Exception } } } - + @Test public void testSimpleWebAppWithJSP() throws Exception { @@ -376,7 +375,6 @@ public void testLog4j2ModuleWithSimpleWebAppWithJSP() throws Exception } } - @Disabled @ParameterizedTest @ValueSource(strings = {"http", "https"}) public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Exception @@ -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,websocket-jetty-client," + module, + }; try (JettyHomeTester.Run run1 = distribution.start(args1)) { assertTrue(run1.awaitFor(5, TimeUnit.SECONDS)); @@ -425,7 +424,6 @@ public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Ex } } - @Disabled @ParameterizedTest @ValueSource(strings = {"http", "https"}) public void testWebsocketClientInWebapp(String scheme) throws Exception @@ -457,7 +455,7 @@ public void testWebsocketClientInWebapp(String scheme) throws Exception "jetty.http.port=" + port, "jetty.ssl.port=" + port, // "jetty.server.dumpAfterStart=true", - }; + }; try (JettyHomeTester.Run run2 = distribution.start(args2)) { @@ -515,8 +513,8 @@ public void testWebAppWithProxyAndJPMS() throws Exception /** * This reproduces some classloading issue with MethodHandles in JDK14-15, this has been fixed in JDK16. - * @see JDK-8244090 * @throws Exception if there is an error during the test. + * @see JDK-8244090 */ @ParameterizedTest @ValueSource(strings = {"", "--jpms"}) @@ -641,5 +639,4 @@ public void testStartStopLog4j2Modules() throws Exception } } } - } diff --git a/tests/test-webapps/test-websocket-client-provided-webapp/pom.xml b/tests/test-webapps/test-websocket-client-provided-webapp/pom.xml index 1ba112c51714..bcbf1c1e5415 100644 --- a/tests/test-webapps/test-websocket-client-provided-webapp/pom.xml +++ b/tests/test-webapps/test-websocket-client-provided-webapp/pom.xml @@ -13,6 +13,15 @@ Test :: Jetty Websocket Simple Webapp with WebSocketClient + + org.slf4j + slf4j-api + + + org.eclipse.jetty + jetty-slf4j-impl + compile + org.eclipse.jetty.toolchain jetty-servlet-api diff --git a/tests/test-webapps/test-websocket-client-webapp/pom.xml b/tests/test-webapps/test-websocket-client-webapp/pom.xml index 92f0054a2a53..3893cd7a350c 100644 --- a/tests/test-webapps/test-websocket-client-webapp/pom.xml +++ b/tests/test-webapps/test-websocket-client-webapp/pom.xml @@ -13,6 +13,15 @@ Test :: Jetty Websocket Simple Webapp with WebSocketClient + + org.slf4j + slf4j-api + + + org.eclipse.jetty + jetty-slf4j-impl + compile + org.eclipse.jetty.toolchain jetty-servlet-api