Skip to content

Commit

Permalink
[#1802] Switch pax-web-jetty from javax to jakarta (deadlocks in HTTP…
Browse files Browse the repository at this point in the history
…/2 tests)
  • Loading branch information
grgrzybek committed Jun 15, 2023
1 parent f624d04 commit 541c375
Show file tree
Hide file tree
Showing 29 changed files with 1,193 additions and 1,120 deletions.
81 changes: 35 additions & 46 deletions pax-web-jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@
<instructions>
<Bundle-Activator>org.ops4j.pax.web.service.jetty.internal.Activator</Bundle-Activator>
<Import-Package>
<!-- ranges indicate Servlet API 3.1+ (JavaEE 7+) -->
javax.servlet;version="[3.1,5)",
javax.servlet.annotation;version="[3.1,5)",
javax.servlet.http;version="[3.1,5)",
<!-- ranges indicate Servlet API 6.0+ (JakartaEE 10+) -->
jakarta.servlet;version="[6,7)",
jakarta.servlet.annotation;version="[6,7)",
jakarta.servlet.http;version="[6,7)",

<!-- ranges indicate we can work with OSGi Core R6+ -->
org.osgi.framework;version="[1.8,2)",
<!-- OSGi Core R8+ -->
org.osgi.framework;version="[1.10,2)",
org.osgi.framework.wiring;version="[1.2,2)",
org.osgi.util.tracker;version="[1.5,2)",

<!-- OSGi cmpn -->
org.osgi.service.http;version="[1.2,2)",
org.osgi.service.http.whiteboard;version="[1.1,2)",
org.osgi.service.servlet.whiteboard;version="[2,3)",

<!-- from pax-web-api -->
org.ops4j.pax.web.service;version="${pax-web.osgi.version}",
org.ops4j.pax.web.service.http;version="${pax-web.osgi.version}",
org.ops4j.pax.web.utils;version="${pax-web.osgi.version}",
<!-- from pax-web-spi -->
org.ops4j.pax.web.service.spi.*;version="${pax-web.osgi.version}",

<!-- from pax-logging-api -->
org.slf4j;version="[1.7,2)",
org.slf4j;version="[2,3)",

<!-- from Jetty bundles -->
org.eclipse.jetty.*,
Expand All @@ -76,16 +76,17 @@
org.eclipse.jetty.servlets;resolution:=optional,

<!-- other -->
javax.annotation;version="[1.2,2)";resolution:=optional,
jakarta.annotation;version="[2,3)";resolution:=optional,
javax.management,
javax.net.ssl,
javax.xml.parsers,
org.w3c.dom,
org.xml.sax
</Import-Package>
<Export-Package>
<!-- TODO: JakartaEE 10 -->
<!-- this is needed to satisfy unused (in Pax Web) requirement from org.eclipse.jetty.websocket.javax.server/10 -->
org.eclipse.jetty.webapp;version="${dependency.org.eclipse.jetty}"
<!-- org.eclipse.jetty.webapp;version="${dependency.org.eclipse.jetty}"-->
</Export-Package>
<Provide-Capability>
osgi.service;effective:=active;objectClass:List&lt;String&gt;="org.ops4j.pax.web.service.spi.ServerControllerFactory"
Expand Down Expand Up @@ -120,28 +121,20 @@
<scope>provided</scope>
</dependency>

<!-- OPS4J dependencies -->
<!-- OSGi -->

<dependency>
<groupId>org.ops4j.base</groupId>
<artifactId>ops4j-base-lang</artifactId>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.base</groupId>
<artifactId>ops4j-base-util-xml</artifactId>
<scope>provided</scope>
</dependency>

<!-- OSGi -->

<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<artifactId>org.osgi.service.servlet</artifactId>
<scope>provided</scope>
</dependency>

<!-- JavaEE -->
<!-- JakartaEE -->

<dependency>
<groupId>jakarta.servlet</groupId>
Expand All @@ -153,6 +146,11 @@
<artifactId>jakarta.websocket-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- Jetty -->

Expand Down Expand Up @@ -279,7 +277,7 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -310,8 +308,18 @@
<!-- Testing -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -322,23 +330,4 @@

</dependencies>

<profiles>
<profile>
<id>jdk11</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<dependencies>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-java-server</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>

</dependencies>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package org.ops4j.pax.web.service.jetty.internal;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import javax.net.ssl.SSLContext;
Expand All @@ -25,6 +27,7 @@
import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.http.HttpCompliance;
import org.eclipse.jetty.http2.HTTP2Cipher;
import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory;
import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
Expand All @@ -33,11 +36,12 @@
import org.eclipse.jetty.server.ForwardedRequestCustomizer;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.MultiPartFormDataCompliance;
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.util.resource.PathResourceFactory;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.ops4j.pax.web.service.spi.config.Configuration;
Expand Down Expand Up @@ -68,6 +72,8 @@ class JettyFactory {
private boolean alpnAvailable;
private boolean http2Available;

private final PathResourceFactory resourceFactory = new PathResourceFactory();

JettyFactory(Bundle paxWebJettyBundle, ClassLoader classLoader) {
this.paxWebJettyBundle = paxWebJettyBundle;
this.classLoader = classLoader;
Expand Down Expand Up @@ -537,7 +543,7 @@ private HttpConfiguration getOrCreateHttpConfiguration(Map<String, HttpConfigura
// default from org.eclipse.jetty.server.HttpConfiguration._outputBufferSize
httpConfig.setOutputBufferSize(32768);
}
httpConfig.setMultiPartFormDataCompliance(MultiPartFormDataCompliance.RFC7578);
httpConfig.setHttpCompliance(HttpCompliance.RFC7230);

if (sc.checkForwardedHeaders() != null && sc.checkForwardedHeaders()) {
httpConfig.addCustomizer(new ForwardedRequestCustomizer());
Expand Down Expand Up @@ -578,4 +584,12 @@ public MBeanContainer enableJmxIfPossible(Server server) {
}
}

public Resource newResource(URL path) {
return resourceFactory.newResource(path);
}

public Resource newResource(File file) {
return resourceFactory.newResource(file.toPath());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
*/
package org.ops4j.pax.web.service.jetty.internal;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.servlet.Servlet;
import jakarta.servlet.Servlet;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.ops4j.pax.web.service.jetty.internal.web.JettyResourceServlet;
import org.ops4j.pax.web.service.spi.ServerController;
import org.ops4j.pax.web.service.spi.ServerState;
Expand Down Expand Up @@ -172,8 +171,8 @@ public void sendBatch(Batch batch) {
public Servlet createResourceServlet(final URL urlBase, final String base) {
final PathResource baseUrlResource;
try {
baseUrlResource = urlBase == null ? null : new PathResource(urlBase);
} catch (IOException | URISyntaxException notPossbleButStill) {
baseUrlResource = urlBase == null ? null : (PathResource) ResourceFactory.root().newResource(urlBase);
} catch (Exception notPossbleButStill) {
throw new IllegalArgumentException(notPossbleButStill.getMessage(), notPossbleButStill);
}
String chroot = baseUrlResource == null ? base : null;
Expand Down
Loading

0 comments on commit 541c375

Please sign in to comment.