Skip to content

Commit

Permalink
[Fixes #1743] Full upgrade of Pax Web 8 to Pax Web 9 with Jetty 10 - …
Browse files Browse the repository at this point in the history
…all tests pass on JDK11+
  • Loading branch information
grgrzybek committed Sep 2, 2022
1 parent bafb02a commit 37a34a9
Show file tree
Hide file tree
Showing 66 changed files with 407 additions and 314 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface PaxWebConstants {
* The only supported {@link javax.servlet.ServletContainerInitializer} class that configures WebSocket
* container for Jetty
*/
String DEFAULT_WEBSOCKET_JETTY_SCI_CLASS = "org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer";
String DEFAULT_WEBSOCKET_JETTY_SCI_CLASS = "org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer";
/**
* The only supported {@link javax.servlet.ServletContainerInitializer} class that configures WebSocket
* container for Tomcat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public class WarExtenderContext implements WebContainerListener, ReportViewPlugi
"tagsoup-*.jar",
"tools.jar",
"websocket-api.jar",
"websocket-jetty-api.jar",
"wsdl4j*.jar",
"xercesImpl.jar",
"xml-apis.jar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.ops4j.pax.web.extender.war.internal.model;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -1813,7 +1814,7 @@ private void buildModel() {
Class<EventListener> listenerClass;
try {
listenerClass = (Class<EventListener>) classLoader.loadClass(listener);
EventListener eventListener = listenerClass.newInstance();
EventListener eventListener = listenerClass.getConstructor().newInstance();
EventListenerModel elm = new EventListenerModel(eventListener);
elm.setRegisteringBundle(bundle);
elm.addContextModel(ocm);
Expand All @@ -1824,7 +1825,7 @@ private void buildModel() {
wabBatch.addEventListenerModel(elm);
} catch (ClassNotFoundException e) {
LOG.warn("Can't load listener class {} in the context of {}: {}", listener, this, e.getMessage(), e);
} catch (InstantiationException | IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
LOG.warn("Can't instantiate listener class {} in the context of {}: {}", listener, this, e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -859,10 +860,11 @@ private void loadSCI(URL url, Bundle bundle, List<ServletContainerInitializer> s
if (name.length() > 0) {
try {
Class<?> sciClass = bundle.loadClass(name);
ServletContainerInitializer sci = (ServletContainerInitializer) sciClass.newInstance();
ServletContainerInitializer sci = (ServletContainerInitializer) sciClass.getConstructor().newInstance();
LOG.trace(" Loaded SCI {}", sci.getClass());
scis.add(sci);
} catch (ClassNotFoundException | ClassCastException | InstantiationException | IllegalAccessException e) {
} catch (ClassNotFoundException | ClassCastException | InstantiationException |
IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
LOG.error(" Problem loading SCI class from {}: {}", url, e.getMessage(), e);
}
}
Expand Down
9 changes: 2 additions & 7 deletions pax-web-features/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<descriptor>mvn:org.ops4j.pax.web/pax-web-features</descriptor>
</blacklistedDescriptors>
<distribution>org.apache.karaf.features:framework</distribution>
<javase>1.8</javase>
<javase>11</javase>
<framework>
<feature>framework</feature>
</framework>
Expand All @@ -100,8 +100,7 @@
<feature>pax-web-jetty-websockets</feature>
<feature>pax-web-jetty-extras</feature>
<feature>pax-web-jetty-http2</feature>
<!-- <feature>pax-web-jetty-http2-jdk8</feature>-->
<!-- <feature>pax-web-jetty-http2-jdk9</feature>-->
<feature>pax-web-jetty-http2-jdk9</feature>
<feature>pax-web-http-jetty</feature>
<feature>pax-web-tomcat</feature>
<feature>pax-web-tomcat-websockets</feature>
Expand Down Expand Up @@ -190,10 +189,6 @@
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility-el2</artifactId>
</dependency>
<dependency>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility-servlet31</artifactId>
</dependency>
<dependency>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-extender-war</artifactId>
Expand Down
38 changes: 11 additions & 27 deletions pax-web-features/src/main/resources/features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
</details>

<bundle start-level="30">mvn:jakarta.servlet/jakarta.servlet-api/${dependency.jakarta.servlet-api}</bundle>
<bundle start-level="30" start="false">mvn:org.ops4j.pax.web/pax-web-compatibility-servlet31/${project.version}</bundle>

<bundle start-level="30">mvn:org.ops4j.pax.web/pax-web-api/${project.version}</bundle>
<bundle start-level="30">mvn:org.ops4j.pax.web/pax-web-spi/${project.version}</bundle>
Expand All @@ -66,9 +65,9 @@

<feature name="pax-web-jetty" description="Jetty 9 bundles" version="${dependency.org.eclipse.jetty}">
<bundle start-level="30" dependency="true">mvn:jakarta.servlet/jakarta.servlet-api/${dependency.jakarta.servlet-api}</bundle>
<bundle start-level="30" start="false">mvn:org.ops4j.pax.web/pax-web-compatibility-servlet31/${project.version}</bundle>

<bundle start-level="30">mvn:org.eclipse.jetty/jetty-client/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-alpn-client/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-util/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-util-ajax/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-io/${dependency.org.eclipse.jetty}</bundle>
Expand All @@ -78,7 +77,6 @@
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-servlet/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-servlets/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-security/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-continuation/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-jmx/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-jaas/${dependency.org.eclipse.jetty}</bundle>
</feature>
Expand All @@ -98,43 +96,29 @@
<feature name="pax-web-jetty-websockets" description="Jetty 9 bundles for Web Sockets support" version="${dependency.org.eclipse.jetty}">
<feature>pax-web-websockets</feature>
<feature>pax-web-jetty</feature>
<feature>pax-web-http-jetty</feature>

<bundle start-level="30">mvn:org.eclipse.jetty/jetty-client/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/javax-websocket-client-impl/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/javax-websocket-server-impl/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-api/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-common/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-client/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-server/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-alpn-client/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-javax-common/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-javax-client/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-javax-server/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-jetty-api/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-core-common/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-core-client/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-core-server/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.websocket/websocket-servlet/${dependency.org.eclipse.jetty}</bundle>
</feature>

<feature name="pax-web-jetty-http2" description="Jetty 9 bundles for HTTP/2 support" version="${dependency.org.eclipse.jetty}" >
<details>
Before JDK 8u252 org.eclipse.jetty.alpn.ALPN from org.eclipse.jetty.alpn:alpn-api:1.1.3.v20160715
had to be present on boot classpath. It's no longer needed and on newer JDK 8 versions it's enough to
have org.eclipse.jetty:jetty-alpn-openjdk8-server bundle installed.
On JDK9+, have org.eclipse.jetty:jetty-alpn-java-server bundle has to be installed.
So without direct dependency, if pax-web-jetty-http2 feature is installed, additional feature has to be
installed depending on JDK used:
- JDK8: pax-web-jetty-http2-jdk8
- JDK9 and later: pax-web-jetty-http2-jdk9
</details>
<feature>pax-web-jetty</feature>
<feature>pax-web-jetty-http2-jdk9</feature>

<bundle start-level="30">mvn:org.eclipse.jetty.http2/http2-hpack/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.http2/http2-common/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty.http2/http2-server/${dependency.org.eclipse.jetty}</bundle>
</feature>

<feature name="pax-web-jetty-http2-jdk8" description="Jetty 9 bundles for HTTP/2 support (JDK8)" version="${dependency.org.eclipse.jetty}" >
<feature>pax-web-jetty</feature>

<bundle start-level="30">mvn:org.eclipse.jetty.alpn/alpn-api/${dependency.org.eclipse.jetty.alpn}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-alpn-server/${dependency.org.eclipse.jetty}</bundle>
<bundle start-level="30">mvn:org.eclipse.jetty/jetty-alpn-openjdk8-server/${dependency.org.eclipse.jetty}</bundle>
</feature>

<feature name="pax-web-jetty-http2-jdk9" description="Jetty 9 bundles for HTTP/2 support (JDK9+)" version="${dependency.org.eclipse.jetty}" >
<feature>pax-web-jetty</feature>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ protected Option[] paxWebJetty() {
return new Option[] {
mavenBundle("org.ops4j.pax.web", "pax-web-jetty")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("org.ops4j.pax.web", "pax-web-compatibility-servlet31")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1).noStart(),

mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-util").versionAsInProject(),
Expand All @@ -305,8 +303,6 @@ protected Option[] paxWebJetty() {
.artifactId("jetty-servlet").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-security").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-continuation").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-jaas").versionAsInProject()
};
Expand All @@ -327,21 +323,12 @@ protected Option[] paxWebJettyHttp2() {
mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-alpn-server").versionAsInProject()
);
if (javaMajorVersion() >= 9) {
return combine(common,
mavenBundle().groupId("org.eclipse.jetty.alpn")
.artifactId("alpn-api").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-alpn-java-server").versionAsInProject()
);
} else {
return combine(common,
mavenBundle().groupId("org.eclipse.jetty.alpn")
.artifactId("alpn-api").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-alpn-openjdk8-server").versionAsInProject()
);
}
return combine(common,
mavenBundle().groupId("org.eclipse.jetty.alpn")
.artifactId("alpn-api").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-alpn-java-server").versionAsInProject()
);
}

protected Option[] jettyWebSockets() {
Expand All @@ -350,18 +337,22 @@ protected Option[] jettyWebSockets() {
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-client").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty")
.artifactId("jetty-alpn-client").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty.websocket")
.artifactId("websocket-javax-common").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty.websocket")
.artifactId("javax-websocket-client-impl").versionAsInProject(),
.artifactId("websocket-javax-client").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty.websocket")
.artifactId("javax-websocket-server-impl").versionAsInProject(),
.artifactId("websocket-javax-server").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty.websocket")
.artifactId("websocket-api").versionAsInProject(),
.artifactId("websocket-jetty-api").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty.websocket")
.artifactId("websocket-common").versionAsInProject(),
.artifactId("websocket-core-common").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty.websocket")
.artifactId("websocket-client").versionAsInProject(),
.artifactId("websocket-core-client").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty.websocket")
.artifactId("websocket-server").versionAsInProject(),
.artifactId("websocket-core-server").versionAsInProject(),
mavenBundle().groupId("org.eclipse.jetty.websocket")
.artifactId("websocket-servlet").versionAsInProject(),
mavenBundle("org.ops4j.pax.web", "pax-web-websocket")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void setUp() throws Exception {
@Test
public void testSlash() throws Exception {
HttpTestClientFactory.createDefaultTestClient()
.withResponseAssertion("Response must contain 'Hello from JSF 2.3 example running on Pax Web 8'",
resp -> resp.contains("Hello from JSF 2.3 example running on Pax Web 8"))
.withResponseAssertion("Response must contain 'Hello from JSF 2.3 example running on Pax Web 9'",
resp -> resp.contains("Hello from JSF 2.3 example running on Pax Web 9"))
.doGETandExecuteTest("http://127.0.0.1:8181/war-jsf23-embedded/");
}

Expand All @@ -56,8 +56,8 @@ public void testJSF() throws Exception {
LOG.debug("Testing JSF workflow!");
String response = HttpTestClientFactory.createDefaultTestClient()
.useCookieState(cookieState)
.withResponseAssertion("Response must contain 'Hello from JSF 2.3 example running on Pax Web 8'",
resp -> resp.contains("Hello from JSF 2.3 example running on Pax Web 8"))
.withResponseAssertion("Response must contain 'Hello from JSF 2.3 example running on Pax Web 9'",
resp -> resp.contains("Hello from JSF 2.3 example running on Pax Web 9"))
.withResponseAssertion("Response must contain JSF-ViewState-ID",
resp -> {
LOG.debug("Found JSF starting page: {}", resp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class AbstractWebSocketIntegrationTest extends AbstractContainer

@Before
public void setUp() throws Exception {
// Jetty uses org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer SCI that handles:
// Jetty uses org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer SCI that handles:
// - classes implementing javax.websocket.server.ServerApplicationConfig
// - classes implementing javax.websocket.Endpoint
// - classes annotated with @javax.websocket.server.ServerEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
import org.ops4j.pax.web.itest.container.AbstractContainerTestBase;
import org.ops4j.pax.web.itest.utils.web.SimpleWebSocket;
import org.ops4j.pax.web.service.PaxWebConstants;
import org.ops4j.pax.web.service.spi.model.events.EventListenerEventData;
import org.ops4j.pax.web.service.spi.model.events.FilterEventData;
import org.ops4j.pax.web.service.spi.model.events.WebElementEvent;
import org.ops4j.pax.web.service.spi.model.events.WebSocketEventData;
import org.osgi.framework.Bundle;
import org.osgi.framework.wiring.BundleWiring;
import org.slf4j.Logger;
Expand Down Expand Up @@ -68,9 +67,8 @@ public void testWebsocket() throws Exception {
configureAndWait(() -> {
context.registerService(Object.class.getName(), simpleWebSocket, filter);
}, events -> events.stream()
// Tomcat and Undertow - a filter, Jetty - a listener
.anyMatch(ev -> ev.getType() == WebElementEvent.State.DEPLOYED
&& (ev.getData() instanceof FilterEventData || ev.getData() instanceof EventListenerEventData)));
&& (ev.getData() instanceof WebSocketEventData)));

WebSocketContainer cc = getWebSocketContainer();
URI uri = new URI("ws://127.0.0.1:8181/simple");
Expand Down

0 comments on commit 37a34a9

Please sign in to comment.