Skip to content

Commit

Permalink
[#1802] Switch pax-web-undertow from javax to jakarta
Browse files Browse the repository at this point in the history
  • Loading branch information
grgrzybek committed Jun 16, 2023
1 parent f69d3f0 commit c826a66
Show file tree
Hide file tree
Showing 24 changed files with 326 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@ public interface PaxWebConfig {
* This property specifies the port used for servlets and resources accessible via HTTP.
* The default value for this property is {@code 80} according to specification, but we'll use {@code 8080}.
*/
String PID_CFG_HTTP_PORT = "org.osgi.service.servlet.port";
String PID_CFG_HTTP_PORT = "org.osgi.service.http.port";

/**
* This property specifies the port used for servlets and resources accessible via HTTPS.
* The default value for this property is {@code 443} according to specificaton, but we'll use {@code 8443}.
*/
String PID_CFG_HTTP_PORT_SECURE = "org.osgi.service.servlet.port.secure";
String PID_CFG_HTTP_PORT_SECURE = "org.osgi.service.http.port.secure";

/** Should the default non-secure port be enabled? */
String PID_CFG_HTTP_ENABLED = "org.osgi.service.servlet.enabled";
String PID_CFG_HTTP_ENABLED = "org.osgi.service.http.enabled";

/** Should the default secure port be enabled? */
String PID_CFG_HTTP_SECURE_ENABLED = "org.osgi.service.servlet.secure.enabled";
String PID_CFG_HTTP_SECURE_ENABLED = "org.osgi.service.http.secure.enabled";

/** Comma-separated list of addresses to bind listeners/connectors to. Defaults to {@code 0.0.0.0} */
String PID_CFG_LISTENING_ADDRESSES = "org.ops4j.pax.web.listening.addresses";

/** Name to use as <em>default</em> (non-secure) connector, defaults to {@code default}. */
String PID_CFG_HTTP_CONNECTOR_NAME = "org.osgi.service.servlet.connector.name";
String PID_CFG_HTTP_CONNECTOR_NAME = "org.osgi.service.http.connector.name";

/** Name to use as <em>secure</em> connector, defaults to {@code secureDefault}. */
String PID_CFG_HTTP_SECURE_CONNECTOR_NAME = "org.osgi.service.servlet.secure.connector.name";
String PID_CFG_HTTP_SECURE_CONNECTOR_NAME = "org.osgi.service.http.secure.connector.name";

/**
* Jetty: {@code org.eclipse.jetty.server.AbstractConnector#setIdleTimeout(long)}
Expand Down Expand Up @@ -119,7 +119,7 @@ public interface PaxWebConfig {
/**
* Jetty: adds {@code org.eclipse.jetty.server.ForwardedRequestCustomizer} to {@code HttpConfiguration}
*/
String PID_CFG_HTTP_CHECK_FORWARDED_HEADERS = "org.osgi.service.servlet.checkForwardedHeaders";
String PID_CFG_HTTP_CHECK_FORWARDED_HEADERS = "org.osgi.service.http.checkForwardedHeaders";

/**
* Comma-separated list of virtual hosts to set on <em>every deployed context</em> if the context itself
Expand Down
4 changes: 2 additions & 2 deletions pax-web-undertow/internals.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ QueuedNioTcpServer@10249 = "TCP server (NIO) <b75f502>"
<2> This is default handler invoked when nothing is matched using <4>
<3> PathHandler will be drilled down later
<4> These 4 welcome pages are defaults from `io.undertow.server.handlers.resource.ResourceHandler.welcomeFiles`
<5> Standard javax.servlet context mapping
<5> Standard jakarta.servlet context mapping

Here's how `io.undertow.Undertow` (Wildfly's version is `org.wildfly.extension.undertow.Server`)
instance can be found (there's one instance of this class):
Expand Down Expand Up @@ -149,7 +149,7 @@ next: {io.undertow.server.handlers.PathHandler@10199}
<2> Path matching within single web application
<3> Servlets of web application
<4> The actual instance of one of the the servlets
<5> Resource manager for calls to e.g., `javax.servlet.ServletContext.getResource()`
<5> Resource manager for calls to e.g., `jakarta.servlet.ServletContext.getResource()`

Here's what really is invoked by `io.undertow.servlet.handlers.ServletDispatchingHandler`:

Expand Down
92 changes: 51 additions & 41 deletions pax-web-undertow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,61 +43,61 @@
<instructions>
<Bundle-Activator>org.ops4j.pax.web.service.undertow.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.descriptor;version="[3.1,5)",
javax.servlet.http;version="[3.1,5)",

<!-- ranges indicate we can work with OSGi Core R6+ -->
org.osgi.framework;version="[1.8,2)",
<!-- ranges indicate Servlet API 6.0+ (JakartaEE 10+) -->
jakarta.servlet;version="[6,7)",
jakarta.servlet.annotation;version="[6,7)",
jakarta.servlet.descriptor;version="[6,7)",
jakarta.servlet.http;version="[6,7)",

<!-- 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)",
org.jboss.logging;version="[3.4,4)",

<!-- undertow and xnio packages -->
org.xnio;version="[3.8,4)",
org.xnio.channels;version="[3.8,4)",
io.undertow;version="[2.2,3)",
io.undertow.connector;version="[2.2,3)",
io.undertow.io;version="[2.2,3)",
io.undertow.predicate;version="[2.2,3)",
io.undertow.protocols.ssl;version="[2.2,3)",
io.undertow.security.api;version="[2.2,3)",
io.undertow.security.idm;version="[2.2,3)",
io.undertow.server;version="[2.2,3)",
io.undertow.server.handlers;version="[2.2,3)",
io.undertow.server.handlers.accesslog;version="[2.2,3)",
io.undertow.server.handlers.builder;version="[2.2,3)",
io.undertow.server.handlers.cache;version="[2.2,3)",
io.undertow.server.handlers.encoding;version="[2.2,3)",
io.undertow.server.handlers.resource;version="[2.2,3)",
io.undertow.server.protocol.http;version="[2.2,3)",
io.undertow.server.protocol.http2;version="[2.2,3)",
io.undertow.server.session;version="[2.2,3)",
io.undertow.servlet;version="[2.2,3)",
io.undertow.servlet.api;version="[2.2,3)",
io.undertow.servlet.core;version="[2.2,3)",
io.undertow.servlet.handlers;version="[2.2,3)",
io.undertow.servlet.spec;version="[2.2,3)",
io.undertow.servlet.util;version="[2.2,3)",
io.undertow.util;version="[2.2,3)",
io.undertow;version="[2.3,3)",
io.undertow.connector;version="[2.3,3)",
io.undertow.io;version="[2.3,3)",
io.undertow.predicate;version="[2.3,3)",
io.undertow.protocols.ssl;version="[2.3,3)",
io.undertow.security.api;version="[2.3,3)",
io.undertow.security.idm;version="[2.3,3)",
io.undertow.server;version="[2.3,3)",
io.undertow.server.handlers;version="[2.3,3)",
io.undertow.server.handlers.accesslog;version="[2.3,3)",
io.undertow.server.handlers.builder;version="[2.3,3)",
io.undertow.server.handlers.cache;version="[2.3,3)",
io.undertow.server.handlers.encoding;version="[2.3,3)",
io.undertow.server.handlers.resource;version="[2.3,3)",
io.undertow.server.protocol.http;version="[2.3,3)",
io.undertow.server.protocol.http2;version="[2.3,3)",
io.undertow.server.session;version="[2.3,3)",
io.undertow.servlet;version="[2.3,3)",
io.undertow.servlet.api;version="[2.3,3)",
io.undertow.servlet.core;version="[2.3,3)",
io.undertow.servlet.handlers;version="[2.3,3)",
io.undertow.servlet.spec;version="[2.3,3)",
io.undertow.servlet.util;version="[2.3,3)",
io.undertow.util;version="[2.3,3)",

<!-- other -->
javax.annotation;version="[1.2,2)";resolution:=optional,
jakarta.annotation;version="[2,3)";resolution:=optional,
javax.net.ssl,
javax.security.auth,
javax.security.auth.callback,
Expand Down Expand Up @@ -163,11 +163,11 @@
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<artifactId>org.osgi.service.servlet</artifactId>
<scope>provided</scope>
</dependency>

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

<dependency>
<groupId>jakarta.annotation</groupId>
Expand Down Expand Up @@ -225,9 +225,14 @@
<artifactId>jul-to-slf4j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</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 @@ -258,8 +263,13 @@
<!-- 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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public static CustomFilter create(Map<QName, String> attributes, Locator locator

@Override
public HttpHandler configure(HttpHandler handler, Predicate predicate) {
// TODO: use javax.servlet filters or just generic io.undertow.server.HttpHandler?
// TODO: use jakarta.servlet filters or just generic io.undertow.server.HttpHandler?
return handler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.ops4j.pax.web.service.undertow.internal;

import java.util.Dictionary;
import javax.servlet.Servlet;
import jakarta.servlet.Servlet;

import io.undertow.Handlers;
import io.undertow.server.HttpHandler;
Expand All @@ -25,13 +25,13 @@
import io.undertow.server.handlers.ResponseCodeHandler;
import io.undertow.server.handlers.cache.LRUCache;
import org.ops4j.pax.web.annotations.Review;
import org.osgi.service.http.HttpContext;
import org.ops4j.pax.web.service.http.HttpContext;

/**
* <p>A {@link PathHandler} that can (try to) resolve conflicts when registering multiple contexts under
* the same path.</p>
* <p>The problem is that when using {@code etc/undertow.xml} with {@code <location>} handlers <strong>and</strong>
* when using normal WARs and {@link org.osgi.service.http.HttpService#registerServlet(String, Servlet, Dictionary, HttpContext)} we may
* when using normal WARs and {@link org.ops4j.pax.web.service.http.HttpService#registerServlet(String, Servlet, Dictionary, HttpContext)} we may
* end up with multiple {@link io.undertow.server.HttpHandler handlers} handling {@code "/"} path. We should always prefer
* the path from {@code etc/undertow.xml} configuration - assuming it's configured and user know what (s)he's
* doing.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package org.ops4j.pax.web.service.undertow.internal;

import java.util.Map;
import javax.servlet.Filter;
import javax.servlet.ServletContext;
import jakarta.servlet.Filter;
import jakarta.servlet.ServletContext;

import io.undertow.servlet.api.FilterInfo;
import io.undertow.servlet.api.InstanceFactory;
Expand All @@ -31,7 +31,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceObjects;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.runtime.dto.DTOConstants;
import org.osgi.service.servlet.runtime.dto.DTOConstants;

/**
* Special {@link FilterInfo} that can be configured from {@link FilterModel}.
Expand All @@ -40,7 +40,7 @@ public class PaxWebFilterInfo extends FilterInfo {

private final FilterModel filterModel;

/** This {@link ServletContext} is scoped to single {@link org.osgi.service.http.context.ServletContextHelper} */
/** This {@link ServletContext} is scoped to single {@link org.osgi.service.servlet.context.ServletContextHelper} */
private final OsgiServletContext osgiServletContext;

private ServiceReference<? extends Filter> serviceReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.ops4j.pax.web.service.undertow.internal;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;

import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
Expand All @@ -32,7 +32,7 @@
import org.ops4j.pax.web.service.spi.servlet.OsgiSessionAttributeListener;

/**
* This {@link HandlerWrapper} ensures that {@link org.osgi.service.http.whiteboard.Preprocessor preprocessors},
* This {@link HandlerWrapper} ensures that {@link org.osgi.service.servlet.whiteboard.Preprocessor preprocessors},
* filters and target servlet use proper request wrapper that returns proper {@link ServletContext}.
*/
public class PaxWebOuterHandlerWrapper implements HandlerWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.FilterChain;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.servlet.handlers.ServletRequestContext;
import org.ops4j.pax.web.service.spi.servlet.OsgiFilterChain;
import org.ops4j.pax.web.service.spi.servlet.PreprocessorFilterConfig;
import org.osgi.service.http.whiteboard.Preprocessor;
import org.osgi.service.servlet.whiteboard.Preprocessor;

/**
* This {@link HandlerWrapper} ensures that {@link org.osgi.service.http.whiteboard.Preprocessor preprocessors},
* This {@link HandlerWrapper} ensures that {@link org.osgi.service.servlet.whiteboard.Preprocessor preprocessors},
* filters and target servlet use proper request wrapper that returns proper {@link ServletContext}.
*/
public class PaxWebPreprocessorsHandler implements HandlerWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package org.ops4j.pax.web.service.undertow.internal;

import javax.servlet.Servlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.Servlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.ops4j.pax.web.service.undertow.internal;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import jakarta.servlet.Servlet;
import jakarta.servlet.ServletContext;

import io.undertow.servlet.api.InstanceFactory;
import io.undertow.servlet.api.InstanceHandle;
Expand All @@ -33,7 +33,7 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceObjects;
import org.osgi.service.http.runtime.dto.DTOConstants;
import org.osgi.service.servlet.runtime.dto.DTOConstants;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -52,7 +52,7 @@ public class PaxWebServletInfo extends ServletInfo {

private Class<? extends Servlet> servletClass;

/** This {@link ServletContext} is scoped to single {@link org.osgi.service.http.context.ServletContextHelper} */
/** This {@link ServletContext} is scoped to single {@link org.osgi.service.servlet.context.ServletContextHelper} */
private final OsgiServletContext osgiServletContext;
/** This {@link ServletContext} is scoped to particular Whiteboard servlet */
private final OsgiScopedServletContext servletContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.servlet.Servlet;
import jakarta.servlet.Servlet;

import io.undertow.security.idm.IdentityManager;
import org.ops4j.pax.web.service.spi.ServerController;
Expand Down
Loading

0 comments on commit c826a66

Please sign in to comment.