diff --git a/pom.xml b/pom.xml index 7182f9fd79..4dbdca2d62 100644 --- a/pom.xml +++ b/pom.xml @@ -255,11 +255,12 @@ 4.13.2 - 3.1.0 + 3.1.0 + 5.0.0 - - - 9.0.90 + + 1.1 + 2.1.1 5.9.2 @@ -757,13 +758,6 @@ com.fasterxml.jackson.module jackson-module-jsonSchema ${jackson.version} - - - - javax.validation - validation-api - - com.fasterxml.jackson.datatype @@ -958,6 +952,13 @@ 3.30.2-GA + + + jakarta.inject + jakarta.inject-api + 2.0.1 + + @@ -1259,7 +1260,12 @@ javax.servlet javax.servlet-api - ${servlet.version} + ${javax.servlet.version} + + + jakarta.servlet + jakarta.servlet-api + ${jakarta.servlet.version} provided @@ -1267,7 +1273,18 @@ javax.websocket javax.websocket-api - 1.1 + ${javax.websocket.version} + + + jakarta.websocket + jakarta.websocket-api + ${jakarta.websocket.version} + provided + + + jakarta.websocket + jakarta.websocket-client-api + ${jakarta.websocket.version} provided @@ -1282,24 +1299,30 @@ cssparser 0.9.30 + + + javax.validation + validation-api + 2.0.1.Final + jakarta.validation jakarta.validation-api - 2.0.2 + 3.0.2 org.hibernate.validator hibernate-validator - 6.2.5.Final + 8.0.1.Final runtime - org.mortbay.jasper - apache-el - ${apache-el.version} - - test + org.glassfish.expressly + expressly + 5.0.0 + + provided @@ -2049,25 +2072,6 @@ - - - enforce-jakarta.validation-api - - enforce - - - ${xwiki.enforcer.enforce-jakarta.validation-api.skip} - - - true - Use jakarta.validation:jakarta.validation-api instead - - javax.validation:validation-api - - - - - enforce-hibernate-validator diff --git a/xwiki-commons-core/pom.xml b/xwiki-commons-core/pom.xml index 36ab2d4d6a..cb80caeb4a 100644 --- a/xwiki-commons-core/pom.xml +++ b/xwiki-commons-core/pom.xml @@ -64,6 +64,7 @@ xwiki-commons-websocket xwiki-commons-xml xwiki-commons-xstream + xwiki-commons-jakartabridge @@ -249,6 +250,68 @@ + + + + revapi false positives + allowed + + + true + java.class.nonFinalClassInheritsFromNewClass + class org.xwiki.component.embed.GenericProvider<T> + class org.xwiki.component.embed.GenericProvider<T> + org.xwiki.component.internal.AbstractGenericProvider<T> + + + true + java.class.nonFinalClassInheritsFromNewClass + class org.xwiki.component.embed.GenericProvider<T> + class org.xwiki.component.embed.GenericProvider<T> + org.xwiki.component.internal.JavaXGenericProvider<T> + + + + + Moved to WebSocket 2.1.1 + highlight + + + true + java.class.noLongerImplementsInterface + class org.xwiki.websocket.AbstractPartialMessageHandler<T> + class org.xwiki.websocket.AbstractPartialMessageHandler<T> + javax.websocket.MessageHandler.Partial<T> + + + true + java.class.noLongerImplementsInterface + class org.xwiki.websocket.AbstractPartialMessageHandler<T> + class org.xwiki.websocket.AbstractPartialMessageHandler<T> + javax.websocket.MessageHandler + + + true + java.class.noLongerImplementsInterface + class org.xwiki.websocket.AbstractPartialStringMessageHandler + class org.xwiki.websocket.AbstractPartialStringMessageHandler + javax.websocket.MessageHandler.Partial<java.lang.String> + + + true + java.class.noLongerImplementsInterface + class org.xwiki.websocket.AbstractPartialStringMessageHandler + class org.xwiki.websocket.AbstractPartialStringMessageHandler + javax.websocket.MessageHandler + + + true + true + java.method.parameterTypeChanged + parameter .* org.xwiki.websocket.WebSocketContext::.* + + + diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/pom.xml b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/pom.xml index 7229e3ba12..bf6ec180eb 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/pom.xml +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/pom.xml @@ -55,13 +55,17 @@ org.slf4j slf4j-api - + + jakarta.inject + jakarta.inject-api + + javax.inject javax.inject 1 + org.xwiki.commons diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/descriptor/DefaultComponentDependency.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/descriptor/DefaultComponentDependency.java index 48cacebd9c..5f4a501e4b 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/descriptor/DefaultComponentDependency.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/descriptor/DefaultComponentDependency.java @@ -26,13 +26,14 @@ import java.util.List; import java.util.Map; import java.util.Objects; - -import javax.inject.Provider; +import java.util.Set; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.xwiki.component.util.DefaultParameterizedType; import org.xwiki.component.util.ReflectionUtils; +import jakarta.inject.Provider; + /** * Default implementation of {@link ComponentDependency}. * @@ -42,6 +43,9 @@ */ public class DefaultComponentDependency extends DefaultComponentRole implements ComponentDependency { + private static final Set> SPECIAL_ROLES = + Set.of(List.class, Collection.class, Map.class, javax.inject.Provider.class, Provider.class); + /** * @see #getName() */ @@ -115,7 +119,8 @@ public boolean equals(Object object) { boolean result; - // See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm. + // See http://www.technofundo.com/tech/java/equalhash.html for the detail of + // this algorithm. if (this == object) { result = true; } else { @@ -192,7 +197,7 @@ public Class getRole() { Class mapping = getMappingType(); - if (mapping == List.class || mapping == Collection.class || mapping == Map.class || mapping == Provider.class) { + if (SPECIAL_ROLES.contains(mapping)) { return ReflectionUtils.getTypeClass(ReflectionUtils.getLastTypeGenericArgument(getRoleType())); } else { return mapping; @@ -204,7 +209,7 @@ public void setRole(Class role) { Class mapping = getMappingType(); - if (mapping == List.class || mapping == Collection.class || mapping == Map.class || mapping == Provider.class) { + if (SPECIAL_ROLES.contains(mapping)) { Type ownerType; Class rawType; if (getRoleType() instanceof ParameterizedType) { diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/multi/AbstractGenericComponentManager.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/multi/AbstractGenericComponentManager.java index 0b2f569941..6ea9a20897 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/multi/AbstractGenericComponentManager.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/multi/AbstractGenericComponentManager.java @@ -21,12 +21,12 @@ import java.lang.reflect.Type; -import javax.inject.Inject; - import org.xwiki.component.descriptor.ComponentDescriptor; import org.xwiki.component.manager.ComponentManager; import org.xwiki.component.manager.ComponentRepositoryException; +import jakarta.inject.Inject; + /** * Generic implementation that creates Component Manager instances based on the generic notion of a key. This is used * for example by the Wiki Component Manager or the User Component Manager which respectively have a key returning the diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/multi/DefaultComponentManagerManager.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/multi/DefaultComponentManagerManager.java index 2354c510ff..5ae0edab50 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/multi/DefaultComponentManagerManager.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/multi/DefaultComponentManagerManager.java @@ -22,14 +22,14 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import javax.inject.Inject; -import javax.inject.Singleton; - import org.xwiki.component.annotation.Component; import org.xwiki.component.manager.ComponentLookupException; import org.xwiki.component.manager.ComponentManager; import org.xwiki.component.namespace.NamespaceUtils; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; + /** * Default implementation of {@link ComponentManagerManager}. * diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/namespace/DefaultNamespaceValidator.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/namespace/DefaultNamespaceValidator.java index 059f5ba8a3..4d3e6e8d9b 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/namespace/DefaultNamespaceValidator.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/main/java/org/xwiki/component/internal/namespace/DefaultNamespaceValidator.java @@ -25,17 +25,17 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Provider; -import javax.inject.Singleton; - import org.apache.commons.lang3.StringUtils; import org.xwiki.component.annotation.Component; import org.xwiki.component.manager.ComponentManager; import org.xwiki.component.namespace.NamespaceNotAllowedException; import org.xwiki.component.namespace.NamespaceValidator; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Provider; +import jakarta.inject.Singleton; + /** * Default implementation of {@link NamespaceValidator}. * diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/descriptor/DefaultComponentRoleTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/descriptor/DefaultComponentRoleTest.java index 69ff9c3130..2dfdf0ade6 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/descriptor/DefaultComponentRoleTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/descriptor/DefaultComponentRoleTest.java @@ -30,7 +30,7 @@ * @version $Id$ * @since 3.3M1 */ -public class DefaultComponentRoleTest +class DefaultComponentRoleTest { private interface Role { diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/DefaultNamespaceValidatorTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/DefaultNamespaceValidatorTest.java index 77496ca0b3..a003f69a8b 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/DefaultNamespaceValidatorTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/DefaultNamespaceValidatorTest.java @@ -34,7 +34,7 @@ * * @version $Id$ */ -public class DefaultNamespaceValidatorTest +class DefaultNamespaceValidatorTest { private DefaultNamespaceValidator validator = new DefaultNamespaceValidator(); diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/NamespaceTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/NamespaceTest.java index ac9e08256b..1e8000d341 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/NamespaceTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/NamespaceTest.java @@ -31,7 +31,7 @@ * * @version $Id$ */ -public class NamespaceTest +class NamespaceTest { @Test void equalsAndHashCode() diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/NamespaceUtilsTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/NamespaceUtilsTest.java index 3785631bd4..50cc2a14a8 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/NamespaceUtilsTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/internal/namespace/NamespaceUtilsTest.java @@ -31,7 +31,7 @@ * * @version $Id$ */ -public class NamespaceUtilsTest +class NamespaceUtilsTest { @Test void getPrefix() diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/DefaultParameterizedTypeTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/DefaultParameterizedTypeTest.java index e0c6ce46f2..a159f33c91 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/DefaultParameterizedTypeTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/DefaultParameterizedTypeTest.java @@ -32,7 +32,7 @@ * * @version $Id$ */ -public class DefaultParameterizedTypeTest +class DefaultParameterizedTypeTest { @Test void toStringTest() diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/ReflectionMethodUtilsTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/ReflectionMethodUtilsTest.java index 530f924f32..b1bbafa2a9 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/ReflectionMethodUtilsTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/ReflectionMethodUtilsTest.java @@ -30,7 +30,7 @@ * * @version $Id$ */ -public class ReflectionMethodUtilsTest +class ReflectionMethodUtilsTest { @Test void testGetMethodParameterAnnotations() throws SecurityException, NoSuchMethodException diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/ReflectionUtilsTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/ReflectionUtilsTest.java index 93cb1569ed..f742e7d4f5 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/ReflectionUtilsTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-api/src/test/java/org/xwiki/component/util/ReflectionUtilsTest.java @@ -46,7 +46,7 @@ * * @version $Id$ */ -public class ReflectionUtilsTest +class ReflectionUtilsTest { private static interface TestInterfaceSimple { diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-archetype/src/main/resources/archetype-resources/src/main/java/internal/DefaultHelloWorld.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-archetype/src/main/resources/archetype-resources/src/main/java/internal/DefaultHelloWorld.java index 0898332d77..f755c332cb 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-archetype/src/main/resources/archetype-resources/src/main/java/internal/DefaultHelloWorld.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-archetype/src/main/resources/archetype-resources/src/main/java/internal/DefaultHelloWorld.java @@ -22,7 +22,7 @@ import ${package}.HelloWorld; import org.xwiki.component.annotation.Component; -import javax.inject.Singleton; +import jakarta.inject.Singleton; /** * Implementation of a {@code HelloWorld} component. diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-archetype/src/main/resources/archetype-resources/src/main/java/script/HelloWorldScriptService.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-archetype/src/main/resources/archetype-resources/src/main/java/script/HelloWorldScriptService.java index 9d6e720e78..dcdbe148f8 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-archetype/src/main/resources/archetype-resources/src/main/java/script/HelloWorldScriptService.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-archetype/src/main/resources/archetype-resources/src/main/java/script/HelloWorldScriptService.java @@ -24,9 +24,9 @@ import ${package}.HelloWorld; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Singleton; /** * Make the HelloWorld API available to scripting. diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/ComponentAnnotationLoader.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/ComponentAnnotationLoader.java index ba180a604d..a424cf0047 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/ComponentAnnotationLoader.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/ComponentAnnotationLoader.java @@ -39,7 +39,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import javax.inject.Provider; +import jakarta.inject.Provider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -363,7 +363,11 @@ public Set findComponentRoleTypes(Class componentClass, Type[] paramete types.add(interfaceType); } - // Handle javax.inject.Provider + // Handle javax.inject.Provider (retro-compatibility since **feature-deploy-jakarta**) + if (javax.inject.Provider.class.isAssignableFrom(interfaceClass)) { + types.add(interfaceType); + } + // Handle jakarta.inject.Provider if (Provider.class.isAssignableFrom(interfaceClass)) { types.add(interfaceType); } @@ -444,7 +448,11 @@ public Set> findComponentRoleClasses(Class componentClass) } } - // Handle javax.inject.Provider + // Handle javax.inject.Provider (retro-compatibility since **feature-deploy-jakarta**) + if (javax.inject.Provider.class.isAssignableFrom(interfaceClass)) { + classes.add(interfaceClass); + } + // Handle jakarta.inject.Provider if (Provider.class.isAssignableFrom(interfaceClass)) { classes.add(interfaceClass); } diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/ComponentDescriptorFactory.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/ComponentDescriptorFactory.java index 7732adbf4a..683d44fc00 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/ComponentDescriptorFactory.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/ComponentDescriptorFactory.java @@ -26,8 +26,6 @@ import java.util.ServiceLoader; import javax.annotation.Priority; -import javax.inject.Named; -import javax.inject.Singleton; import org.xwiki.component.descriptor.ComponentDependency; import org.xwiki.component.descriptor.ComponentDescriptor; @@ -35,6 +33,9 @@ import org.xwiki.component.descriptor.DefaultComponentDescriptor; import org.xwiki.component.util.ReflectionUtils; +import jakarta.inject.Named; +import jakarta.inject.Singleton; + /** * Constructs a Component Descriptor out of a class definition that contains Annotations. * @@ -101,23 +102,32 @@ public List> createComponentDescriptors(Class> descriptors = new ArrayList<>(); - // If there's a @Named annotation, use it and ignore hints specified in the @Component annotation. + // If there's a @Named annotation, use it and ignore hints specified in the + // @Component annotation. String[] hints; Named named = componentClass.getAnnotation(Named.class); - Component component = componentClass.getAnnotation(Component.class); if (named != null) { hints = new String[] {named.value()}; } else { - // If the Component annotation has several hints specified ignore the default hint value and for each - // specified hint create a Component Descriptor - if (component != null && component.hints().length > 0) { - hints = component.hints(); + javax.inject.Named legacyNamed = componentClass.getAnnotation(javax.inject.Named.class); + + if (legacyNamed != null) { + hints = new String[] {legacyNamed.value()}; } else { - if (component != null && component.value().trim().length() > 0) { - hints = new String[] {component.value().trim()}; + Component component = componentClass.getAnnotation(Component.class); + + // If the Component annotation has several hints specified ignore the default + // hint value and for each + // specified hint create a Component Descriptor + if (component != null && component.hints().length > 0) { + hints = component.hints(); } else { - hints = new String[] {"default"}; + if (component != null && component.value().trim().length() > 0) { + hints = new String[] {component.value().trim()}; + } else { + hints = new String[] {"default"}; + } } } } @@ -160,8 +170,10 @@ private ComponentDescriptor createComponentDescriptor(Class descriptor.setRoleHintPriority(roleHintPriority); // Set the injected fields. - // Note: that we need to find all fields since we can have some inherited fields which are annotated in a - // superclass. Since Java doesn't offer a method to return all fields we have to traverse all parent classes + // Note: that we need to find all fields since we can have some inherited fields + // which are annotated in a + // superclass. Since Java doesn't offer a method to return all fields we have to + // traverse all parent classes // looking for declared fields. for (Field field : ReflectionUtils.getAllFields(componentClass)) { ComponentDependency dependency = createComponentDependency(field); @@ -183,17 +195,25 @@ private ComponentInstantiationStrategy createComponentInstantiationStrategy(Clas // Support both InstantiationStrategy and JSR 330's Singleton annotations. Singleton singleton = componentClass.getAnnotation(Singleton.class); + if (singleton != null) { strategy = ComponentInstantiationStrategy.SINGLETON; } else { - InstantiationStrategy instantiationStrategy = componentClass.getAnnotation(InstantiationStrategy.class); - if (instantiationStrategy != null) { - strategy = instantiationStrategy.value(); - } else { - // TODO: In order to be JSR330 compliant we need to change this behavior and consider components are - // per lookup when no annotation is specified. Before we can do this we need to modify the full xwiki - // code base and possibly introduce a configuration option. To be discussed. + javax.inject.Singleton legacySingleton = componentClass.getAnnotation(javax.inject.Singleton.class); + if (legacySingleton != null) { strategy = ComponentInstantiationStrategy.SINGLETON; + } else { + InstantiationStrategy instantiationStrategy = componentClass.getAnnotation(InstantiationStrategy.class); + if (instantiationStrategy != null) { + strategy = instantiationStrategy.value(); + } else { + // TODO: In order to be JSR330 compliant we need to change this behavior and + // consider components are + // per lookup when no annotation is specified. Before we can do this we need to + // modify the full xwiki + // code base and possibly introduce a configuration option. To be discussed. + strategy = ComponentInstantiationStrategy.SINGLETON; + } } } diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/DefaultComponentDependencyFactory.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/DefaultComponentDependencyFactory.java index a41c8e4843..eeab3c5497 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/DefaultComponentDependencyFactory.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/annotation/DefaultComponentDependencyFactory.java @@ -21,13 +21,13 @@ import java.lang.reflect.Field; -import javax.inject.Inject; -import javax.inject.Named; - import org.xwiki.component.descriptor.ComponentDependency; import org.xwiki.component.descriptor.DefaultComponentDependency; import org.xwiki.component.util.ReflectionUtils; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * Uses {@link javax.inject.Inject} and {@link javax.inject.Named} annotations to recognize a Component Dependency. * @@ -39,30 +39,43 @@ public class DefaultComponentDependencyFactory extends AbstractComponentDependen @Override public ComponentDependency createComponentDependency(Field field) { - DefaultComponentDependency dependency; + DefaultComponentDependency dependency = null; - Inject inject = field.getAnnotation(Inject.class); - if (inject != null) { - dependency = new DefaultComponentDependency(); + if (field.getAnnotation(Inject.class) != null || field.getAnnotation(javax.inject.Inject.class) != null) { + dependency = createDependency(field); + } else { + dependency = null; + } - Class fieldClass = field.getType(); - if (ReflectionUtils.getDirectAnnotation(ComponentRole.class, fieldClass) != null - && ReflectionUtils.getDirectAnnotation(Role.class, fieldClass) == null) { - // since 4.0M1, retro-compatibility (generic type used to not be taken into account) - dependency.setRoleType(fieldClass); - } else { - dependency.setRoleType(field.getGenericType()); - } + return dependency; + } - dependency.setName(field.getName()); + private DefaultComponentDependency createDependency(Field field) + { + DefaultComponentDependency dependency = new DefaultComponentDependency(); - // Look for a Named annotation - Named named = field.getAnnotation(Named.class); - if (named != null) { - dependency.setRoleHint(named.value()); - } + Class fieldClass = field.getType(); + if (ReflectionUtils.getDirectAnnotation(ComponentRole.class, fieldClass) != null + && ReflectionUtils.getDirectAnnotation(Role.class, fieldClass) == null) { + // since 4.0M1, retro-compatibility (generic type used to not be taken into + // account) + dependency.setRoleType(fieldClass); } else { - dependency = null; + dependency.setRoleType(field.getGenericType()); + } + + dependency.setName(field.getName()); + + // Look for a Named annotation + Named named = field.getAnnotation(Named.class); + if (named != null) { + dependency.setRoleHint(named.value()); + } else { + // Look for legacy Named annotation + javax.inject.Named legacyNamed = field.getAnnotation(javax.inject.Named.class); + if (legacyNamed != null) { + dependency.setRoleHint(legacyNamed.value()); + } } return dependency; diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/embed/EmbeddableComponentManager.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/embed/EmbeddableComponentManager.java index 6d0a20404a..a6a5e34be1 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/embed/EmbeddableComponentManager.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/embed/EmbeddableComponentManager.java @@ -19,6 +19,7 @@ */ package org.xwiki.component.embed; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collections; @@ -31,8 +32,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import javax.inject.Provider; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xwiki.collection.internal.PriorityEntries; @@ -42,6 +41,10 @@ import org.xwiki.component.descriptor.ComponentDescriptor; import org.xwiki.component.descriptor.ComponentInstantiationStrategy; import org.xwiki.component.descriptor.DefaultComponentDescriptor; +import org.xwiki.component.internal.JakartaGenericProvider; +import org.xwiki.component.internal.JakartaJavaXProvider; +import org.xwiki.component.internal.JavaXGenericProvider; +import org.xwiki.component.internal.JavaXJakartaProvider; import org.xwiki.component.internal.RoleHint; import org.xwiki.component.manager.ComponentEventManager; import org.xwiki.component.manager.ComponentLifecycleException; @@ -51,8 +54,11 @@ import org.xwiki.component.manager.ComponentRepositoryException; import org.xwiki.component.manager.NamespacedComponentManager; import org.xwiki.component.phase.Disposable; +import org.xwiki.component.util.DefaultParameterizedType; import org.xwiki.component.util.ReflectionUtils; +import jakarta.inject.Provider; + /** * Simple implementation of {@link ComponentManager} to be used when using some XWiki modules standalone. * @@ -277,7 +283,7 @@ public boolean hasComponent(Type role) @Override public boolean hasComponent(Type roleType, String roleHint) { - if (getComponentEntry(roleType, roleHint) != null) { + if (getComponentEntry(roleType, roleHint, true) != null) { return true; } @@ -295,10 +301,11 @@ public T getInstance(Type roleType, String roleHint) throws ComponentLookupE { T instance; - ComponentEntry componentEntry = (ComponentEntry) getComponentEntry(roleType, roleHint); + ComponentEntry componentEntry = (ComponentEntry) getComponentEntry(roleType, roleHint, true); if (componentEntry == null) { if (getParent() != null) { + // Try the parent instance = getParent().getInstance(roleType, roleHint); } else { throw new ComponentLookupException( @@ -417,7 +424,7 @@ private T getMapInstance(ComponentEntry roleEntry) throws ComponentLookup { try { return getComponentInstance(roleEntry); - } catch (Exception|Error e) { + } catch (Exception | Error e) { if (roleEntry.descriptor.isMandatory()) { throw new ComponentLookupException("Failed to lookup component with type [" + roleEntry.descriptor.getRoleType() + "] and hint [" + roleEntry.descriptor.getRoleHint() + "]", @@ -431,10 +438,63 @@ private T getMapInstance(ComponentEntry roleEntry) throws ComponentLookup return null; } + private ComponentEntry tryOtherProvider(Type roleType, String roleHint) + { + ComponentEntry entry = null; + + if (roleType instanceof ParameterizedType) { + ParameterizedType parameterizedRoleType = (ParameterizedType) roleType; + + if (parameterizedRoleType.getRawType() == Provider.class) { + // Try to get the javax version of the provider + ParameterizedType javaxProviderType = new DefaultParameterizedType(null, javax.inject.Provider.class, + parameterizedRoleType.getActualTypeArguments()[0]); + ComponentEntry javaxEntry = getComponentEntry(javaxProviderType, roleHint); + + if (javaxEntry != null) { + // Wrap it as a jakarta provider + DefaultComponentDescriptor descriptor = new DefaultComponentDescriptor<>(javaxEntry.descriptor); + descriptor.setRoleType(Provider.class); + descriptor.setImplementation(JavaXJakartaProvider.class); + + entry = new ComponentEntry(descriptor, new JavaXJakartaProvider(this, javaxProviderType, roleHint)); + } + } else if (parameterizedRoleType.getRawType() == javax.inject.Provider.class) { + // Try to get the jakarta version of the provider + ParameterizedType jakartaProviderType = new DefaultParameterizedType(null, Provider.class, + parameterizedRoleType.getActualTypeArguments()[0]); + ComponentEntry jakartaEntry = getComponentEntry(jakartaProviderType, roleHint); + + if (jakartaEntry != null) { + // Wrap it as a javax provider + DefaultComponentDescriptor descriptor = new DefaultComponentDescriptor<>(jakartaEntry.descriptor); + descriptor.setRoleType(javax.inject.Provider.class); + descriptor.setImplementation(JakartaJavaXProvider.class); + + entry = + new ComponentEntry(descriptor, new JakartaJavaXProvider(this, jakartaProviderType, roleHint)); + } + } + } + + return entry; + } + + private ComponentEntry getComponentEntry(Type role, String hint, boolean javaxBridge) + { + ComponentEntry entry = getComponentEntry(role, hint); + + if (entry == null && javaxBridge) { + // Retro compatibility: proxy javax or jakarta Provider to the other side + entry = tryOtherProvider(role, hint); + } + + return entry; + } + private ComponentEntry getComponentEntry(Type role, String hint) { ComponentEntries entries = this.componentEntries.get(role); - if (entries != null) { return entries.get(hint != null ? hint : RoleHint.DEFAULT_HINT); } @@ -561,42 +621,57 @@ protected Object getDependencyInstance(ComponentDescriptor descriptor, Object // Handle different field types Object fieldValue; - // Step 1: Verify if there's a Provider registered for the field type - // - A Provider is a component like any other (except it cannot have a field produced by itself!) - // - A Provider must implement the JSR330 Producer interface - // - // Step 2: Handle Logger injection. - // - // Step 3: No producer found, handle scalar and collection types by looking up standard component - // implementations. - - Class dependencyRoleClass = ReflectionUtils.getTypeClass(dependency.getRoleType()); - - if (dependencyRoleClass.isAssignableFrom(Logger.class)) { - fieldValue = createLogger(parentInstance.getClass()); - } else if (dependencyRoleClass.isAssignableFrom(List.class)) { - fieldValue = getInstanceList(ReflectionUtils.getLastTypeGenericArgument(dependency.getRoleType())); - } else if (dependencyRoleClass.isAssignableFrom(Map.class)) { - fieldValue = getInstanceMap(ReflectionUtils.getLastTypeGenericArgument(dependency.getRoleType())); - } else if (dependencyRoleClass.isAssignableFrom(Provider.class)) { - // Check if there's a Provider registered for the type - if (hasComponent(dependency.getRoleType(), dependency.getRoleHint())) { - fieldValue = getInstance(dependency.getRoleType(), dependency.getRoleHint()); + ComponentEntry dependencyEntry = getComponentEntry(dependency.getRoleType(), dependency.getRoleHint(), true); + + if (dependencyEntry != null) { + // There is a component explicitly registered for this role type + fieldValue = getInstance(dependency.getRoleType(), dependency.getRoleHint()); + } else { + // There is no component explicitly registered for this role type, check for various types with a special + // meaning + Class dependencyRoleClass = ReflectionUtils.getTypeClass(dependency.getRoleType()); + + if (dependencyRoleClass.isAssignableFrom(Logger.class)) { + fieldValue = createLogger(parentInstance.getClass()); + } else if (dependencyRoleClass.isAssignableFrom(List.class)) { + fieldValue = getInstanceList(ReflectionUtils.getLastTypeGenericArgument(dependency.getRoleType())); + } else if (dependencyRoleClass.isAssignableFrom(Map.class)) { + fieldValue = getInstanceMap(ReflectionUtils.getLastTypeGenericArgument(dependency.getRoleType())); + } else if (dependencyRoleClass.isAssignableFrom(Provider.class)) { + // Check if there's a Provider registered for the type + if (hasComponent(dependency.getRoleType(), dependency.getRoleHint())) { + fieldValue = getInstance(dependency.getRoleType(), dependency.getRoleHint()); + } else { + fieldValue = createJakartaGenericProvider(descriptor, dependency); + } + } else if (dependencyRoleClass.isAssignableFrom(javax.inject.Provider.class)) { + // Check if there's a Provider registered for the type + if (hasComponent(dependency.getRoleType(), dependency.getRoleHint())) { + fieldValue = getInstance(dependency.getRoleType(), dependency.getRoleHint()); + } else { + fieldValue = createGenericProvider(descriptor, dependency); + } + } else if (dependencyRoleClass.isAssignableFrom(ComponentDescriptor.class)) { + fieldValue = new DefaultComponentDescriptor<>(descriptor); } else { - fieldValue = createGenericProvider(descriptor, dependency); + fieldValue = getInstance(dependency.getRoleType(), dependency.getRoleHint()); } - } else if (dependencyRoleClass.isAssignableFrom(ComponentDescriptor.class)) { - fieldValue = new DefaultComponentDescriptor<>(descriptor); - } else { - fieldValue = getInstance(dependency.getRoleType(), dependency.getRoleHint()); } return fieldValue; } - protected Provider createGenericProvider(ComponentDescriptor descriptor, ComponentDependency dependency) + protected javax.inject.Provider createGenericProvider(ComponentDescriptor descriptor, + ComponentDependency dependency) + { + return new JavaXGenericProvider<>(this, new RoleHint<>( + ReflectionUtils.getLastTypeGenericArgument(dependency.getRoleType()), dependency.getRoleHint())); + } + + protected Provider createJakartaGenericProvider(ComponentDescriptor descriptor, + ComponentDependency dependency) { - return new GenericProvider<>(this, new RoleHint<>( + return new JakartaGenericProvider<>(this, new RoleHint<>( ReflectionUtils.getLastTypeGenericArgument(dependency.getRoleType()), dependency.getRoleHint())); } @@ -657,7 +732,7 @@ public void registerComponent(ComponentDescriptor componentDescriptor) th public void registerComponent(ComponentDescriptor componentDescriptor, T componentInstance) { ComponentEntry componentEntry = - getComponentEntry(componentDescriptor.getRoleType(), componentDescriptor.getRoleHint()); + getComponentEntry(componentDescriptor.getRoleType(), componentDescriptor.getRoleHint(), true); if (componentEntry == null || componentEntry.descriptor.getRoleHintPriority() >= componentDescriptor.getRoleHintPriority()) { diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/embed/GenericProvider.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/AbstractGenericProvider.java similarity index 64% rename from xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/embed/GenericProvider.java rename to xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/AbstractGenericProvider.java index 26dea6cd43..5cd98efb8a 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/embed/GenericProvider.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/AbstractGenericProvider.java @@ -17,21 +17,20 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.xwiki.component.embed; +package org.xwiki.component.internal; import java.lang.reflect.Type; import java.util.List; import java.util.Map; -import javax.inject.Provider; - import org.xwiki.component.annotation.ComponentRole; import org.xwiki.component.annotation.Role; -import org.xwiki.component.internal.RoleHint; import org.xwiki.component.manager.ComponentLookupException; import org.xwiki.component.manager.ComponentManager; import org.xwiki.component.util.ReflectionUtils; +import jakarta.inject.Provider; + /** * Default provider used when the Component Manager needs to inject a {@link Provider} field but no custom Provider has * been registered. The default behavior is simply to look up the Component role class when @@ -39,17 +38,17 @@ * * @param the role type * @version $Id$ - * @since 3.3M2 + * @since 42.0.0 */ -public class GenericProvider implements Provider +public abstract class AbstractGenericProvider { /** - * @see GenericProvider#GenericProvider(ComponentManager, RoleHint) + * @see AbstractGenericProvider#GenericProvider(ComponentManager, RoleHint) */ protected ComponentManager componentManager; /** - * @see GenericProvider#GenericProvider(ComponentManager, RoleHint) + * @see AbstractGenericProvider#GenericProvider(ComponentManager, RoleHint) */ private RoleHint roleHint; @@ -58,13 +57,21 @@ public class GenericProvider implements Provider * {@link javax.inject.Provider#get()} * @param roleHint the Component Role and Hint that uniquely identify the Component we wish to provide for */ - public GenericProvider(ComponentManager componentManager, RoleHint roleHint) + AbstractGenericProvider(ComponentManager componentManager, RoleHint roleHint) { this.componentManager = componentManager; this.roleHint = roleHint; } - @Override + /** + * Provides a fully-constructed and injected instance of {@code T}. + * + * @return instance of {@code T}. + * @throws RuntimeException if the injector encounters an error while providing an instance. For example, if an + * injectable member on {@code T} throws an exception, the injector may wrap the exception and throw it + * to the caller of {@code get()}. Callers should not try to handle such exceptions as the behavior may + * vary across injector implementations and even different configurations of the same injector. + */ @SuppressWarnings("unchecked") public T get() { @@ -73,25 +80,21 @@ public T get() try { Class roleClass = this.roleHint.getRoleClass(); - if (roleClass.isAssignableFrom(Provider.class)) { + if (roleClass.isAssignableFrom(Provider.class) || roleClass.isAssignableFrom(javax.inject.Provider.class)) { try { - component = - this.componentManager.getInstance(this.roleHint.getRoleType(), this.roleHint.getHint()); + component = this.componentManager.getInstance(this.roleHint.getRoleType(), this.roleHint.getHint()); } catch (ComponentLookupException e) { // Inject a default Provider - component = - (T) new GenericProvider<>(this.componentManager, new RoleHint<>( - ReflectionUtils.getLastTypeGenericArgument(this.roleHint.getRoleType()), + component = (T) newProvider(this.componentManager, + new RoleHint<>(ReflectionUtils.getLastTypeGenericArgument(this.roleHint.getRoleType()), this.roleHint.getHint())); } } else if (roleClass.isAssignableFrom(List.class)) { - component = - (T) this.componentManager.getInstanceList(ReflectionUtils.getLastTypeGenericArgument(this.roleHint - .getRoleType())); + component = (T) this.componentManager + .getInstanceList(ReflectionUtils.getLastTypeGenericArgument(this.roleHint.getRoleType())); } else if (roleClass.isAssignableFrom(Map.class)) { - component = - (T) this.componentManager.getInstanceMap(ReflectionUtils.getLastTypeGenericArgument(this.roleHint - .getRoleType())); + component = (T) this.componentManager + .getInstanceMap(ReflectionUtils.getLastTypeGenericArgument(this.roleHint.getRoleType())); } else if (ReflectionUtils.getDirectAnnotation(ComponentRole.class, roleClass) != null && ReflectionUtils.getDirectAnnotation(Role.class, roleClass) == null) { // since 4.0M1, retro-compatibility (generic type used to not be taken into account) @@ -106,6 +109,8 @@ public T get() return component; } + protected abstract AbstractGenericProvider newProvider(ComponentManager componentManager, RoleHint roleHint); + protected T getInstance(Type type, String hint) throws ComponentLookupException { return this.componentManager.getInstance(type, hint); diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/ContextComponentManagerProvider.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/ContextComponentManagerProvider.java index 369678276a..159e51b656 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/ContextComponentManagerProvider.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/ContextComponentManagerProvider.java @@ -19,17 +19,17 @@ */ package org.xwiki.component.internal; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Provider; -import javax.inject.Singleton; - import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; import org.xwiki.component.annotation.Component; import org.xwiki.component.manager.ComponentLookupException; import org.xwiki.component.manager.ComponentManager; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Provider; +import jakarta.inject.Singleton; + /** * Provide the {@link ComponentManager} associated to the current context. Return the root {@link ComponentManager} if * no context oriented {@link ComponentManager} can be found. diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JakartaGenericProvider.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JakartaGenericProvider.java new file mode 100644 index 0000000000..e93cbc50fd --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JakartaGenericProvider.java @@ -0,0 +1,52 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.component.internal; + +import org.xwiki.component.manager.ComponentManager; + +import jakarta.inject.Provider; + +/** + * Default provider used when the Component Manager needs to inject a {@link Provider} field but no custom Provider has + * been registered. The default behavior is simply to look up the Component role class when {@link Provider#get()} is + * called. This is useful for example when you wish to do "lazy injection". + * + * @param the role type + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaGenericProvider extends AbstractGenericProvider implements Provider +{ + /** + * @param componentManager the Component Manager instance that we'll use to look up the Component Role during + * {@link javax.inject.Provider#get()} + * @param roleHint the Component Role and Hint that uniquely identify the Component we wish to provide for + */ + public JakartaGenericProvider(ComponentManager componentManager, RoleHint roleHint) + { + super(componentManager, roleHint); + } + + @Override + protected AbstractGenericProvider newProvider(ComponentManager componentManager, RoleHint roleHint) + { + return new JakartaGenericProvider<>(componentManager, roleHint); + } +} diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JakartaJavaXProvider.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JakartaJavaXProvider.java new file mode 100644 index 0000000000..06fb13cd68 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JakartaJavaXProvider.java @@ -0,0 +1,70 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.component.internal; + +import java.lang.reflect.Type; + +import javax.inject.Provider; + +import org.xwiki.component.manager.ComponentLookupException; +import org.xwiki.component.manager.ComponentManager; + +/** + * Wrapper used to expose a {@link Provider} as a {@link javax.inject.Provider}. + * + * @param the role type to provide + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaJavaXProvider implements Provider +{ + private final ComponentManager componentManager; + + private final Type providerType; + + private final String roleHint; + + /** + * @param componentManager the Component Manager instance to use to get the wrapped {@link jakarta.inject.Provider} + * @param providerType the role type to provide + * @param roleHint the hint that differentiates a component implementation from another one (each component is + * registered with a hint; the "default" hint being the default) + */ + public JakartaJavaXProvider(ComponentManager componentManager, Type providerType, String roleHint) + { + this.componentManager = componentManager; + this.providerType = providerType; + this.roleHint = roleHint; + } + + @Override + public T get() + { + jakarta.inject.Provider provider; + try { + provider = this.componentManager.getInstance(this.providerType, this.roleHint); + } catch (ComponentLookupException e) { + throw new RuntimeException( + "Failed to get the provider [" + this.providerType + "] with role hint [" + this.roleHint + "]", e); + } + + return provider.get(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JavaXGenericProvider.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JavaXGenericProvider.java new file mode 100644 index 0000000000..d3ee08c921 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JavaXGenericProvider.java @@ -0,0 +1,52 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.component.internal; + +import javax.inject.Provider; + +import org.xwiki.component.manager.ComponentManager; + +/** + * Default provider used when the Component Manager needs to inject a {@link Provider} field but no custom Provider has + * been registered. The default behavior is simply to look up the Component role class when {@link Provider#get()} is + * called. This is useful for example when you wish to do "lazy injection". + * + * @param the role type + * @version $Id$ + * @since 42.0.0 + */ +public class JavaXGenericProvider extends AbstractGenericProvider implements Provider +{ + /** + * @param componentManager the Component Manager instance that we'll use to look up the Component Role during + * {@link javax.inject.Provider#get()} + * @param roleHint the Component Role and Hint that uniquely identify the Component we wish to provide for + */ + public JavaXGenericProvider(ComponentManager componentManager, RoleHint roleHint) + { + super(componentManager, roleHint); + } + + @Override + protected AbstractGenericProvider newProvider(ComponentManager componentManager, RoleHint roleHint) + { + return new JavaXGenericProvider<>(componentManager, roleHint); + } +} diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JavaXJakartaProvider.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JavaXJakartaProvider.java new file mode 100644 index 0000000000..cfc3df76a8 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/JavaXJakartaProvider.java @@ -0,0 +1,70 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.component.internal; + +import java.lang.reflect.Type; + +import org.xwiki.component.manager.ComponentLookupException; +import org.xwiki.component.manager.ComponentManager; + +import jakarta.inject.Provider; + +/** + * Wrapper used to expose a {@link Provider} as a {@link javax.inject.Provider}. + * + * @param the role type to provide + * @version $Id$ + * @since 42.0.0 + */ +public class JavaXJakartaProvider implements Provider +{ + private final ComponentManager componentManager; + + private final Type providerType; + + private final String roleHint; + + /** + * @param componentManager the Component Manager instance to use to get the wrapped {@link jakarta.inject.Provider} + * @param providerType the role type to provide + * @param roleHint the hint that differentiates a component implementation from another one (each component is + * registered with a hint; the "default" hint being the default) + */ + public JavaXJakartaProvider(ComponentManager componentManager, Type providerType, String roleHint) + { + this.componentManager = componentManager; + this.providerType = providerType; + this.roleHint = roleHint; + } + + @Override + public T get() + { + javax.inject.Provider provider; + try { + provider = this.componentManager.getInstance(this.providerType, this.roleHint); + } catch (ComponentLookupException e) { + throw new RuntimeException( + "Failed to get the provider [" + this.providerType + "] with role hint [" + this.roleHint + "]", e); + } + + return provider.get(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/RootComponentManager.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/RootComponentManager.java index ea5d36753c..80c299be59 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/RootComponentManager.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/RootComponentManager.java @@ -19,16 +19,16 @@ */ package org.xwiki.component.internal; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - import org.xwiki.component.annotation.Component; import org.xwiki.component.internal.multi.DelegateComponentManager; import org.xwiki.component.manager.ComponentManager; import org.xwiki.component.phase.Initializable; import org.xwiki.component.phase.InitializationException; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Singleton; + /** * Allow injecting the root component manager. * diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/embed/EmbeddableComponentManagerFactory.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/embed/EmbeddableComponentManagerFactory.java index 5263d3fbe3..8749b8fbeb 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/embed/EmbeddableComponentManagerFactory.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/main/java/org/xwiki/component/internal/embed/EmbeddableComponentManagerFactory.java @@ -19,14 +19,14 @@ */ package org.xwiki.component.internal.embed; -import javax.inject.Inject; -import javax.inject.Singleton; - import org.xwiki.component.annotation.Component; import org.xwiki.component.embed.EmbeddableComponentManager; import org.xwiki.component.internal.multi.ComponentManagerFactory; import org.xwiki.component.manager.ComponentManager; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; + /** * Create Component Manager implementation based on the Embeddable Component Manager (i.e. a simple implementation of * {@link ComponentManager} to be used when using some XWiki modules standalone). diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/JakartaProviderIntegrationTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/JakartaProviderIntegrationTest.java new file mode 100644 index 0000000000..f7240e634f --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/JakartaProviderIntegrationTest.java @@ -0,0 +1,212 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.component; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.xwiki.component.annotation.Component; +import org.xwiki.component.annotation.Role; +import org.xwiki.component.descriptor.DefaultComponentDescriptor; +import org.xwiki.component.embed.EmbeddableComponentManager; +import org.xwiki.component.embed.EmbeddableComponentManagerTest.RoleImpl; +import org.xwiki.component.embed.EmbeddableComponentManagerTest.TestRole; +import org.xwiki.component.manager.ComponentLookupException; +import org.xwiki.component.manager.ComponentRepositoryException; +import org.xwiki.component.phase.Initializable; +import org.xwiki.component.phase.InitializationException; +import org.xwiki.test.LogLevel; +import org.xwiki.test.junit5.LogCaptureExtension; + +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Provider; +import jakarta.inject.Singleton; + +/** + * Validate loading and injection of Providers in a real use case. + * + * @version $Id$ + */ +//This class needs to remain public because some interfaces are reused in other tests +public class JakartaProviderIntegrationTest +{ + @RegisterExtension + private LogCaptureExtension logCapture = new LogCaptureExtension(LogLevel.ERROR); + + @Role + public interface TestComponentRole + { + + } + + @Component + @Singleton + public static class TestComponentWithProviders implements TestComponentRole + { + @Inject + public Provider provider1; + + @Inject + @Named("another") + public Provider provider12; + + @Inject + public Provider provider2; + + @Inject + public Provider> providerList; + + @Inject + public Provider> providerMap; + } + + public static class TestProvider1 implements Provider + { + @Override + public String get() + { + return "value"; + } + } + + @Named("another") + public static class TestProvider12 implements Provider + { + @Override + public String get() + { + return "another value"; + } + } + + public static class TestProvider2 implements Provider + { + @Override + public Integer get() + { + return 1; + } + } + + @Component + @Named("exception") + @Singleton + public static class TestComponentWithProviderInException implements TestComponentRole + { + @Inject + @Named("exception") + public Provider providerWithExceptionInInitialize; + } + + @Named("exception") + public static class TestProviderWithExceptionInInitialize implements Provider, Initializable + { + @Override + public void initialize() throws InitializationException + { + throw new InitializationException("Some error in init"); + } + + @Override + public String get() + { + throw new RuntimeException("should not be called!"); + } + } + + @Test + void loadAndInjectProviders() throws ComponentLookupException, ComponentRepositoryException + { + EmbeddableComponentManager cm = new EmbeddableComponentManager(); + + // Register components for the list and map + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); + cd1.setRoleHint("hint1"); + cd1.setImplementation(RoleImpl.class); + cm.registerComponent(cd1); + DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); + cd2.setRoleType(TestRole.class); + cd2.setRoleHint("hint2"); + cd2.setImplementation(RoleImpl.class); + cm.registerComponent(cd2); + + // Initialize + cm.initialize(getClass().getClassLoader()); + + TestComponentWithProviders component = cm.getInstance(TestComponentRole.class); + + assertEquals("value", component.provider1.get()); + assertEquals("another value", component.provider12.get()); + assertEquals(Integer.valueOf(1), component.provider2.get()); + + assertEquals(2, component.providerList.get().size()); + assertEquals(2, component.providerMap.get().size()); + } + + /** + * Verify that an exception is raised when a Provider implementing {@link Initializable} fails to initialize. + */ + @Test + void loadAndInjectProviderWhenExceptionInInitialize() + { + EmbeddableComponentManager cm = new EmbeddableComponentManager(); + cm.initialize(getClass().getClassLoader()); + + Throwable exception = + assertThrows(ComponentLookupException.class, () -> cm.getInstance(TestComponentRole.class, "exception")); + assertEquals("Failed to lookup component " + + "[org.xwiki.component.JakartaProviderIntegrationTest$TestComponentWithProviderInException] identified by " + + "type [interface org.xwiki.component.JakartaProviderIntegrationTest$TestComponentRole] and hint [exception]", + exception.getMessage()); + assertEquals("Failed to lookup component " + + "[org.xwiki.component.JakartaProviderIntegrationTest$TestProviderWithExceptionInInitialize] identified by " + + "type [jakarta.inject.Provider] and hint [exception]", + exception.getCause().getMessage()); + assertEquals("Some error in init", exception.getCause().getCause().getMessage()); + } + + @Test + void loadAndInjectProviderWhenNoImplementationFound() throws Exception + { + EmbeddableComponentManager cm = new EmbeddableComponentManager(); + + // Register a bad descriptor (missing an implementation class) to force an error. + DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); + cd.setRoleHint("hint1"); + cm.registerComponent(cd); + + cm.initialize(getClass().getClassLoader()); + + TestComponentWithProviders component = cm.getInstance(TestComponentRole.class); + List components = component.providerList.get(); + + assertEquals("Failed to lookup component with" + + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$TestRole] and hint [hint1]", + this.logCapture.getMessage(0)); + } +} diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/ProviderIntegrationTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/JavaxProviderIntegrationTest.java similarity index 80% rename from xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/ProviderIntegrationTest.java rename to xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/JavaxProviderIntegrationTest.java index 109e773f61..8e964acb3b 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/ProviderIntegrationTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/JavaxProviderIntegrationTest.java @@ -19,6 +19,9 @@ */ package org.xwiki.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.util.List; import java.util.Map; @@ -33,8 +36,8 @@ import org.xwiki.component.annotation.ComponentRole; import org.xwiki.component.descriptor.DefaultComponentDescriptor; import org.xwiki.component.embed.EmbeddableComponentManager; -import org.xwiki.component.embed.EmbeddableComponentManagerTest.Role; import org.xwiki.component.embed.EmbeddableComponentManagerTest.RoleImpl; +import org.xwiki.component.embed.EmbeddableComponentManagerTest.TestRole; import org.xwiki.component.manager.ComponentLookupException; import org.xwiki.component.manager.ComponentRepositoryException; import org.xwiki.component.phase.Initializable; @@ -42,15 +45,13 @@ import org.xwiki.test.LogLevel; import org.xwiki.test.junit5.LogCaptureExtension; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - /** * Validate loading and injection of Providers in a real use case. * * @version $Id$ */ -public class ProviderIntegrationTest +//This class needs to remain public because some interfaces are reused in other tests +public class JavaxProviderIntegrationTest { @RegisterExtension private LogCaptureExtension logCapture = new LogCaptureExtension(LogLevel.ERROR); @@ -76,10 +77,10 @@ public static class TestComponentWithProviders implements TestComponentRole public Provider provider2; @Inject - public Provider> providerList; + public Provider> providerList; @Inject - public Provider> providerMap; + public Provider> providerMap; } public static class TestProvider1 implements Provider @@ -142,13 +143,13 @@ void loadAndInjectProviders() throws ComponentLookupException, ComponentReposito EmbeddableComponentManager cm = new EmbeddableComponentManager(); // Register components for the list and map - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setRoleHint("hint1"); cd1.setImplementation(RoleImpl.class); cm.registerComponent(cd1); - DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); - cd2.setRoleType(Role.class); + DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); + cd2.setRoleType(TestRole.class); cd2.setRoleHint("hint2"); cd2.setImplementation(RoleImpl.class); cm.registerComponent(cd2); @@ -175,16 +176,15 @@ void loadAndInjectProviderWhenExceptionInInitialize() EmbeddableComponentManager cm = new EmbeddableComponentManager(); cm.initialize(getClass().getClassLoader()); - Throwable exception = assertThrows(ComponentLookupException.class, - () -> cm.getInstance(TestComponentRole.class, "exception")); + Throwable exception = + assertThrows(ComponentLookupException.class, () -> cm.getInstance(TestComponentRole.class, "exception")); assertEquals("Failed to lookup component " - + "[org.xwiki.component.ProviderIntegrationTest$TestComponentWithProviderInException] identified by " - + "type [interface org.xwiki.component.ProviderIntegrationTest$TestComponentRole] and hint [exception]", + + "[org.xwiki.component.JavaxProviderIntegrationTest$TestComponentWithProviderInException] identified by " + + "type [interface org.xwiki.component.JavaxProviderIntegrationTest$TestComponentRole] and hint [exception]", exception.getMessage()); assertEquals("Failed to lookup component " - + "[org.xwiki.component.ProviderIntegrationTest$TestProviderWithExceptionInInitialize] identified by " - + "type [javax.inject.Provider] and hint [exception]", - exception.getCause().getMessage()); + + "[org.xwiki.component.JavaxProviderIntegrationTest$TestProviderWithExceptionInInitialize] identified by " + + "type [javax.inject.Provider] and hint [exception]", exception.getCause().getMessage()); assertEquals("Some error in init", exception.getCause().getCause().getMessage()); } @@ -194,19 +194,18 @@ void loadAndInjectProviderWhenNoImplementationFound() throws Exception EmbeddableComponentManager cm = new EmbeddableComponentManager(); // Register a bad descriptor (missing an implementation class) to force an error. - DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); - cd.setRoleType(Role.class); + DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); cd.setRoleHint("hint1"); cm.registerComponent(cd); cm.initialize(getClass().getClassLoader()); TestComponentWithProviders component = cm.getInstance(TestComponentRole.class); - List components = component.providerList.get(); + List components = component.providerList.get(); - assertEquals( - "Failed to lookup component with" - + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$Role] and hint [hint1]", + assertEquals("Failed to lookup component with" + + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$TestRole] and hint [hint1]", this.logCapture.getMessage(0)); } } diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/ComponentAnnotationLoaderTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JakartaComponentAnnotationLoaderTest.java similarity index 81% rename from xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/ComponentAnnotationLoaderTest.java rename to xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JakartaComponentAnnotationLoaderTest.java index 1f4c8ef0a7..9bfb68c4b1 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/ComponentAnnotationLoaderTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JakartaComponentAnnotationLoaderTest.java @@ -19,17 +19,19 @@ */ package org.xwiki.component.annotation; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + import java.lang.reflect.Type; import java.util.Set; -import javax.inject.Named; -import javax.inject.Provider; -import javax.inject.Singleton; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; -import org.xwiki.component.ProviderIntegrationTest; +import org.xwiki.component.JakartaProviderIntegrationTest; import org.xwiki.component.descriptor.ComponentDescriptor; import org.xwiki.component.descriptor.DefaultComponentDescriptor; import org.xwiki.component.internal.ContextComponentManagerProvider; @@ -40,11 +42,9 @@ import org.xwiki.component.manager.ComponentManager; import org.xwiki.component.util.DefaultParameterizedType; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import jakarta.inject.Named; +import jakarta.inject.Provider; +import jakarta.inject.Singleton; /** * Unit tests for {@link ComponentAnnotationLoader}. @@ -52,7 +52,7 @@ * @version $Id$ * @since 1.8.1 */ -public class ComponentAnnotationLoaderTest +class JakartaComponentAnnotationLoaderTest { @SuppressWarnings("deprecation") @ComponentRole @@ -186,7 +186,7 @@ void setupLogger() * priority wins (ie the smallest integer value). */ @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) void priorities() throws Exception { ComponentManager componentManager = mock(ComponentManager.class); @@ -207,17 +207,18 @@ void priorities() throws Exception ComponentDescriptor descriptor7 = this.loader.getComponentsDescriptors(DefaultNamespaceValidator.class).get(0); ComponentDescriptor descriptor8 = - this.loader.getComponentsDescriptors(ProviderIntegrationTest.TestProvider1.class).get(0); + this.loader.getComponentsDescriptors(JakartaProviderIntegrationTest.TestProvider1.class).get(0); ComponentDescriptor descriptor9 = - this.loader.getComponentsDescriptors(ProviderIntegrationTest.TestProvider12.class).get(0); + this.loader.getComponentsDescriptors(JakartaProviderIntegrationTest.TestProvider12.class).get(0); ComponentDescriptor descriptor10 = - this.loader.getComponentsDescriptors(ProviderIntegrationTest.TestProvider2.class).get(0); - ComponentDescriptor descriptor11 = - this.loader.getComponentsDescriptors(ProviderIntegrationTest.TestComponentWithProviders.class).get(0); + this.loader.getComponentsDescriptors(JakartaProviderIntegrationTest.TestProvider2.class).get(0); + ComponentDescriptor descriptor11 = this.loader + .getComponentsDescriptors(JakartaProviderIntegrationTest.TestComponentWithProviders.class).get(0); ComponentDescriptor descriptor12 = this.loader - .getComponentsDescriptors(ProviderIntegrationTest.TestProviderWithExceptionInInitialize.class).get(0); + .getComponentsDescriptors(JakartaProviderIntegrationTest.TestProviderWithExceptionInInitialize.class) + .get(0); ComponentDescriptor descriptor13 = this.loader - .getComponentsDescriptors(ProviderIntegrationTest.TestComponentWithProviderInException.class).get(0); + .getComponentsDescriptors(JakartaProviderIntegrationTest.TestComponentWithProviderInException.class).get(0); this.loader.initialize(componentManager, this.getClass().getClassLoader()); @@ -227,15 +228,6 @@ void priorities() throws Exception verify(componentManager, times(1)).registerComponent(descriptor2); verify(componentManager, times(1)).registerComponent(descriptor3); verify(componentManager, times(1)).registerComponent(descriptor4); - verify(componentManager, times(1)).registerComponent(descriptor5); - verify(componentManager, times(1)).registerComponent(descriptor6); - verify(componentManager, times(1)).registerComponent(descriptor7); - verify(componentManager, times(1)).registerComponent(descriptor8); - verify(componentManager, times(1)).registerComponent(descriptor9); - verify(componentManager, times(1)).registerComponent(descriptor10); - verify(componentManager, times(1)).registerComponent(descriptor11); - verify(componentManager, times(1)).registerComponent(descriptor12); - verify(componentManager, times(1)).registerComponent(descriptor13); } @Test @@ -267,8 +259,10 @@ void findComponentRoleTypesForProvider() Set types = this.loader.findComponentRoleTypes(ProviderImpl.class); assertEquals(1, types.size()); - assertEquals(new DefaultParameterizedType(null, Provider.class, new DefaultParameterizedType( - ComponentAnnotationLoaderTest.class, NotGenericRole.class, String.class)), types.iterator().next()); + assertEquals( + new DefaultParameterizedType(null, Provider.class, new DefaultParameterizedType( + JakartaComponentAnnotationLoaderTest.class, NotGenericRole.class, String.class)), + types.iterator().next()); } @Test @@ -277,8 +271,9 @@ void findComponentRoleTypesWithGenericRole() Set types = this.loader.findComponentRoleTypes(GenericComponent.class); assertEquals(1, types.size()); - assertEquals(new DefaultParameterizedType(ComponentAnnotationLoaderTest.class, GenericRole.class, - String.class), types.iterator().next()); + assertEquals( + new DefaultParameterizedType(JakartaComponentAnnotationLoaderTest.class, GenericRole.class, String.class), + types.iterator().next()); } @Test @@ -296,8 +291,9 @@ void findComponentRoleTypesWithExtendingGenericRole() Set types = this.loader.findComponentRoleTypes(ExtendingGenericComponent.class); assertEquals(1, types.size()); - assertEquals(new DefaultParameterizedType(ComponentAnnotationLoaderTest.class, GenericRole.class, - String.class), types.iterator().next()); + assertEquals( + new DefaultParameterizedType(JakartaComponentAnnotationLoaderTest.class, GenericRole.class, String.class), + types.iterator().next()); } @Test diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JakartaComponentDescriptorFactoryTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JakartaComponentDescriptorFactoryTest.java new file mode 100644 index 0000000000..ad7664f5b5 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JakartaComponentDescriptorFactoryTest.java @@ -0,0 +1,269 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.component.annotation; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.xwiki.component.descriptor.ComponentDependency; +import org.xwiki.component.descriptor.ComponentDescriptor; +import org.xwiki.component.descriptor.ComponentInstantiationStrategy; +import org.xwiki.component.util.DefaultParameterizedType; + +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Singleton; + +/** + * Unit tests for {@link ComponentDescriptorFactory}. + * + * @version $Id$ + * @since 1.8.1 + */ +class JakartaComponentDescriptorFactoryTest +{ + @ComponentRole + public interface NonGenericFieldRole + { + } + + @Role + public interface GenericFieldRole + { + } + + @Component(staticRegistration = false) + @Singleton + public class FieldroleImpl implements NonGenericFieldRole + { + } + + @Component(value = "special", staticRegistration = false) + @Singleton + public class SpecialFieldRoleImpl implements NonGenericFieldRole + { + } + + @ComponentRole + public interface NonGenericRole + { + } + + @ComponentRole + public interface ExtendedRole extends NonGenericRole + { + } + + @Component(staticRegistration = false) + @Singleton + public class RoleImpl implements ExtendedRole + { + @Inject + private NonGenericFieldRole fieldRole; + + @Inject + @Named("special") + private NonGenericFieldRole specialFieldRole; + + @Inject + private GenericFieldRole genericFieldRole; + + @Inject + private GenericFieldRole nonGenericFieldRole; + + /** + * Inject all implementation of the FieldRole role. + */ + @Inject + private List> roles; + + /** + * Inject all implementation of the FieldRole role. + */ + @Inject + private Map> mapRoles; + } + + @Component(staticRegistration = false) + @Singleton + public class SuperRoleImpl extends RoleImpl + { + @Inject + @Named("other") + private NonGenericFieldRole fieldRole; + } + + /** + * Test that we can have a component implementing several roles. + */ + @Component(hints = { "hint1", "hint2" }, staticRegistration = false) + @Singleton + public class MultipleRolesImpl implements NonGenericRole + { + } + + @Component(staticRegistration = false) + @Singleton + public class SingletonImpl implements NonGenericRole + { + } + + @Component(staticRegistration = false) + @Named("special") + @Singleton + public class SpecialImpl implements NonGenericRole + { + } + + @Test + void tcreateComponentDescriptor() + { + assertComponentDescriptor(RoleImpl.class, "default"); + } + + /** + * Verify that we get the same result when we use a class that extends another class (i.e. inheritance works). + */ + @Test + void createComponentDescriptorWhenClassExtension() + { + assertComponentDescriptor(SuperRoleImpl.class, "other"); + } + + @Test + void multipleRolesForComponent() + { + ComponentDescriptorFactory factory = new ComponentDescriptorFactory(); + List> descriptors = + factory.createComponentDescriptors(MultipleRolesImpl.class, NonGenericRole.class); + + assertEquals(2, descriptors.size()); + assertEquals("hint1", descriptors.get(0).getRoleHint()); + assertEquals("hint2", descriptors.get(1).getRoleHint()); + } + + @Test + void singletonAnnotationForComponent() + { + ComponentDescriptorFactory factory = new ComponentDescriptorFactory(); + List> descriptors = + factory.createComponentDescriptors(SingletonImpl.class, NonGenericRole.class); + + assertEquals(1, descriptors.size()); + assertEquals(ComponentInstantiationStrategy.SINGLETON, descriptors.get(0).getInstantiationStrategy()); + } + + @Test + void namedAnnotationForComponent() + { + ComponentDescriptorFactory factory = new ComponentDescriptorFactory(); + List> descriptors = + factory.createComponentDescriptors(SpecialImpl.class, NonGenericRole.class); + + assertEquals(1, descriptors.size()); + assertEquals("special", descriptors.get(0).getRoleHint()); + } + + private void assertComponentDescriptor(Class componentClass, String fieldRoleName) + { + ComponentDescriptorFactory factory = new ComponentDescriptorFactory(); + List> descriptors = factory.createComponentDescriptors(componentClass, + ExtendedRole.class); + + assertEquals(1, descriptors.size()); + ComponentDescriptor descriptor = descriptors.get(0); + + assertSame(componentClass, descriptor.getImplementation()); + assertSame(ExtendedRole.class, descriptor.getRole()); + assertSame(ExtendedRole.class, descriptor.getRoleType()); + assertEquals("default", descriptor.getRoleHint()); + assertEquals(ComponentInstantiationStrategy.SINGLETON, descriptor.getInstantiationStrategy()); + + Collection> deps = descriptor.getComponentDependencies(); + assertEquals(6, deps.size()); + Iterator> it = deps.iterator(); + + // Test the following injection: + // @Inject + // private NonGenericFieldRole fieldRole; + ComponentDependency dep = it.next(); + assertSame(NonGenericFieldRole.class, dep.getRole()); + assertSame(NonGenericFieldRole.class, dep.getRoleType()); + assertEquals(fieldRoleName, dep.getRoleHint()); + assertSame(NonGenericFieldRole.class, dep.getMappingType()); + assertEquals("fieldRole", dep.getName()); + + // Test the following injection: + // @Inject + // @Named("special") + // private NonGenericFieldRole specialFieldRole; + dep = it.next(); + assertSame(NonGenericFieldRole.class, dep.getRole()); + assertSame(NonGenericFieldRole.class, dep.getRoleType()); + assertEquals("special", dep.getRoleHint()); + assertSame(NonGenericFieldRole.class, dep.getMappingType()); + assertEquals("specialFieldRole", dep.getName()); + + // Test the following injection: + // @Inject + // private GenericFieldRole genericFieldRole; + dep = it.next(); + assertSame(GenericFieldRole.class, dep.getRole()); + assertEquals(new DefaultParameterizedType(JakartaComponentDescriptorFactoryTest.class, GenericFieldRole.class, + String.class), dep.getRoleType()); + assertEquals("default", dep.getRoleHint()); + assertSame(GenericFieldRole.class, dep.getMappingType()); + assertEquals("genericFieldRole", dep.getName()); + + // Test the following injection: + // @Inject + // private GenericFieldRole nonGenericFieldRole; + dep = it.next(); + assertSame(GenericFieldRole.class, dep.getRole()); + assertEquals(GenericFieldRole.class, dep.getRoleType()); + assertEquals("default", dep.getRoleHint()); + assertSame(GenericFieldRole.class, dep.getMappingType()); + assertEquals("nonGenericFieldRole", dep.getName()); + + // Test the following injection: + // @Inject + // private List> roles; + dep = it.next(); + assertSame(NonGenericFieldRole.class, dep.getRole()); + assertEquals("default", dep.getRoleHint()); + assertSame(List.class, dep.getMappingType()); + assertEquals("roles", dep.getName()); + + // Test the following injection: + // @Inject + // private Map> mapRoles; + dep = it.next(); + assertSame(NonGenericFieldRole.class, dep.getRole()); + assertEquals("default", dep.getRoleHint()); + assertSame(Map.class, dep.getMappingType()); + assertEquals("mapRoles", dep.getName()); + } +} diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JavaxComponentAnnotationLoaderTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JavaxComponentAnnotationLoaderTest.java new file mode 100644 index 0000000000..73c90d49a1 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JavaxComponentAnnotationLoaderTest.java @@ -0,0 +1,241 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.component.annotation; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + +import java.lang.reflect.Type; +import java.util.Set; + +import javax.inject.Named; +import javax.inject.Provider; +import javax.inject.Singleton; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.xwiki.component.util.DefaultParameterizedType; + +/** + * Unit tests for {@link ComponentAnnotationLoader}. + * + * @version $Id$ + * @since 1.8.1 + */ +class JavaxComponentAnnotationLoaderTest +{ + @SuppressWarnings("deprecation") + @ComponentRole + public interface NotGenericRole + { + } + + @SuppressWarnings("deprecation") + @ComponentRole + public interface ExtendedRole extends NotGenericRole + { + } + + @Component(staticRegistration = false) + @Singleton + public class RoleImpl implements ExtendedRole + { + } + + /** + * Note that even though it's not necessary we implement Role to ensure that the SuperRoleImpl component will only + * be registered once. + */ + @Component(staticRegistration = false) + @Singleton + public class SuperRoleImpl extends RoleImpl implements NotGenericRole + { + } + + // Test overrides with priorities (see components.txt file) + @Component(value = "test") + @Singleton + public class SimpleRole implements NotGenericRole + { + } + + @Component(value = "test") + @Singleton + public class OverrideRole implements NotGenericRole + { + } + + // Verify backward compatibility for deprecated component-overrides.txt file + @Component(value = "deprecated") + @Singleton + public class DeprecatedSimpleRole implements NotGenericRole + { + } + + @Component(staticRegistration = false) + @Named("customprovider") + @Singleton + public class ProviderImpl implements Provider> + { + @Override + public NotGenericRole get() + { + return new RoleImpl(); + } + } + + @Role + public interface GenericRole + { + } + + @Component(staticRegistration = false) + @Singleton + public class GenericComponent implements GenericRole + { + } + + @Component(staticRegistration = false) + @Singleton + @SuppressWarnings("rawtypes") + public class NonGenericComponent implements GenericRole + { + } + + public abstract class AbstractGenericComponent implements GenericRole + { + } + + @Component(staticRegistration = false) + @Singleton + public class ExtendingGenericComponent extends AbstractGenericComponent + { + } + + @Component(staticRegistration = false) + @Singleton + @SuppressWarnings("rawtypes") + public class ExtendingNonGenericComponent extends AbstractGenericComponent + { + } + + private ComponentAnnotationLoader loader; + + private class TestableComponentAnnotationLoader extends ComponentAnnotationLoader + { + private Logger logger; + + TestableComponentAnnotationLoader(Logger logger) + { + this.logger = logger; + } + + @Override + protected Logger getLogger() + { + return this.logger; + } + } + + @BeforeEach + void setupLogger() + { + // Note: we don't define any expectation on the Logger since we want to be sure that the tests below don't + // generate any logging at all. + this.loader = new TestableComponentAnnotationLoader(mock(Logger.class)); + } + + @Test + void findComponentRoleTypes() + { + assertComponentRoleTypes(RoleImpl.class); + } + + /** + * Verify that we get the same result when we use a class that extends another class (i.e. inheritance works). + */ + @Test + void findComponentRoleTypesWhenClassExtension() + { + assertComponentRoleTypes(SuperRoleImpl.class); + } + + private void assertComponentRoleTypes(Class componentClass) + { + Set type = this.loader.findComponentRoleTypes(componentClass); + assertEquals(2, type.size()); + assertTrue(type.contains(NotGenericRole.class)); + assertTrue(type.contains(ExtendedRole.class)); + } + + @Test + void findComponentRoleTypesForProvider() + { + Set types = this.loader.findComponentRoleTypes(ProviderImpl.class); + + assertEquals(1, types.size()); + assertEquals( + new DefaultParameterizedType(null, Provider.class, new DefaultParameterizedType( + JavaxComponentAnnotationLoaderTest.class, NotGenericRole.class, String.class)), + types.iterator().next()); + } + + @Test + void findComponentRoleTypesWithGenericRole() + { + Set types = this.loader.findComponentRoleTypes(GenericComponent.class); + + assertEquals(1, types.size()); + assertEquals( + new DefaultParameterizedType(JavaxComponentAnnotationLoaderTest.class, GenericRole.class, String.class), + types.iterator().next()); + } + + @Test + void findComponentRoleTypesWithGenericRoleAndNonGenericComponent() + { + Set types = this.loader.findComponentRoleTypes(NonGenericComponent.class); + + assertEquals(1, types.size()); + assertEquals(GenericRole.class, types.iterator().next()); + } + + @Test + void findComponentRoleTypesWithExtendingGenericRole() + { + Set types = this.loader.findComponentRoleTypes(ExtendingGenericComponent.class); + + assertEquals(1, types.size()); + assertEquals( + new DefaultParameterizedType(JavaxComponentAnnotationLoaderTest.class, GenericRole.class, String.class), + types.iterator().next()); + } + + @Test + void findComponentRoleTypesWithExtendingNonGenericRole() + { + Set types = this.loader.findComponentRoleTypes(ExtendingNonGenericComponent.class); + + assertEquals(1, types.size()); + assertEquals(GenericRole.class, types.iterator().next()); + } +} diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/ComponentDescriptorFactoryTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JavaxComponentDescriptorFactoryTest.java similarity index 98% rename from xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/ComponentDescriptorFactoryTest.java rename to xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JavaxComponentDescriptorFactoryTest.java index 3ed69d2ffd..301033caf2 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/ComponentDescriptorFactoryTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/annotation/JavaxComponentDescriptorFactoryTest.java @@ -43,7 +43,7 @@ * @version $Id$ * @since 1.8.1 */ -public class ComponentDescriptorFactoryTest +public class JavaxComponentDescriptorFactoryTest { @ComponentRole public interface NonGenericFieldRole @@ -232,7 +232,7 @@ private void assertComponentDescriptor(Class componentClass, St // private GenericFieldRole genericFieldRole; dep = it.next(); assertSame(GenericFieldRole.class, dep.getRole()); - assertEquals(new DefaultParameterizedType(ComponentDescriptorFactoryTest.class, GenericFieldRole.class, + assertEquals(new DefaultParameterizedType(JavaxComponentDescriptorFactoryTest.class, GenericFieldRole.class, String.class), dep.getRoleType()); assertEquals("default", dep.getRoleHint()); assertSame(GenericFieldRole.class, dep.getMappingType()); diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/embed/EmbeddableComponentManagerTest.java b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/embed/EmbeddableComponentManagerTest.java index b4a9d7710c..70461a5bd3 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/embed/EmbeddableComponentManagerTest.java +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/java/org/xwiki/component/embed/EmbeddableComponentManagerTest.java @@ -19,6 +19,18 @@ */ package org.xwiki.component.embed; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.List; import java.util.Map; @@ -27,6 +39,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.xwiki.component.annotation.DisposePriority; +import org.xwiki.component.descriptor.ComponentDependency; import org.xwiki.component.descriptor.ComponentDescriptor; import org.xwiki.component.descriptor.ComponentInstantiationStrategy; import org.xwiki.component.descriptor.DefaultComponentDependency; @@ -34,6 +47,7 @@ import org.xwiki.component.manager.ComponentEventManager; import org.xwiki.component.manager.ComponentLookupException; import org.xwiki.component.manager.ComponentManager; +import org.xwiki.component.manager.ComponentRepositoryException; import org.xwiki.component.phase.Disposable; import org.xwiki.component.phase.Initializable; import org.xwiki.component.phase.InitializationException; @@ -41,16 +55,7 @@ import org.xwiki.test.LogLevel; import org.xwiki.test.junit5.LogCaptureExtension; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; +import jakarta.inject.Provider; /** * Unit tests for {@link EmbeddableComponentManager}. @@ -58,25 +63,25 @@ * @version $Id$ * @since 2.0M1 */ -// This class needs to remain public because some interfaces are reused in ProviderIntegrationTest +// This class needs to remain public because some interfaces are reused in other tests public class EmbeddableComponentManagerTest { @RegisterExtension private LogCaptureExtension logCapture = new LogCaptureExtension(LogLevel.ERROR); - public interface Role + public interface TestRole { } - public static class RoleImpl implements Role + public static class RoleImpl implements TestRole { } - public static class OtherRoleImpl implements Role + public static class OtherRoleImpl implements TestRole { } - public static class FailingRoleImpl implements Role, Initializable + public static class FailingRoleImpl implements TestRole, Initializable { @Override public void initialize() throws InitializationException @@ -87,7 +92,7 @@ public void initialize() throws InitializationException private static String lastDisposedComponent; - public static class InitializableRoleImpl implements Role, Initializable + public static class InitializableRoleImpl implements TestRole, Initializable { private boolean initialized = false; @@ -103,7 +108,7 @@ public boolean isInitialized() } } - public static class DisposableRoleImpl implements Role, Disposable + public static class DisposableRoleImpl implements TestRole, Disposable { private boolean finalized = false; @@ -121,7 +126,7 @@ public boolean isFinalized() } @DisposePriority(2000) - public static class DisposableWithPriorityRoleImpl implements Role, Disposable + public static class DisposableWithPriorityRoleImpl implements TestRole, Disposable { private boolean finalized = false; @@ -138,7 +143,7 @@ public boolean isFinalized() } } - public static class LoggingRoleImpl implements Role + public static class LoggingRoleImpl implements TestRole { private Logger logger; @@ -161,17 +166,17 @@ void getComponentDescriptorList() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); - d1.setRoleType(Role.class); + DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); + d1.setRoleType(TestRole.class); d1.setRoleHint("hint1"); ecm.registerComponent(d1); - DefaultComponentDescriptor d2 = new DefaultComponentDescriptor<>(); - d2.setRoleType(Role.class); + DefaultComponentDescriptor d2 = new DefaultComponentDescriptor<>(); + d2.setRoleType(TestRole.class); d2.setRoleHint("hint2"); ecm.registerComponent(d2); - List> cds = ecm.getComponentDescriptorList(Role.class); + List> cds = ecm.getComponentDescriptorList(TestRole.class); assertEquals(2, cds.size()); assertTrue(cds.contains(d1)); assertTrue(cds.contains(d2)); @@ -183,7 +188,7 @@ void getComponentDescriptorListInParent() throws Exception EmbeddableComponentManager ecm = new EmbeddableComponentManager(); ecm.setParent(createParentComponentManager()); - List> cds = ecm.getComponentDescriptorList((Type) Role.class); + List> cds = ecm.getComponentDescriptorList((Type) TestRole.class); assertEquals(1, cds.size()); } @@ -193,7 +198,7 @@ void getComponentDescriptorInParent() throws Exception EmbeddableComponentManager ecm = new EmbeddableComponentManager(); ecm.setParent(createParentComponentManager("somehint")); - ComponentDescriptor cd = ecm.getComponentDescriptor(Role.class, "somehint"); + ComponentDescriptor cd = ecm.getComponentDescriptor(TestRole.class, "somehint"); assertNotNull(cd); assertEquals(RoleImpl.class, cd.getImplementation()); } @@ -205,15 +210,15 @@ void getComponentDescriptorWhenSomeComponentsInParent() throws Exception ecm.setParent(createParentComponentManager()); // Register a component with the same Role and Hint as in the parent - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setImplementation(RoleImpl.class); - Role roleImpl = new RoleImpl(); + TestRole roleImpl = new RoleImpl(); ecm.registerComponent(cd1, roleImpl); // Register a component with the same Role as in the parent but with a different hint - DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); - cd2.setRoleType(Role.class); + DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); + cd2.setRoleType(TestRole.class); cd2.setRoleHint("hint"); cd2.setImplementation(RoleImpl.class); ecm.registerComponent(cd2); @@ -221,7 +226,7 @@ void getComponentDescriptorWhenSomeComponentsInParent() throws Exception // Verify that the components are found // Note: We find only 2 components since 2 components are registered with the same Role and Hint. - List> descriptors = ecm.getComponentDescriptorList(Role.class); + List> descriptors = ecm.getComponentDescriptorList(TestRole.class); assertEquals(2, descriptors.size()); } @@ -230,20 +235,20 @@ void registerComponentOverExistingOne() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); - d1.setRoleType(Role.class); + DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); + d1.setRoleType(TestRole.class); d1.setImplementation(RoleImpl.class); ecm.registerComponent(d1); - Object instance = ecm.getInstance(Role.class); + Object instance = ecm.getInstance(TestRole.class); assertSame(RoleImpl.class, instance.getClass()); - DefaultComponentDescriptor d2 = new DefaultComponentDescriptor<>(); - d2.setRoleType(Role.class); + DefaultComponentDescriptor d2 = new DefaultComponentDescriptor<>(); + d2.setRoleType(TestRole.class); d2.setImplementation(OtherRoleImpl.class); ecm.registerComponent(d2); - instance = ecm.getInstance(Role.class); + instance = ecm.getInstance(TestRole.class); assertSame(OtherRoleImpl.class, instance.getClass()); } @@ -252,13 +257,13 @@ void registerComponentInstance() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); - d1.setRoleType(Role.class); + DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); + d1.setRoleType(TestRole.class); d1.setImplementation(RoleImpl.class); - Role instance = new RoleImpl(); + TestRole instance = new RoleImpl(); ecm.registerComponent(d1, instance); - assertSame(instance, ecm.getInstance(Role.class)); + assertSame(instance, ecm.getInstance(TestRole.class)); } @Test @@ -266,13 +271,13 @@ void unregisterComponent() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); - d1.setRoleType(Role.class); + DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); + d1.setRoleType(TestRole.class); d1.setImplementation(RoleImpl.class); ecm.registerComponent(d1); // Verify that the component is properly registered - assertSame(RoleImpl.class, ecm.getInstance(Role.class).getClass()); + assertSame(RoleImpl.class, ecm.getInstance(TestRole.class).getClass()); ecm.unregisterComponent(d1.getRoleType(), d1.getRoleHint()); @@ -290,7 +295,7 @@ void getInstanceWhenComponentInParent() throws Exception EmbeddableComponentManager ecm = new EmbeddableComponentManager(); ecm.setParent(createParentComponentManager()); - Role instance = ecm.getInstance(Role.class); + TestRole instance = ecm.getInstance(TestRole.class); assertNotNull(instance); } @@ -301,16 +306,16 @@ void getInstanceListAndMapWhenSameTypeAndHintAndHintPriorityThanParent() throws ecm.setParent(createParentComponentManager()); // Register a component with the same type, hint and hint priority as in the parent - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setImplementation(RoleImpl.class); - Role roleInstance = new RoleImpl(); + TestRole roleInstance = new RoleImpl(); ecm.registerComponent(cd1, roleInstance); - List instanceList = ecm.getInstanceList(Role.class); + List instanceList = ecm.getInstanceList(TestRole.class); assertEquals(List.of(roleInstance), instanceList); - Map instances = ecm.getInstanceMap(Role.class); + Map instances = ecm.getInstanceMap(TestRole.class); assertEquals(1, instances.size()); assertSame(roleInstance, instances.get("default")); } @@ -319,23 +324,23 @@ void getInstanceListAndMapWhenSameTypeAndHintAndHintPriorityThanParent() throws void getInstanceListAndMapWhenSameTypeAndHintAndLowerHintPriorityThanParent() throws Exception { ComponentManager parentcm = createParentComponentManager(); - Role parentInstance = parentcm.getInstance(Role.class); + TestRole parentInstance = parentcm.getInstance(TestRole.class); EmbeddableComponentManager ecm = new EmbeddableComponentManager(); ecm.setParent(parentcm); // Register a component with the same type, hint as in the parent but lower hint priority - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setImplementation(RoleImpl.class); cd1.setRoleHintPriority(ComponentDescriptor.DEFAULT_PRIORITY + 1); - Role roleInstance = new RoleImpl(); + TestRole roleInstance = new RoleImpl(); ecm.registerComponent(cd1, roleInstance); - List instanceList = ecm.getInstanceList(Role.class); + List instanceList = ecm.getInstanceList(TestRole.class); assertEquals(List.of(parentInstance), instanceList); - Map instances = ecm.getInstanceMap(Role.class); + Map instances = ecm.getInstanceMap(TestRole.class); assertEquals(1, instances.size()); assertSame(parentInstance, instances.get("default")); } @@ -344,23 +349,23 @@ void getInstanceListAndMapWhenSameTypeAndHintAndLowerHintPriorityThanParent() th void getInstanceListAndMapWhenSameTypeAndHintPriorityThanParent() throws Exception { ComponentManager parentcm = createParentComponentManager(); - Role parentInstance = parentcm.getInstance(Role.class); + TestRole parentInstance = parentcm.getInstance(TestRole.class); EmbeddableComponentManager ecm = new EmbeddableComponentManager(); ecm.setParent(parentcm); // Register a component with the same type, hint as in the parent but lower hint priority - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setRoleHint("hint1"); cd1.setImplementation(RoleImpl.class); - Role roleInstance = new RoleImpl(); + TestRole roleInstance = new RoleImpl(); ecm.registerComponent(cd1, roleInstance); - List instanceList = ecm.getInstanceList(Role.class); + List instanceList = ecm.getInstanceList(TestRole.class); assertEquals(List.of(roleInstance, parentInstance), instanceList); - Map instances = ecm.getInstanceMap(Role.class); + Map instances = ecm.getInstanceMap(TestRole.class); assertEquals(2, instances.size()); assertSame(roleInstance, instances.get("hint1")); assertSame(parentInstance, instances.get("default")); @@ -370,24 +375,24 @@ void getInstanceListAndMapWhenSameTypeAndHintPriorityThanParent() throws Excepti void getInstanceListAndMapWhenSameTypeAndLowerHintPriorityThanParent() throws Exception { ComponentManager parentcm = createParentComponentManager(); - Role parentInstance = parentcm.getInstance(Role.class); + TestRole parentInstance = parentcm.getInstance(TestRole.class); EmbeddableComponentManager ecm = new EmbeddableComponentManager(); ecm.setParent(parentcm); // Register a component with the same type, hint as in the parent but lower hint priority - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setRoleHint("hint1"); cd1.setImplementation(RoleImpl.class); cd1.setRoleTypePriority(ComponentDescriptor.DEFAULT_PRIORITY + 1); - Role roleInstance = new RoleImpl(); + TestRole roleInstance = new RoleImpl(); ecm.registerComponent(cd1, roleInstance); - List instanceList = ecm.getInstanceList(Role.class); + List instanceList = ecm.getInstanceList(TestRole.class); assertEquals(List.of(parentInstance, roleInstance), instanceList); - Map instances = ecm.getInstanceMap(Role.class); + Map instances = ecm.getInstanceMap(TestRole.class); assertEquals(2, instances.size()); assertSame(roleInstance, instances.get("hint1")); assertSame(parentInstance, instances.get("default")); @@ -398,33 +403,33 @@ void getInstanceListAndMapWithoutTypePriorities() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setRoleHint("hint1"); cd1.setImplementation(RoleImpl.class); - Role roleImpl1 = new RoleImpl(); + TestRole roleImpl1 = new RoleImpl(); ecm.registerComponent(cd1, roleImpl1); - DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); - cd2.setRoleType(Role.class); + DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); + cd2.setRoleType(TestRole.class); cd2.setRoleHint("hint2"); cd2.setImplementation(RoleImpl.class); ecm.registerComponent(cd2); - Role roleImpl2 = new RoleImpl(); + TestRole roleImpl2 = new RoleImpl(); ecm.registerComponent(cd2, roleImpl2); - DefaultComponentDescriptor cd3 = new DefaultComponentDescriptor<>(); - cd3.setRoleType(Role.class); + DefaultComponentDescriptor cd3 = new DefaultComponentDescriptor<>(); + cd3.setRoleType(TestRole.class); cd3.setRoleHint("hint3"); cd3.setImplementation(RoleImpl.class); ecm.registerComponent(cd3); - Role roleImpl3 = new RoleImpl(); + TestRole roleImpl3 = new RoleImpl(); ecm.registerComponent(cd3, roleImpl3); - List instanceList = ecm.getInstanceList(Role.class); + List instanceList = ecm.getInstanceList(TestRole.class); assertEquals(List.of(roleImpl1, roleImpl2, roleImpl3), instanceList); - Map instances = ecm.getInstanceMap(Role.class); + Map instances = ecm.getInstanceMap(TestRole.class); assertEquals(3, instances.size()); assertSame(roleImpl1, instances.get("hint1")); assertSame(roleImpl2, instances.get("hint2")); @@ -436,36 +441,36 @@ void getInstanceListAndMapWithTypePriorities() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setRoleHint("hint1"); cd1.setRoleTypePriority(3); cd1.setImplementation(RoleImpl.class); - Role roleImpl1 = new RoleImpl(); + TestRole roleImpl1 = new RoleImpl(); ecm.registerComponent(cd1, roleImpl1); - DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); - cd2.setRoleType(Role.class); + DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); + cd2.setRoleType(TestRole.class); cd2.setRoleHint("hint2"); cd2.setRoleTypePriority(1); cd2.setImplementation(RoleImpl.class); ecm.registerComponent(cd2); - Role roleImpl2 = new RoleImpl(); + TestRole roleImpl2 = new RoleImpl(); ecm.registerComponent(cd2, roleImpl2); - DefaultComponentDescriptor cd3 = new DefaultComponentDescriptor<>(); - cd3.setRoleType(Role.class); + DefaultComponentDescriptor cd3 = new DefaultComponentDescriptor<>(); + cd3.setRoleType(TestRole.class); cd3.setRoleHint("hint3"); cd3.setRoleTypePriority(2); cd3.setImplementation(RoleImpl.class); ecm.registerComponent(cd3); - Role roleImpl3 = new RoleImpl(); + TestRole roleImpl3 = new RoleImpl(); ecm.registerComponent(cd3, roleImpl3); - List instanceList = ecm.getInstanceList(Role.class); + List instanceList = ecm.getInstanceList(TestRole.class); assertEquals(List.of(roleImpl2, roleImpl3, roleImpl1), instanceList); - Map instances = ecm.getInstanceMap(Role.class); + Map instances = ecm.getInstanceMap(TestRole.class); assertEquals(3, instances.size()); assertSame(roleImpl2, instances.get("hint2")); assertSame(roleImpl3, instances.get("hint3")); @@ -477,71 +482,67 @@ void getInstanceListAndMapWhenFailingComponent() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setRoleHint("hint1"); cd1.setImplementation(RoleImpl.class); ecm.registerComponent(cd1); - List instanceList = ecm.getInstanceList(Role.class); + List instanceList = ecm.getInstanceList(TestRole.class); assertEquals(1, instanceList.size()); assertSame(RoleImpl.class, instanceList.get(0).getClass()); - Map instanceMap = ecm.getInstanceMap(Role.class); + Map instanceMap = ecm.getInstanceMap(TestRole.class); assertEquals(1, instanceMap.size()); assertSame(RoleImpl.class, instanceMap.get("hint1").getClass()); // Register a component which fail to initialize but is not mandatory - DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); - cd2.setRoleType(Role.class); + DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); + cd2.setRoleType(TestRole.class); cd2.setRoleHint("hint2"); cd2.setImplementation(FailingRoleImpl.class); ecm.registerComponent(cd2); ComponentLookupException exception = - assertThrows(ComponentLookupException.class, () -> ecm.getInstance(Role.class, "hint2")); + assertThrows(ComponentLookupException.class, () -> ecm.getInstance(TestRole.class, "hint2")); assertEquals("fail", exception.getCause().getMessage()); - instanceList = ecm.getInstanceList(Role.class); + instanceList = ecm.getInstanceList(TestRole.class); assertEquals(1, instanceList.size()); assertSame(RoleImpl.class, instanceList.get(0).getClass()); - assertEquals( - "Failed to lookup component with" - + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$Role] and hint [hint2]", + assertEquals("Failed to lookup component with" + + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$TestRole] and hint [hint2]", this.logCapture.getMessage(0)); - instanceMap = ecm.getInstanceMap(Role.class); + instanceMap = ecm.getInstanceMap(TestRole.class); assertEquals(1, instanceMap.size()); assertSame(RoleImpl.class, instanceMap.get("hint1").getClass()); - assertEquals( - "Failed to lookup component with" - + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$Role] and hint [hint2]", + assertEquals("Failed to lookup component with" + + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$TestRole] and hint [hint2]", this.logCapture.getMessage(1)); // Register a component which fail to initialize and is mandatory - DefaultComponentDescriptor cd3 = new DefaultComponentDescriptor<>(); - cd3.setRoleType(Role.class); + DefaultComponentDescriptor cd3 = new DefaultComponentDescriptor<>(); + cd3.setRoleType(TestRole.class); cd3.setRoleHint("hint3"); cd3.setMandatory(true); cd3.setImplementation(FailingRoleImpl.class); ecm.registerComponent(cd3); - exception = assertThrows(ComponentLookupException.class, () -> ecm.getInstanceList(Role.class)); + exception = assertThrows(ComponentLookupException.class, () -> ecm.getInstanceList(TestRole.class)); assertEquals("fail", exception.getCause().getMessage()); - assertEquals( - "Failed to lookup component with" - + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$Role] and hint [hint2]", + assertEquals("Failed to lookup component with" + + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$TestRole] and hint [hint2]", this.logCapture.getMessage(2)); - exception = assertThrows(ComponentLookupException.class, () -> ecm.getInstanceMap(Role.class)); + exception = assertThrows(ComponentLookupException.class, () -> ecm.getInstanceMap(TestRole.class)); assertEquals("fail", exception.getCause().getMessage()); - assertEquals( - "Failed to lookup component with" - + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$Role] and hint [hint2]", + assertEquals("Failed to lookup component with" + + " type [interface org.xwiki.component.embed.EmbeddableComponentManagerTest$TestRole] and hint [hint2]", this.logCapture.getMessage(3)); } @@ -550,13 +551,13 @@ void hasComponent() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); - d1.setRoleType(Role.class); + DefaultComponentDescriptor d1 = new DefaultComponentDescriptor<>(); + d1.setRoleType(TestRole.class); d1.setRoleHint("default"); ecm.registerComponent(d1); - assertTrue(ecm.hasComponent(Role.class)); - assertTrue(ecm.hasComponent(Role.class, "default")); + assertTrue(ecm.hasComponent(TestRole.class)); + assertTrue(ecm.hasComponent(TestRole.class, "default")); } @Test @@ -565,8 +566,8 @@ void hasComponentWhenComponentInParent() throws Exception EmbeddableComponentManager ecm = new EmbeddableComponentManager(); ecm.setParent(createParentComponentManager()); - assertTrue(ecm.hasComponent(Role.class)); - assertTrue(ecm.hasComponent(Role.class, "default")); + assertTrue(ecm.hasComponent(TestRole.class)); + assertTrue(ecm.hasComponent(TestRole.class, "default")); } @Test @@ -574,8 +575,8 @@ void loggingInjection() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor d = new DefaultComponentDescriptor<>(); - d.setRoleType(Role.class); + DefaultComponentDescriptor d = new DefaultComponentDescriptor<>(); + d.setRoleType(TestRole.class); d.setImplementation(LoggingRoleImpl.class); DefaultComponentDependency dependencyDescriptor = new DefaultComponentDependency(); @@ -585,7 +586,7 @@ void loggingInjection() throws Exception d.addComponentDependency(dependencyDescriptor); ecm.registerComponent(d); - LoggingRoleImpl impl = ecm.getInstance(Role.class); + LoggingRoleImpl impl = ecm.getInstance(TestRole.class); assertNotNull(impl.getLogger()); } @@ -597,8 +598,8 @@ private ComponentManager createParentComponentManager() throws Exception private ComponentManager createParentComponentManager(String hint) throws Exception { EmbeddableComponentManager parent = new EmbeddableComponentManager(); - DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); - cd.setRoleType(Role.class); + DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); cd.setImplementation(RoleImpl.class); if (hint != null) { cd.setRoleHint(hint); @@ -612,11 +613,11 @@ void registerInitializableComponent() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); - cd.setRoleType(Role.class); + DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); cd.setImplementation(InitializableRoleImpl.class); ecm.registerComponent(cd); - InitializableRoleImpl instance = ecm.getInstance(Role.class); + InitializableRoleImpl instance = ecm.getInstance(TestRole.class); assertTrue(instance.isInitialized()); } @@ -626,13 +627,13 @@ void unregisterDisposableSingletonComponent() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); - cd.setRoleType(Role.class); + DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); cd.setImplementation(DisposableRoleImpl.class); cd.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); ecm.registerComponent(cd); - DisposableRoleImpl instance = ecm.getInstance(Role.class); + DisposableRoleImpl instance = ecm.getInstance(TestRole.class); assertFalse(instance.isFinalized()); @@ -646,8 +647,8 @@ void unregisterDisposableSingletonComponentWithInstance() { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); - cd.setRoleType(Role.class); + DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); cd.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); DisposableRoleImpl instance = new DisposableRoleImpl(); @@ -665,10 +666,10 @@ void release() throws Exception { final EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - final DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); - cd.setRoleType(Role.class); + final DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); cd.setImplementation(RoleImpl.class); - Role roleImpl = new RoleImpl(); + TestRole roleImpl = new RoleImpl(); ecm.registerComponent(cd, roleImpl); final ComponentEventManager cem = mock(ComponentEventManager.class); @@ -679,8 +680,8 @@ void release() throws Exception verify(cem).notifyComponentUnregistered(cd, ecm); verify(cem).notifyComponentRegistered(cd, ecm); - assertNotNull(ecm.getInstance(Role.class)); - assertNotSame(roleImpl, ecm.getInstance(Role.class)); + assertNotNull(ecm.getInstance(TestRole.class)); + assertNotSame(roleImpl, ecm.getInstance(TestRole.class)); } @Test @@ -688,13 +689,13 @@ void releaseDisposableComponent() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); - cd.setRoleType(Role.class); + DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); cd.setImplementation(DisposableRoleImpl.class); cd.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); ecm.registerComponent(cd); - DisposableRoleImpl instance = ecm.getInstance(Role.class); + DisposableRoleImpl instance = ecm.getInstance(TestRole.class); assertFalse(instance.isFinalized()); @@ -708,8 +709,8 @@ void registerComponentNotification() throws Exception { final EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - final DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); - cd.setRoleType(Role.class); + final DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); cd.setImplementation(RoleImpl.class); final ComponentEventManager cem = mock(ComponentEventManager.class); @@ -725,8 +726,8 @@ void unregisterComponentNotification() throws Exception { final EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - final DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); - cd.setRoleType(Role.class); + final DefaultComponentDescriptor cd = new DefaultComponentDescriptor<>(); + cd.setRoleType(TestRole.class); cd.setImplementation(RoleImpl.class); ecm.registerComponent(cd); @@ -743,13 +744,13 @@ void registerComponentNotificationOnSecondRegistration() throws Exception { final EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - final DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + final DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setImplementation(RoleImpl.class); ecm.registerComponent(cd1); - final DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); - cd2.setRoleType(Role.class); + final DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); + cd2.setRoleType(TestRole.class); cd2.setImplementation(OtherRoleImpl.class); final ComponentEventManager cem = mock(ComponentEventManager.class); @@ -771,22 +772,22 @@ void dispose() throws Exception // - a second one using a default dispose priority // First component - DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); - cd1.setRoleType(Role.class); + DefaultComponentDescriptor cd1 = new DefaultComponentDescriptor<>(); + cd1.setRoleType(TestRole.class); cd1.setRoleHint("instance1"); cd1.setImplementation(DisposableWithPriorityRoleImpl.class); cd1.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); ecm.registerComponent(cd1); - DisposableWithPriorityRoleImpl instance1 = ecm.getInstance(Role.class, "instance1"); + DisposableWithPriorityRoleImpl instance1 = ecm.getInstance(TestRole.class, "instance1"); // Second component - DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); - cd2.setRoleType(Role.class); + DefaultComponentDescriptor cd2 = new DefaultComponentDescriptor<>(); + cd2.setRoleType(TestRole.class); cd2.setRoleHint("instance2"); cd2.setImplementation(DisposableRoleImpl.class); cd2.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); ecm.registerComponent(cd2); - DisposableRoleImpl instance2 = ecm.getInstance(Role.class, "instance2"); + DisposableRoleImpl instance2 = ecm.getInstance(TestRole.class, "instance2"); assertFalse(instance1.isFinalized()); assertFalse(instance2.isFinalized()); @@ -796,8 +797,8 @@ void dispose() throws Exception assertTrue(instance1.isFinalized()); assertTrue(instance2.isFinalized()); - assertNull(ecm.getComponentDescriptor(Role.class, "instance1")); - assertNull(ecm.getComponentDescriptor(Role.class, "instance2")); + assertNull(ecm.getComponentDescriptor(TestRole.class, "instance1")); + assertNull(ecm.getComponentDescriptor(TestRole.class, "instance2")); assertNotNull(ecm.getComponentDescriptor(ComponentManager.class, "default")); // Verify that dispose() has been called in the right order. @@ -822,7 +823,7 @@ void diposeWhenImplementationIsECM() ecm.dispose(); } - public static class ComponentDescriptorRoleImpl implements Role + public static class ComponentDescriptorRoleImpl implements TestRole { private ComponentDescriptor descriptor; @@ -837,8 +838,8 @@ void componentDescriptorInjection() throws Exception { EmbeddableComponentManager ecm = new EmbeddableComponentManager(); - DefaultComponentDescriptor d = new DefaultComponentDescriptor<>(); - d.setRoleType(Role.class); + DefaultComponentDescriptor d = new DefaultComponentDescriptor<>(); + d.setRoleType(TestRole.class); d.setImplementation(ComponentDescriptorRoleImpl.class); DefaultComponentDependency dependencyDescriptor = new DefaultComponentDependency(); @@ -849,7 +850,7 @@ void componentDescriptorInjection() throws Exception d.addComponentDependency(dependencyDescriptor); ecm.registerComponent(d); - ComponentDescriptorRoleImpl impl = ecm.getInstance(Role.class); + ComponentDescriptorRoleImpl impl = ecm.getInstance(TestRole.class); assertNotNull(impl.getComponentDescriptor()); } @@ -859,4 +860,117 @@ void constructorWithNameSpace() EmbeddableComponentManager ecm = new EmbeddableComponentManager("namespace"); assertEquals("namespace", ecm.getNamespace()); } + + public static class JakartaProvider implements Provider + { + @Override + public String get() + { + return "jakarta"; + } + } + + public static class JavaXProvider implements javax.inject.Provider + { + @Override + public String get() + { + return "javax"; + } + } + + public static class ComponentWithJakartaProvider + { + Provider provider; + + public String get() + { + return this.provider.get(); + } + } + + public static class ComponentWithJavaXProvider + { + javax.inject.Provider provider; + + public String get() + { + return this.provider.get(); + } + } + + private static DefaultComponentDependency dependency(Type roleType, String roleHint, String field) + { + DefaultComponentDependency dependency = new DefaultComponentDependency<>(); + dependency.setRoleType(roleType); + dependency.setRoleHint(roleHint); + dependency.setName(field); + + return dependency; + } + + private void registerComponent(EmbeddableComponentManager ecm, Type roleType, String roleHint, + Class implementation, ComponentDependency... dependencies) throws ComponentRepositoryException + { + DefaultComponentDescriptor djakarta = new DefaultComponentDescriptor<>(); + djakarta.setRoleType(roleType); + djakarta.setRoleHint(roleHint); + djakarta.setImplementation(implementation); + + for (ComponentDependency dependency : dependencies) { + djakarta.addComponentDependency(dependency); + } + + ecm.registerComponent(djakarta); + } + + @Test + void getInstanceJakartaJavaxProvider() throws Exception + { + EmbeddableComponentManager ecm = new EmbeddableComponentManager(); + + ParameterizedType jakartaRoleType = new DefaultParameterizedType(null, Provider.class, String.class); + registerComponent(ecm, jakartaRoleType, "jakarta", JakartaProvider.class); + + ParameterizedType javaxRoleType = new DefaultParameterizedType(null, javax.inject.Provider.class, String.class); + registerComponent(ecm, javaxRoleType, "javax", JavaXProvider.class); + + assertEquals("jakarta", ecm.>getInstance(jakartaRoleType, "jakarta").get()); + assertEquals("javax", ecm.>getInstance(jakartaRoleType, "javax").get()); + + assertEquals("javax", ecm.>getInstance(javaxRoleType, "javax").get()); + assertEquals("jakarta", ecm.>getInstance(javaxRoleType, "jakarta").get()); + } + + @Test + void injectJakartaJavaxProvider() throws Exception + { + EmbeddableComponentManager ecm = new EmbeddableComponentManager(); + + ParameterizedType jakartaRoleType = new DefaultParameterizedType(null, Provider.class, String.class); + registerComponent(ecm, jakartaRoleType, "jakarta", JakartaProvider.class); + + ParameterizedType javaxRoleType = new DefaultParameterizedType(null, javax.inject.Provider.class, String.class); + registerComponent(ecm, javaxRoleType, "javax", JavaXProvider.class); + + registerComponent(ecm, ComponentWithJakartaProvider.class, "jakarta", ComponentWithJakartaProvider.class, + dependency(jakartaRoleType, "jakarta", "provider")); + registerComponent(ecm, ComponentWithJakartaProvider.class, "javax", ComponentWithJakartaProvider.class, + dependency(jakartaRoleType, "javax", "provider")); + + registerComponent(ecm, ComponentWithJavaXProvider.class, "jakarta", ComponentWithJavaXProvider.class, + dependency(javaxRoleType, "jakarta", "provider")); + registerComponent(ecm, ComponentWithJavaXProvider.class, "javax", ComponentWithJavaXProvider.class, + dependency(javaxRoleType, "javax", "provider")); + + assertEquals("jakarta", + ecm.getInstance(ComponentWithJakartaProvider.class, "jakarta").get()); + assertEquals("javax", + ecm.getInstance(ComponentWithJakartaProvider.class, "javax").get()); + + assertEquals("jakarta", + ecm.getInstance(ComponentWithJavaXProvider.class, "jakarta").get()); + assertEquals("javax", + ecm.getInstance(ComponentWithJavaXProvider.class, "javax").get()); + } } diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/resources/META-INF/component-overrides.txt b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/resources/META-INF/component-overrides.txt index 9781374229..9458772aa4 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/resources/META-INF/component-overrides.txt +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/resources/META-INF/component-overrides.txt @@ -1 +1 @@ -org.xwiki.component.annotation.ComponentAnnotationLoaderTest$DeprecatedOverrideRole \ No newline at end of file +org.xwiki.component.annotation.JakartaComponentAnnotationLoaderTest$DeprecatedOverrideRole diff --git a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/resources/META-INF/components.txt b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/resources/META-INF/components.txt index 79fe730707..428de086df 100644 --- a/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/resources/META-INF/components.txt +++ b/xwiki-commons-core/xwiki-commons-component/xwiki-commons-component-default/src/test/resources/META-INF/components.txt @@ -1,11 +1,17 @@ -org.xwiki.component.annotation.ComponentAnnotationLoaderTest$DeprecatedSimpleRole -org.xwiki.component.annotation.ComponentAnnotationLoaderTest$DeprecatedOverrideRole -org.xwiki.component.annotation.ComponentAnnotationLoaderTest$SimpleRole -500:org.xwiki.component.annotation.ComponentAnnotationLoaderTest$OverrideRole +org.xwiki.component.annotation.JakartaComponentAnnotationLoaderTest$DeprecatedSimpleRole +org.xwiki.component.annotation.JakartaComponentAnnotationLoaderTest$DeprecatedOverrideRole +org.xwiki.component.annotation.JakartaComponentAnnotationLoaderTest$SimpleRole +500:org.xwiki.component.annotation.JakartaComponentAnnotationLoaderTest$OverrideRole -org.xwiki.component.ProviderIntegrationTest$TestComponentWithProviders -org.xwiki.component.ProviderIntegrationTest$TestProvider1 -org.xwiki.component.ProviderIntegrationTest$TestProvider12 -org.xwiki.component.ProviderIntegrationTest$TestProvider2 -org.xwiki.component.ProviderIntegrationTest$TestComponentWithProviderInException -org.xwiki.component.ProviderIntegrationTest$TestProviderWithExceptionInInitialize \ No newline at end of file +org.xwiki.component.JakartaProviderIntegrationTest$TestComponentWithProviders +org.xwiki.component.JavaxProviderIntegrationTest$TestComponentWithProviders +org.xwiki.component.JakartaProviderIntegrationTest$TestProvider1 +org.xwiki.component.JavaxProviderIntegrationTest$TestProvider1 +org.xwiki.component.JakartaProviderIntegrationTest$TestProvider12 +org.xwiki.component.JavaxProviderIntegrationTest$TestProvider12 +org.xwiki.component.JakartaProviderIntegrationTest$TestProvider2 +org.xwiki.component.JavaxProviderIntegrationTest$TestProvider2 +org.xwiki.component.JakartaProviderIntegrationTest$TestComponentWithProviderInException +org.xwiki.component.JavaxProviderIntegrationTest$TestComponentWithProviderInException +org.xwiki.component.JakartaProviderIntegrationTest$TestProviderWithExceptionInInitialize +org.xwiki.component.JavaxProviderIntegrationTest$TestProviderWithExceptionInInitialize diff --git a/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/pom.xml b/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/pom.xml index 6484a101c3..860b7cbf00 100644 --- a/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/pom.xml +++ b/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/pom.xml @@ -41,8 +41,13 @@ ${project.version} - javax.servlet - javax.servlet-api + org.xwiki.commons + xwiki-commons-jakartabridge-servlet + ${project.version} + + + jakarta.servlet + jakarta.servlet-api diff --git a/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/src/main/java/org/xwiki/environment/internal/ServletEnvironment.java b/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/src/main/java/org/xwiki/environment/internal/ServletEnvironment.java index b783d8a3f6..76f93bae91 100644 --- a/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/src/main/java/org/xwiki/environment/internal/ServletEnvironment.java +++ b/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/src/main/java/org/xwiki/environment/internal/ServletEnvironment.java @@ -27,10 +27,12 @@ import java.net.URL; import javax.inject.Singleton; -import javax.servlet.ServletContext; import org.apache.commons.lang3.exception.ExceptionUtils; import org.xwiki.component.annotation.Component; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.ServletContext; /** * Defines what an Environment means in a Servlet environment. @@ -42,35 +44,65 @@ @Singleton public class ServletEnvironment extends AbstractEnvironment { + /** + * @see #getJakartaServletContext() + */ + private ServletContext jakartaServletContext; + /** * @see #getServletContext() */ - private ServletContext servletContext; + private javax.servlet.ServletContext javaxServletContext; + + /** + * @param servletContext see {@link #getServletContext()} + */ + public void setServletContext(javax.servlet.ServletContext servletContext) + { + this.javaxServletContext = servletContext; + this.jakartaServletContext = JakartaServletBridge.toJakarta(servletContext); + } /** * @param servletContext see {@link #getServletContext()} */ public void setServletContext(ServletContext servletContext) { - this.servletContext = servletContext; + this.jakartaServletContext = servletContext; + } + + /** + * @return the legacy Javax Servlet Context + * @deprecated use {@link #getJakartaServletContext()} instead + */ + @Deprecated(since = "42.0.0") + public javax.servlet.ServletContext getServletContext() + { + if (this.javaxServletContext == null) { + this.javaxServletContext = JakartaServletBridge.toJavax(getJakartaServletContext()); + } + + return this.javaxServletContext; } /** * @return the Servlet Context + * @since 42.0.0 */ - public ServletContext getServletContext() + public ServletContext getJakartaServletContext() { - if (this.servletContext == null) { - throw new RuntimeException("The Servlet Environment has not been properly initialized " - + "(The Servlet Context is not set)"); + if (this.jakartaServletContext == null) { + throw new RuntimeException( + "The Servlet Environment has not been properly initialized (The Servlet Context is not set)"); } - return this.servletContext; + + return this.jakartaServletContext; } @Override public InputStream getResourceAsStream(String resourceName) { - return getServletContext().getResourceAsStream(resourceName); + return getJakartaServletContext().getResourceAsStream(resourceName); } @Override @@ -78,18 +110,19 @@ public URL getResource(String resourceName) { URL url; try { - url = getServletContext().getResource(resourceName); + url = getJakartaServletContext().getResource(resourceName); // ensure to normalize the URI, we don't want relative path. if (url != null) { url = url.toURI().normalize().toURL(); } - // We're catching IllegalArgumentException which might be thrown by Tomcat when trying to resolve path such as - // `templates/../..` + // We're catching IllegalArgumentException which might be thrown by Tomcat when trying to resolve path such + // as + // `templates/../..` } catch (MalformedURLException | URISyntaxException | IllegalArgumentException e) { url = null; - this.logger.warn("Error getting resource [{}] because of invalid path format. Reason: [{}]", - resourceName, e.getMessage()); + this.logger.warn("Error getting resource [{}] because of invalid path format. Reason: [{}]", resourceName, + e.getMessage()); } return url; } @@ -100,7 +133,7 @@ protected String getTemporaryDirectoryName() final String tmpDirectory = super.getTemporaryDirectoryName(); try { if (tmpDirectory == null) { - File tempDir = (File) this.getServletContext().getAttribute(ServletContext.TEMPDIR); + File tempDir = (File) getJakartaServletContext().getAttribute(ServletContext.TEMPDIR); return tempDir == null ? null : tempDir.getCanonicalPath(); } } catch (IOException e) { diff --git a/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/src/test/java/org/xwiki/environment/internal/ServletEnvironmentTest.java b/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/src/test/java/org/xwiki/environment/internal/ServletEnvironmentTest.java index 5102979c9e..e333ed1bb0 100644 --- a/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/src/test/java/org/xwiki/environment/internal/ServletEnvironmentTest.java +++ b/xwiki-commons-core/xwiki-commons-environment/xwiki-commons-environment-servlet/src/test/java/org/xwiki/environment/internal/ServletEnvironmentTest.java @@ -23,7 +23,7 @@ import java.net.MalformedURLException; import java.net.URL; -import javax.servlet.ServletContext; +import jakarta.servlet.ServletContext; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.AfterEach; @@ -47,7 +47,7 @@ * @version $Id$ * @since 3.5M1 */ -public class ServletEnvironmentTest +class ServletEnvironmentTest { private File servletTmpDir; @@ -160,7 +160,7 @@ void getPermanentDirectoryWhenSetWithSystemProperty() throws Exception void getPermanentDirectoryWhenNotSet() throws Exception { ServletContext servletContext = mock(ServletContext.class); - when(servletContext.getAttribute("javax.servlet.context.tempdir")).thenReturn(this.servletTmpDir); + when(servletContext.getAttribute("jakarta.servlet.context.tempdir")).thenReturn(this.servletTmpDir); this.environment.setServletContext(servletContext); Logger logger = mock(Logger.class); @@ -187,7 +187,7 @@ void getTemporaryDirectory() throws Exception void getTemporaryDirectoryWhenNotSet() throws Exception { ServletContext servletContext = mock(ServletContext.class); - when(servletContext.getAttribute("javax.servlet.context.tempdir")).thenReturn(this.servletTmpDir); + when(servletContext.getAttribute("jakarta.servlet.context.tempdir")).thenReturn(this.servletTmpDir); this.environment.setServletContext(servletContext); File tmpDir = this.environment.getTemporaryDirectory(); @@ -210,6 +210,6 @@ void getTemporaryDirectoryWhenServletTempDirNotSet() throws Exception // Verify that servletContext.getAttribute was called (and that we returned null - this happens because we // didn't set any stubbing on servletContext and null is the default returned by Mockito). - verify(servletContext).getAttribute("javax.servlet.context.tempdir"); + verify(servletContext).getAttribute("jakarta.servlet.context.tempdir"); } } diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/pom.xml b/xwiki-commons-core/xwiki-commons-jakartabridge/pom.xml new file mode 100644 index 0000000000..f2ed554ff1 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/pom.xml @@ -0,0 +1,41 @@ + + + + +4.0.0 + + xwiki-commons-core + org.xwiki.commons + 17.0.0-SNAPSHOT + + xwiki-commons-jakartabridge + XWiki Commons - Jakarta Bridge + pom + Various bridge to help with the javax to jakarta migration + + + **/*.java + + + xwiki-commons-jakartabridge-common + xwiki-commons-jakartabridge-servlet + + diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/pom.xml b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/pom.xml new file mode 100644 index 0000000000..f73cf2bc00 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + + xwiki-commons-jakartabridge + org.xwiki.commons + 17.0.0-SNAPSHOT + + xwiki-commons-jakartabridge-common + XWiki Commons - Jakarta Bridge - common + jar + Various tools to help bridge jakarta/javax APIs + + 0.0 + + api + + diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/JakartaBridge.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/JakartaBridge.java new file mode 100644 index 0000000000..32ed157495 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/JakartaBridge.java @@ -0,0 +1,213 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.function.Function; + +import org.xwiki.jakartabridge.internal.JakartaToJavaxCollection; +import org.xwiki.jakartabridge.internal.JakartaToJavaxIterator; +import org.xwiki.jakartabridge.internal.JakartaToJavaxList; +import org.xwiki.jakartabridge.internal.JakartaToJavaxListIterator; +import org.xwiki.jakartabridge.internal.JavaxToJakartaCollection; +import org.xwiki.jakartabridge.internal.JavaxToJakartaIterator; +import org.xwiki.jakartabridge.internal.JavaxToJakartaList; +import org.xwiki.jakartabridge.internal.JavaxToJakartaListIterator; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public final class JakartaBridge +{ + private JakartaBridge() + { + } + + ////////////////////////////////////////////////// + // Wrapped + + /** + * @param the jakarta type + * @param the javax type + * @param jakarta the jakarta version + * @param javaxProvider the reference to the {@link JakartaToJavaxWrapper} implementation's constructor + * @return the javax version + */ + public static X toJavax(K jakarta, Function javaxProvider) + { + X javax = null; + + if (jakarta != null) { + if (jakarta instanceof JakartaToJavaxWrapper wrapper) { + javax = (X) wrapper.getJavax(); + } + + if (javax == null) { + javax = javaxProvider.apply(jakarta); + } + } + + return javax; + } + + /** + * @param the javax type + * @param the jakarta type + * @param javax the javax version + * @param jakartaConstructor the reference to the {@link JavaxToJakartaWrapper} implementation's constructor + * @return the jakarta version + */ + public static K toJakarta(X javax, Function jakartaConstructor) + { + K jakarta = null; + + if (javax != null) { + if (javax instanceof JavaxToJakartaWrapper wrapper) { + jakarta = (K) wrapper.getJakarta(); + } + + if (jakarta == null) { + jakarta = jakartaConstructor.apply(javax); + } + } + + return jakarta; + } + + ////////////////////////////////////////////////// + // Multi + + /** + * @param the javax type + * @param the jakarta type + * @param jakarta the jakarta version + * @param javaxProvider the reference to the {@link JakartaToJavaxWrapper} implementation's provider + * @param jakartaProvider the reference to the {@link JavaxToJakartaWrapper} implementation's provider + * @return the javax version + */ + public static Collection toJavax(Collection jakarta, Function javaxProvider, + Function jakartaProvider) + { + return toJavax(jakarta, k -> new JavaxToJakartaCollection(k, javaxProvider, jakartaProvider)); + } + + /** + * @param the javax type + * @param the jakarta type + * @param javax the javax version + * @param javaxProvider the reference to the {@link JakartaToJavaxWrapper} implementation's provider + * @param jakartaProvider the reference to the {@link JavaxToJakartaWrapper} implementation's provider + * @return the jakarta version + */ + public static Collection toJakarta(Collection javax, Function javaxProvider, + Function jakartaProvider) + { + return toJakarta(javax, x -> new JakartaToJavaxCollection(x, javaxProvider, jakartaProvider)); + } + + + /** + * @param the javax type + * @param the jakarta type + * @param jakarta the jakarta version + * @param javaxProvider the reference to the {@link JakartaToJavaxWrapper} implementation's provider + * @param jakartaProvider the reference to the {@link JavaxToJakartaWrapper} implementation's provider + * @return the javax version + */ + public static List toJavax(List jakarta, Function javaxProvider, + Function jakartaProvider) + { + return toJavax(jakarta, k -> new JavaxToJakartaList(k, javaxProvider, jakartaProvider)); + } + + /** + * @param the javax type + * @param the jakarta type + * @param javax the javax version + * @param javaxProvider the reference to the {@link JakartaToJavaxWrapper} implementation's provider + * @param jakartaProvider the reference to the {@link JavaxToJakartaWrapper} implementation's provider + * @return the jakarta version + */ + public static List toJakarta(List javax, Function javaxProvider, + Function jakartaProvider) + { + return toJakarta(javax, x -> new JakartaToJavaxList(x, javaxProvider, jakartaProvider)); + } + + /** + * @param the javax type + * @param the jakarta type + * @param jakarta the jakarta version + * @param javaxProvider the reference to the {@link JakartaToJavaxWrapper} implementation's provider + * @param jakartaProvider the reference to the {@link JavaxToJakartaWrapper} implementation's provider + * @return the javax version + */ + public static Iterator toJavax(Iterator jakarta, Function javaxProvider, + Function jakartaProvider) + { + return toJavax(jakarta, k -> new JavaxToJakartaIterator(k, javaxProvider)); + } + + /** + * @param the javax type + * @param the jakarta type + * @param javax the javax version + * @param javaxProvider the reference to the {@link JakartaToJavaxWrapper} implementation's provider + * @param jakartaProvider the reference to the {@link JavaxToJakartaWrapper} implementation's provider + * @return the jakarta version + */ + public static Iterator toJakarta(Iterator javax, Function javaxProvider, + Function jakartaProvider) + { + return toJakarta(javax, x -> new JakartaToJavaxIterator(x, jakartaProvider)); + } + + /** + * @param the javax type + * @param the jakarta type + * @param jakarta the jakarta version + * @param javaxProvider the reference to the {@link JakartaToJavaxWrapper} implementation's provider + * @param jakartaProvider the reference to the {@link JavaxToJakartaWrapper} implementation's provider + * @return the javax version + */ + public static ListIterator toJavax(ListIterator jakarta, Function javaxProvider, + Function jakartaProvider) + { + return toJavax(jakarta, k -> new JavaxToJakartaListIterator(k, javaxProvider, jakartaProvider)); + } + + /** + * @param the javax type + * @param the jakarta type + * @param javax the javax version + * @param javaxProvider the reference to the {@link JakartaToJavaxWrapper} implementation's provider + * @param jakartaProvider the reference to the {@link JavaxToJakartaWrapper} implementation's provider + * @return the jakarta version + */ + public static ListIterator toJakarta(ListIterator javax, Function javaxProvider, + Function jakartaProvider) + { + return toJakarta(javax, x -> new JakartaToJavaxListIterator(x, javaxProvider, jakartaProvider)); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/JakartaToJavaxWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/JakartaToJavaxWrapper.java new file mode 100644 index 0000000000..3d77c45e7f --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/JakartaToJavaxWrapper.java @@ -0,0 +1,33 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge; + +/** + * @param the type of the wrapped object + * @version $Id$ + * @since 42.0.0 + */ +public interface JakartaToJavaxWrapper +{ + /** + * @return the wrapped version + */ + T getJavax(); +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/JavaxToJakartaWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/JavaxToJakartaWrapper.java new file mode 100644 index 0000000000..180eaf394b --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/JavaxToJakartaWrapper.java @@ -0,0 +1,33 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge; + +/** + * @param the type of the wrapped object + * @version $Id$ + * @since 42.0.0 + */ +public interface JavaxToJakartaWrapper +{ + /** + * @return the wrapped version + */ + T getJakarta(); +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/AbstractJakartaToJavaxWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/AbstractJakartaToJavaxWrapper.java new file mode 100644 index 0000000000..a1cf60cf2c --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/AbstractJakartaToJavaxWrapper.java @@ -0,0 +1,46 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import org.xwiki.jakartabridge.JakartaToJavaxWrapper; + +/** + * @param the type of the wrapped object + * @version $Id$ + * @since 42.0.0 + */ +public abstract class AbstractJakartaToJavaxWrapper implements JakartaToJavaxWrapper +{ + protected final T javax; + + /** + * @param wrapped the wrapped object + */ + protected AbstractJakartaToJavaxWrapper(T wrapped) + { + this.javax = wrapped; + } + + @Override + public T getJavax() + { + return this.javax; + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/AbstractJavaxToJakartaWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/AbstractJavaxToJakartaWrapper.java new file mode 100644 index 0000000000..bc52980756 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/AbstractJavaxToJakartaWrapper.java @@ -0,0 +1,46 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import org.xwiki.jakartabridge.JavaxToJakartaWrapper; + +/** + * @param the type of the wrapped object + * @version $Id$ + * @since 42.0.0 + */ +public abstract class AbstractJavaxToJakartaWrapper implements JavaxToJakartaWrapper +{ + protected final T jakarta; + + /** + * @param wrapped the wrapped object + */ + protected AbstractJavaxToJakartaWrapper(T wrapped) + { + this.jakarta = wrapped; + } + + @Override + public T getJakarta() + { + return this.jakarta; + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxCollection.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxCollection.java new file mode 100644 index 0000000000..b03b122220 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxCollection.java @@ -0,0 +1,147 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import java.util.Collection; +import java.util.Iterator; +import java.util.function.Function; + +import org.xwiki.jakartabridge.JakartaBridge; + +/** + * @param the type of {@link Collection} + * @param the javax type + * @param the jakarta type + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxCollection, K, X> extends AbstractJakartaToJavaxWrapper + implements Collection +{ + private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; + + protected final Function javaxProvider; + + protected final Function jakartaProvider; + + /** + * @param wrapped the wrapped version + * @param javaxProvider the javax wrapper provider + * @param jakartaProvider the jakarta wrapper provider + */ + public JakartaToJavaxCollection(C wrapped, Function javaxProvider, Function jakartaProvider) + { + super(wrapped); + + this.javaxProvider = javaxProvider; + this.jakartaProvider = jakartaProvider; + } + + @Override + public int size() + { + return getJavax().size(); + } + + @Override + public boolean isEmpty() + { + return getJavax().isEmpty(); + } + + @Override + public boolean contains(Object o) + { + return getJavax().contains(this.jakartaProvider.apply((X) o)); + } + + @Override + public Iterator iterator() + { + return JakartaBridge.toJakarta(getJavax().iterator(), this.javaxProvider, this.jakartaProvider); + } + + @Override + public Object[] toArray() + { + return toArray(EMPTY_OBJECT_ARRAY); + } + + @Override + public T[] toArray(T[] a) + { + if (a.length == 0) { + return a; + } + + Object[] javaxArray = getJavax().toArray(); + + T[] jakartaArray = + (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), javaxArray.length); + for (int i = 0; i < javaxArray.length; ++i) { + Object javaxObject = javaxArray[i]; + jakartaArray[i] = javaxObject != null ? (T) this.jakartaProvider.apply((X) javaxObject) : null; + } + + return jakartaArray; + } + + @Override + public boolean add(K e) + { + return getJavax().add(this.javaxProvider.apply(e)); + } + + @Override + public boolean remove(Object o) + { + return getJavax().remove(this.javaxProvider.apply((K) o)); + } + + @Override + public boolean containsAll(Collection c) + { + return getJavax().remove(JakartaBridge.toJavax((Collection) c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public boolean addAll(Collection c) + { + return getJavax().addAll(JakartaBridge.toJavax(c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public boolean retainAll(Collection c) + { + return getJavax().retainAll(JakartaBridge.toJavax((Collection) c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public boolean removeAll(Collection c) + { + return getJavax().removeAll(JakartaBridge.toJavax((Collection) c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public void clear() + { + getJavax().clear(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxIterator.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxIterator.java new file mode 100644 index 0000000000..dd9a4e487c --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxIterator.java @@ -0,0 +1,59 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import java.util.Iterator; +import java.util.function.Function; + +/** + * @param the type of javax {@link Iterator} + * @param the javax type + * @param the jakarta type + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxIterator, X, K> extends AbstractJakartaToJavaxWrapper + implements Iterator +{ + protected final Function jakartaProvider; + + /** + * @param wrapped the wrapped version + * @param jakartaProvider the jakarta wrapper provider + */ + public JakartaToJavaxIterator(I wrapped, Function jakartaProvider) + { + super(wrapped); + + this.jakartaProvider = jakartaProvider; + } + + @Override + public boolean hasNext() + { + return getJavax().hasNext(); + } + + @Override + public K next() + { + return this.jakartaProvider.apply(getJavax().next()); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxList.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxList.java new file mode 100644 index 0000000000..b52383d6a1 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxList.java @@ -0,0 +1,107 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import java.util.Collection; +import java.util.List; +import java.util.ListIterator; +import java.util.function.Function; + +import org.xwiki.jakartabridge.JakartaBridge; + +/** + * @param the javax type + * @param the jakarta type + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxList extends JakartaToJavaxCollection, K, X> implements List +{ + /** + * @param wrapped the wrapped version + * @param javaxProvider the javax wrapper provider + * @param jakartaProvider the jakarta wrapper provider + */ + public JakartaToJavaxList(List wrapped, Function javaxProvider, Function jakartaProvider) + { + super(wrapped, javaxProvider, jakartaProvider); + } + + @Override + public boolean addAll(int index, Collection c) + { + return getJavax().addAll(index, JakartaBridge.toJavax(c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public K get(int index) + { + return this.jakartaProvider.apply(getJavax().get(index)); + } + + @Override + public K set(int index, K element) + { + return this.jakartaProvider.apply(getJavax().set(index, this.javaxProvider.apply(element))); + } + + @Override + public void add(int index, K element) + { + getJavax().add(index, this.javaxProvider.apply(element)); + } + + @Override + public K remove(int index) + { + return this.jakartaProvider.apply(getJavax().remove(index)); + } + + @Override + public int indexOf(Object o) + { + return getJavax().indexOf(this.jakartaProvider.apply((X) o)); + } + + @Override + public int lastIndexOf(Object o) + { + return getJavax().lastIndexOf(this.jakartaProvider.apply((X) o)); + } + + @Override + public ListIterator listIterator() + { + return JakartaBridge.toJakarta(getJavax().listIterator(), this.javaxProvider, this.jakartaProvider); + } + + @Override + public ListIterator listIterator(int index) + { + return JakartaBridge.toJakarta(getJavax().listIterator(index), this.javaxProvider, this.jakartaProvider); + } + + @Override + public List subList(int fromIndex, int toIndex) + { + return JakartaBridge.toJakarta(getJavax().subList(fromIndex, toIndex), this.javaxProvider, + this.jakartaProvider); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxListIterator.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxListIterator.java new file mode 100644 index 0000000000..c4a9703916 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JakartaToJavaxListIterator.java @@ -0,0 +1,89 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import java.util.ListIterator; +import java.util.function.Function; + +/** + * @param the javax type + * @param the jakarta type + * @version $Id$ + */ +public class JakartaToJavaxListIterator extends JakartaToJavaxIterator, X, K> + implements ListIterator +{ + protected final Function javaxProvider; + + /** + * @param wrapped the wrapped version + * @param javaxProvider the javax wrapper provider + * @param jakartaProvider the jakarta wrapper provider + */ + public JakartaToJavaxListIterator(ListIterator wrapped, Function javaxProvider, + Function jakartaProvider) + { + super(wrapped, jakartaProvider); + + this.javaxProvider = javaxProvider; + } + + @Override + public boolean hasPrevious() + { + return getJavax().hasPrevious(); + } + + @Override + public K previous() + { + return this.jakartaProvider.apply(getJavax().previous()); + } + + @Override + public int nextIndex() + { + return getJavax().nextIndex(); + } + + @Override + public int previousIndex() + { + return getJavax().previousIndex(); + } + + @Override + public void remove() + { + getJavax().remove(); + } + + @Override + public void set(K e) + { + getJavax().set(this.javaxProvider.apply(e)); + } + + @Override + public void add(K e) + { + getJavax().add(this.javaxProvider.apply(e)); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaCollection.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaCollection.java new file mode 100644 index 0000000000..6af3082684 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaCollection.java @@ -0,0 +1,150 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import java.util.Collection; +import java.util.Iterator; +import java.util.function.Function; + +import org.xwiki.jakartabridge.JakartaBridge; + +/** + * @param the type of {@link Collection} + * @param the javax type + * @param the jakarta type + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaCollection, X, K> extends AbstractJavaxToJakartaWrapper + implements Collection +{ + private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; + + protected final Function javaxProvider; + + protected final Function jakartaProvider; + + /** + * @param wrapped the wrapped version + * @param javaxProvider the javax wrapper provider + * @param jakartaProvider the jakarta wrapper provider + */ + public JavaxToJakartaCollection(C wrapped, Function javaxProvider, Function jakartaProvider) + { + super(wrapped); + + this.javaxProvider = javaxProvider; + this.jakartaProvider = jakartaProvider; + } + + @Override + public int size() + { + return getJakarta().size(); + } + + @Override + public boolean isEmpty() + { + return getJakarta().isEmpty(); + } + + @Override + public boolean contains(Object o) + { + return getJakarta().contains(this.jakartaProvider.apply((X) o)); + } + + @Override + public Iterator iterator() + { + return JakartaBridge.toJavax(getJakarta().iterator(), this.javaxProvider, this.jakartaProvider); + } + + @Override + public Object[] toArray() + { + return toArray(EMPTY_OBJECT_ARRAY); + } + + @Override + public T[] toArray(T[] a) + { + if (a.length == 0) { + return a; + } + + Object[] jakartaArray = getJakarta().toArray(); + + T[] javaxArray = + (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), jakartaArray.length); + for (int i = 0; i < jakartaArray.length; ++i) { + Object jakartaObject = jakartaArray[i]; + javaxArray[i] = jakartaObject != null ? (T) this.javaxProvider.apply((K) jakartaObject) : null; + } + + return javaxArray; + } + + @Override + public boolean add(X e) + { + return getJakarta().add(this.jakartaProvider.apply(e)); + } + + @Override + public boolean remove(Object o) + { + return getJakarta().remove(this.jakartaProvider.apply((X) o)); + } + + @Override + public boolean containsAll(Collection c) + { + return getJakarta() + .remove(JakartaBridge.toJakarta((Collection) c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public boolean addAll(Collection c) + { + return getJakarta().addAll(JakartaBridge.toJakarta(c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public boolean retainAll(Collection c) + { + return getJakarta() + .retainAll(JakartaBridge.toJakarta((Collection) c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public boolean removeAll(Collection c) + { + return getJakarta() + .removeAll(JakartaBridge.toJakarta((Collection) c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public void clear() + { + getJakarta().clear(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaIterator.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaIterator.java new file mode 100644 index 0000000000..faecacf693 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaIterator.java @@ -0,0 +1,60 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import java.util.Iterator; +import java.util.function.Function; + +/** + * @param the type of jakarta {@link Iterator} + * @param the javax type + * @param the jakarta type + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaIterator, X, K> extends AbstractJavaxToJakartaWrapper + implements Iterator +{ + protected final Function javaxProvider; + + /** + * @param wrapped the wrapped version + * @param javaxProvider the javax wrapper provider + */ + public JavaxToJakartaIterator(I wrapped, Function javaxProvider) + { + super(wrapped); + + this.javaxProvider = javaxProvider; + } + + @Override + public boolean hasNext() + { + return getJakarta().hasNext(); + } + + @Override + public X next() + { + return this.javaxProvider.apply(getJakarta().next()); + } + +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaList.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaList.java new file mode 100644 index 0000000000..73fe882af2 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaList.java @@ -0,0 +1,107 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import java.util.Collection; +import java.util.List; +import java.util.ListIterator; +import java.util.function.Function; + +import org.xwiki.jakartabridge.JakartaBridge; + +/** + * @param the javax type + * @param the jakarta type + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaList extends JavaxToJakartaCollection, X, K> implements List +{ + /** + * @param wrapped the wrapped version + * @param javaxProvider the javax wrapper provider + * @param jakartaProvider the jakarta wrapper provider + */ + public JavaxToJakartaList(List wrapped, Function javaxProvider, Function jakartaProvider) + { + super(wrapped, javaxProvider, jakartaProvider); + } + + @Override + public boolean addAll(int index, Collection c) + { + return getJakarta().addAll(index, JakartaBridge.toJakarta(c, this.javaxProvider, this.jakartaProvider)); + } + + @Override + public X get(int index) + { + return this.javaxProvider.apply(getJakarta().get(index)); + } + + @Override + public X set(int index, X element) + { + return this.javaxProvider.apply(getJakarta().set(index, this.jakartaProvider.apply(element))); + } + + @Override + public void add(int index, X element) + { + getJakarta().add(index, this.jakartaProvider.apply(element)); + } + + @Override + public X remove(int index) + { + return this.javaxProvider.apply(getJakarta().remove(index)); + } + + @Override + public int indexOf(Object o) + { + return getJakarta().indexOf(this.jakartaProvider.apply((X) o)); + } + + @Override + public int lastIndexOf(Object o) + { + return getJakarta().lastIndexOf(this.jakartaProvider.apply((X) o)); + } + + @Override + public ListIterator listIterator() + { + return JakartaBridge.toJavax(getJakarta().listIterator(), this.javaxProvider, this.jakartaProvider); + } + + @Override + public ListIterator listIterator(int index) + { + return JakartaBridge.toJavax(getJakarta().listIterator(index), this.javaxProvider, this.jakartaProvider); + } + + @Override + public List subList(int fromIndex, int toIndex) + { + return JakartaBridge.toJavax(getJakarta().subList(fromIndex, toIndex), this.javaxProvider, + this.jakartaProvider); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaListIterator.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaListIterator.java new file mode 100644 index 0000000000..2c5ac36a37 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaListIterator.java @@ -0,0 +1,89 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import java.util.ListIterator; +import java.util.function.Function; + +/** + * @param the javax type + * @param the jakarta type + * @version $Id$ + */ +public class JavaxToJakartaListIterator extends JavaxToJakartaIterator, X, K> + implements ListIterator +{ + protected final Function jakartaConstructor; + + /** + * @param wrapped the wrapped version + * @param javaxProvider the javax wrapper provider + * @param jakartaProvider the jakarta wrapper provider + */ + public JavaxToJakartaListIterator(ListIterator wrapped, Function javaxProvider, + Function jakartaProvider) + { + super(wrapped, javaxProvider); + + this.jakartaConstructor = jakartaProvider; + } + + @Override + public boolean hasPrevious() + { + return getJakarta().hasPrevious(); + } + + @Override + public X previous() + { + return this.javaxProvider.apply(getJakarta().previous()); + } + + @Override + public int nextIndex() + { + return getJakarta().nextIndex(); + } + + @Override + public int previousIndex() + { + return getJakarta().previousIndex(); + } + + @Override + public void remove() + { + getJakarta().remove(); + } + + @Override + public void set(X e) + { + getJakarta().set(this.jakartaConstructor.apply(e)); + } + + @Override + public void add(X e) + { + getJakarta().add(this.jakartaConstructor.apply(e)); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaSet.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaSet.java new file mode 100644 index 0000000000..bbf286f76f --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-common/src/main/java/org/xwiki/jakartabridge/internal/JavaxToJakartaSet.java @@ -0,0 +1,42 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.internal; + +import java.util.Set; +import java.util.function.Function; + +/** + * @param the javax type + * @param the jakarta type + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaSet extends JavaxToJakartaCollection, X, K> implements Set +{ + /** + * @param wrapped the wrapped version + * @param javaxProvider the javax wrapper provider + * @param jakartaProvider the jakarta wrapper provider + */ + public JavaxToJakartaSet(Set wrapped, Function javaxProvider, Function jakartaProvider) + { + super(wrapped, javaxProvider, jakartaProvider); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/pom.xml b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/pom.xml new file mode 100644 index 0000000000..338b0cba54 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/pom.xml @@ -0,0 +1,75 @@ + + + + + 4.0.0 + + xwiki-commons-jakartabridge + org.xwiki.commons + 17.0.0-SNAPSHOT + + xwiki-commons-jakartabridge-servlet + XWiki Commons - Jakarta Bridge - Servlet + jar + Various bridge to help with the javax to jakarta Servlet migration + + 0.0 + + api + + + + org.xwiki.commons + xwiki-commons-jakartabridge-common + ${project.version} + + + jakarta.servlet + jakarta.servlet-api + + + javax.servlet + javax.servlet-api + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + default + + + org/xwiki/jakartabridge/servlet/JakartaServletBridge.java, + org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletRequestWrapper.java, + org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletRequestWrapper.java, + org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletContext.java + + + + + + + + diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/jakarta/servlet/http/HttpSessionContext.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/jakarta/servlet/http/HttpSessionContext.java new file mode 100644 index 0000000000..b6204dc18a --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/jakarta/servlet/http/HttpSessionContext.java @@ -0,0 +1,49 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package jakarta.servlet.http; + +import java.util.Enumeration; + +/** + * @version $Id$ + * @deprecated deleted in Servlet 6 + * @see HttpSession + * @see HttpSessionBindingEvent + * @see HttpSessionBindingListener + */ +public interface HttpSessionContext +{ + /** + * @deprecated As of Java Servlet API 2.1 with no replacement. This method must return null and will be removed in a + * future version of this API. + * @param sessionId the id of the session to be returned + * @return null in all cases + */ + @Deprecated + HttpSession getSession(String sessionId); + + /** + * @deprecated As of Java Servlet API 2.1 with no replacement. This method must return an empty + * Enumeration and will be removed in a future version of this API. + * @return null + */ + @Deprecated + Enumeration getIds(); +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/JakartaServletBridge.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/JakartaServletBridge.java new file mode 100644 index 0000000000..e708a8b108 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/JakartaServletBridge.java @@ -0,0 +1,1002 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet; + +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.Enumeration; +import java.util.Set; +import java.util.stream.Collectors; + +import org.xwiki.jakartabridge.JakartaBridge; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxAsyncContext; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxAsyncListener; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxCookie; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxFilter; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxFilterChain; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxFilterConfig; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxFilterRegistration; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxHttpServletRequest; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxHttpServletRequestWrapper; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxHttpServletResponse; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxHttpServletResponseWrapper; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxHttpSession; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxHttpSessionContext; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxPart; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxReadListener; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxRequestDispatcher; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServlet; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServletConfig; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServletContext; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServletInputStream; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServletOutputStream; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServletRegistration; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServletRequest; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServletRequestWrapper; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServletResponse; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxServletResponseWrapper; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxSessionCookieConfig; +import org.xwiki.jakartabridge.servlet.internal.JakartaToJavaxWriteListener; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaAsyncContext; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaAsyncListener; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaCookie; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaFilter; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaFilterChain; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaFilterConfig; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaFilterRegistration; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaHttpServletRequest; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaHttpServletRequestWrapper; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaHttpServletResponse; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaHttpServletResponseWrapper; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaHttpSession; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaHttpSessionContext; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaPart; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaReadListener; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaRequestDispatcher; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServlet; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServletConfig; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServletContext; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServletInputStream; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServletOutputStream; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServletRegistration; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServletRequest; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServletRequestWrapper; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServletResponse; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaServletResponseWrapper; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaSessionCookieConfig; +import org.xwiki.jakartabridge.servlet.internal.JavaxToJakartaWriteListener; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.MultipartConfigElement; +import jakarta.servlet.ReadListener; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.ServletRegistration; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.ServletResponseWrapper; +import jakarta.servlet.ServletSecurityElement; +import jakarta.servlet.SessionCookieConfig; +import jakarta.servlet.SessionTrackingMode; +import jakarta.servlet.WriteListener; +import jakarta.servlet.descriptor.JspConfigDescriptor; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequestWrapper; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponseWrapper; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpSessionContext; +import jakarta.servlet.http.Part; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public final class JakartaServletBridge +{ + private JakartaServletBridge() + { + } + + ////////////////////////////////////////////////// + // Wrapped + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ServletRequest toJavax(ServletRequest jakarta) + { + javax.servlet.ServletRequest javax; + + if (jakarta == null) { + javax = null; + } else if (jakarta instanceof JakartaToJavaxServletRequest bridge) { + javax = bridge.getJavax(); + } else if (jakarta instanceof HttpServletRequest httpjakarta) { + javax = toJavax(httpjakarta); + } else if (jakarta instanceof ServletRequestWrapper wrapper) { + javax = new JavaxToJakartaServletRequestWrapper(wrapper); + } else { + javax = new JavaxToJakartaServletRequest(jakarta); + } + + return javax; + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.http.HttpServletRequest toJavax(HttpServletRequest jakarta) + { + javax.servlet.http.HttpServletRequest javax; + + if (jakarta == null) { + javax = null; + } else if (jakarta instanceof JakartaToJavaxHttpServletRequest bridge) { + javax = bridge.getJavax(); + } else if (jakarta instanceof HttpServletRequestWrapper wrapper) { + javax = + new JavaxToJakartaHttpServletRequestWrapper(wrapper); + } else { + javax = new JavaxToJakartaHttpServletRequest(jakarta); + } + + return javax; + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static ServletRequest toJakarta(javax.servlet.ServletRequest javax) + { + ServletRequest jakarta; + + if (javax == null) { + jakarta = null; + } else if (javax instanceof JavaxToJakartaServletRequest bridge) { + jakarta = bridge.getJakarta(); + } else if (javax instanceof javax.servlet.http.HttpServletRequest httpjakarta) { + jakarta = toJakarta(httpjakarta); + } else if (javax instanceof javax.servlet.ServletRequestWrapper wrapper) { + jakarta = new JakartaToJavaxServletRequestWrapper(wrapper); + } else { + jakarta = new JakartaToJavaxServletRequest(javax); + } + + return jakarta; + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static HttpServletRequest toJakarta(javax.servlet.http.HttpServletRequest javax) + { + HttpServletRequest jakarta; + + if (javax == null) { + jakarta = null; + } else if (javax instanceof JavaxToJakartaHttpServletRequest bridge) { + jakarta = bridge.getJakarta(); + } else if (javax instanceof javax.servlet.http.HttpServletRequestWrapper wrapper) { + jakarta = + new JakartaToJavaxHttpServletRequestWrapper(wrapper); + } else { + jakarta = new JakartaToJavaxHttpServletRequest(javax); + } + + return jakarta; + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ServletResponse toJavax(ServletResponse jakarta) + { + javax.servlet.ServletResponse javax; + + if (jakarta == null) { + javax = null; + } else if (jakarta instanceof JakartaToJavaxServletResponse bridge) { + javax = bridge.getJavax(); + } else if (jakarta instanceof HttpServletResponse httpjakarta) { + javax = toJavax(httpjakarta); + } else if (jakarta instanceof ServletResponseWrapper wrapper) { + javax = new JavaxToJakartaServletResponseWrapper(wrapper); + } else { + javax = new JavaxToJakartaServletResponse(jakarta); + } + + return javax; + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.http.HttpServletResponse toJavax(HttpServletResponse jakarta) + { + javax.servlet.http.HttpServletResponse javax; + + if (jakarta == null) { + javax = null; + } else if (jakarta instanceof JakartaToJavaxHttpServletResponse bridge) { + javax = bridge.getJavax(); + } else if (jakarta instanceof HttpServletResponseWrapper wrapper) { + javax = + new JavaxToJakartaHttpServletResponseWrapper(wrapper); + } else { + javax = new JavaxToJakartaHttpServletResponse(jakarta); + } + + return javax; + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static ServletResponse toJakarta(javax.servlet.ServletResponse javax) + { + ServletResponse jakarta; + + if (javax == null) { + jakarta = null; + } else if (javax instanceof JavaxToJakartaServletResponse bridge) { + jakarta = bridge.getJakarta(); + } else if (javax instanceof javax.servlet.http.HttpServletResponse httpjakarta) { + jakarta = toJakarta(httpjakarta); + } else if (javax instanceof javax.servlet.ServletResponseWrapper wrapper) { + jakarta = new JakartaToJavaxServletResponseWrapper(wrapper); + } else { + jakarta = new JakartaToJavaxServletResponse(javax); + } + + return jakarta; + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static HttpServletResponse toJakarta(javax.servlet.http.HttpServletResponse javax) + { + HttpServletResponse jakarta; + + if (javax == null) { + jakarta = null; + } else if (javax instanceof JavaxToJakartaHttpServletResponse bridge) { + jakarta = bridge.getJakarta(); + } else if (javax instanceof javax.servlet.http.HttpServletResponseWrapper wrapper) { + jakarta = + new JakartaToJavaxHttpServletResponseWrapper(wrapper); + } else { + jakarta = new JakartaToJavaxHttpServletResponse(javax); + } + + return jakarta; + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.RequestDispatcher toJavax(RequestDispatcher jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaRequestDispatcher::new); + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static RequestDispatcher toJakarta(javax.servlet.RequestDispatcher javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxRequestDispatcher::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ServletContext toJavax(ServletContext jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaServletContext::new); + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static ServletContext toJakarta(javax.servlet.ServletContext javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxServletContext::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.Servlet toJavax(Servlet jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaServlet::new); + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static Servlet toJakarta(javax.servlet.Servlet javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxServlet::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.http.HttpSession toJavax(HttpSession jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaHttpSession::new); + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static HttpSession toJakarta(javax.servlet.http.HttpSession javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxHttpSession::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.http.Part toJavax(Part jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaPart::new); + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static Part toJakarta(javax.servlet.http.Part javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxPart::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ReadListener toJavax(ReadListener jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaReadListener::new); + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static ReadListener toJakarta(javax.servlet.ReadListener javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxReadListener::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.WriteListener toJavax(WriteListener jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaWriteListener::new); + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static WriteListener toJakarta(javax.servlet.WriteListener javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxWriteListener::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ServletOutputStream toJavax(ServletOutputStream jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaServletOutputStream::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static ServletOutputStream toJakarta(javax.servlet.ServletOutputStream javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxServletOutputStream::new); + + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.http.HttpSessionContext toJavax(HttpSessionContext jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaHttpSessionContext::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static HttpSessionContext toJakarta(javax.servlet.http.HttpSessionContext javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxHttpSessionContext::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ServletConfig toJavax(ServletConfig jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaServletConfig::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static ServletConfig toJakarta(javax.servlet.ServletConfig javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxServletConfig::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.AsyncContext toJavax(AsyncContext jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaAsyncContext::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static AsyncContext toJakarta(javax.servlet.AsyncContext javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxAsyncContext::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.SessionCookieConfig toJavax(SessionCookieConfig jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaSessionCookieConfig::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static SessionCookieConfig toJakarta(javax.servlet.SessionCookieConfig javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxSessionCookieConfig::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.FilterRegistration toJavax(FilterRegistration jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaFilterRegistration::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static FilterRegistration toJakarta(javax.servlet.FilterRegistration javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxFilterRegistration::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.FilterRegistration.Dynamic toJavax(FilterRegistration.Dynamic jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaFilterRegistration.Dynamic::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static jakarta.servlet.FilterRegistration.Dynamic toJakarta(javax.servlet.FilterRegistration.Dynamic javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxFilterRegistration.Dynamic::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ServletRegistration toJavax(ServletRegistration jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaServletRegistration::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static ServletRegistration toJakarta(javax.servlet.ServletRegistration javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxServletRegistration::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ServletRegistration.Dynamic toJavax(ServletRegistration.Dynamic jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaServletRegistration.Dynamic::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static ServletRegistration.Dynamic toJakarta(javax.servlet.ServletRegistration.Dynamic javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxServletRegistration.Dynamic::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.Filter toJavax(Filter jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaFilter::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static Filter toJakarta(javax.servlet.Filter javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxFilter::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.AsyncListener toJavax(AsyncListener jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaAsyncListener::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static AsyncListener toJakarta(javax.servlet.AsyncListener javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxAsyncListener::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ServletInputStream toJavax(ServletInputStream jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaServletInputStream::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static ServletInputStream toJakarta(javax.servlet.ServletInputStream javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxServletInputStream::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.FilterChain toJavax(FilterChain jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaFilterChain::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static FilterChain toJakarta(javax.servlet.FilterChain javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxFilterChain::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.FilterConfig toJavax(FilterConfig jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaFilterConfig::new); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static FilterConfig toJakarta(javax.servlet.FilterConfig javax) + { + return JakartaBridge.toJakarta(javax, JakartaToJavaxFilterConfig::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.http.Cookie toJavax(Cookie jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaCookie::new); + } + + /** + * @param javax the javax version + * @return the jakarta version + */ + public static Cookie toJakarta(javax.servlet.http.Cookie javax) + { + return JakartaBridge.toJavax(javax, JakartaToJavaxCookie::new); + } + + ////////////////////////////////////////////////// + // Converted + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.DispatcherType toJavax(DispatcherType jakarta) + { + if (jakarta == null) { + return null; + } + + return javax.servlet.DispatcherType.valueOf(jakarta.name()); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static DispatcherType toJakarta(javax.servlet.DispatcherType javax) + { + if (javax == null) { + return null; + } + + return DispatcherType.valueOf(javax.name()); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.AsyncEvent toJavax(AsyncEvent jakarta) + { + if (jakarta == null) { + return null; + } + + return new javax.servlet.AsyncEvent(toJavax(jakarta.getAsyncContext()), toJavax(jakarta.getSuppliedRequest()), + toJavax(jakarta.getSuppliedResponse()), jakarta.getThrowable()); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static AsyncEvent toJakarta(javax.servlet.AsyncEvent javax) + { + if (javax == null) { + return null; + } + + return new AsyncEvent(toJakarta(javax.getAsyncContext()), toJakarta(javax.getSuppliedRequest()), + toJakarta(javax.getSuppliedResponse()), javax.getThrowable()); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.SessionTrackingMode toJavax(SessionTrackingMode jakarta) + { + if (jakarta == null) { + return null; + } + + return javax.servlet.SessionTrackingMode.valueOf(jakarta.name()); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static SessionTrackingMode toJakarta(javax.servlet.SessionTrackingMode javax) + { + if (javax == null) { + return null; + } + + return SessionTrackingMode.valueOf(javax.name()); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static Set toJavax(Set jakarta) + { + if (jakarta == null) { + return null; + } + + return jakarta.stream().map(JakartaServletBridge::toJavax).collect(Collectors.toSet()); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static Set toJakarta(Set javax) + { + if (javax == null) { + return null; + } + + return javax.stream().map(JakartaServletBridge::toJakarta).collect(Collectors.toSet()); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.MultipartConfigElement toJavax(MultipartConfigElement jakarta) + { + if (jakarta == null) { + return null; + } + + return new javax.servlet.MultipartConfigElement(jakarta.getLocation(), jakarta.getMaxFileSize(), + jakarta.getMaxRequestSize(), jakarta.getFileSizeThreshold()); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static MultipartConfigElement toJakarta(javax.servlet.MultipartConfigElement javax) + { + if (javax == null) { + return null; + } + + return new MultipartConfigElement(javax.getLocation(), javax.getMaxFileSize(), javax.getMaxRequestSize(), + javax.getFileSizeThreshold()); + } + + ////////////////////////////////////////////////// + // Multi + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static Collection toJavax(Collection jakarta) + { + return JakartaBridge.toJavax(jakarta, JavaxToJakartaPart::new, JakartaToJavaxPart::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static Collection toJakarta(Collection jakarta) + { + return JakartaBridge.toJakarta(jakarta, JavaxToJakartaPart::new, JakartaToJavaxPart::new); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static Enumeration toJavax(Enumeration jakarta) + { + if (jakarta == null) { + return null; + } + + return Collections.enumeration(Collections.list(jakarta).stream().map(JakartaServletBridge::toJavax).toList()); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static Enumeration toJakarta(Enumeration javax) + { + if (javax == null) { + return null; + } + + return Collections.enumeration(Collections.list(javax).stream().map(JakartaServletBridge::toJakarta).toList()); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.http.Cookie[] toJavax(Cookie[] jakarta) + { + if (jakarta == null) { + return null; + } + + javax.servlet.http.Cookie[] javax = new javax.servlet.http.Cookie[jakarta.length]; + + for (int i = 0; i < jakarta.length; ++i) { + javax[i] = toJavax(jakarta[i]); + } + + return javax; + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static Cookie[] toJakarta(javax.servlet.http.Cookie[] javax) + { + if (javax == null) { + return null; + } + + Cookie[] jakarta = new Cookie[javax.length]; + + for (int i = 0; i < javax.length; ++i) { + jakarta[i] = toJakarta(javax[i]); + } + + return jakarta; + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static EnumSet toJavax(EnumSet jakarta) + { + if (jakarta == null) { + return null; + } + + return EnumSet.copyOf(jakarta.stream().map(JakartaServletBridge::toJavax).collect(Collectors.toList())); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static EnumSet toJakarta(EnumSet javax) + { + if (javax == null) { + return null; + } + + return EnumSet.copyOf(javax.stream().map(JakartaServletBridge::toJakarta).collect(Collectors.toList())); + } + + ////////////////////////////////////////////////// + // Unsupported + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.descriptor.JspConfigDescriptor toJavax(JspConfigDescriptor jakarta) + { + // TODO + throw new UnsupportedOperationException(); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static JspConfigDescriptor toJakarta(javax.servlet.descriptor.JspConfigDescriptor javax) + { + // TODO + throw new UnsupportedOperationException(); + } + + /** + * @param jakarta the jakarta version + * @return the javax version + */ + public static javax.servlet.ServletSecurityElement toJavax(ServletSecurityElement jakarta) + { + // TODO + throw new UnsupportedOperationException(); + } + + /** + * @param javax the javax version + * @return the javax version + */ + public static ServletSecurityElement toJakarta(javax.servlet.ServletSecurityElement javax) + { + // TODO + throw new UnsupportedOperationException(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/EmptyJakartaHttpSessionContext.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/EmptyJakartaHttpSessionContext.java new file mode 100644 index 0000000000..4eb8ef0e15 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/EmptyJakartaHttpSessionContext.java @@ -0,0 +1,51 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Collections; +import java.util.Enumeration; + +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionContext; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class EmptyJakartaHttpSessionContext implements HttpSessionContext +{ + /** + * An empty implementation of {@link HttpSessionContext}. + */ + public static final EmptyJakartaHttpSessionContext EMPTY = new EmptyJakartaHttpSessionContext(); + + @Override + public HttpSession getSession(String sessionId) + { + return null; + } + + @Override + public Enumeration getIds() + { + return Collections.emptyEnumeration(); + } + +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/EmptyJavaxHttpSessionContext.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/EmptyJavaxHttpSessionContext.java new file mode 100644 index 0000000000..8247a47a2e --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/EmptyJavaxHttpSessionContext.java @@ -0,0 +1,51 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Collections; +import java.util.Enumeration; + +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionContext; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class EmptyJavaxHttpSessionContext implements HttpSessionContext +{ + /** + * An empty implementation of {@link HttpSessionContext}. + */ + public static final EmptyJavaxHttpSessionContext EMPTY = new EmptyJavaxHttpSessionContext(); + + @Override + public HttpSession getSession(String sessionId) + { + return null; + } + + @Override + public Enumeration getIds() + { + return Collections.emptyEnumeration(); + } + +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxAsyncContext.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxAsyncContext.java new file mode 100644 index 0000000000..c68b09a607 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxAsyncContext.java @@ -0,0 +1,126 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.AsyncListener; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxAsyncContext extends AbstractJakartaToJavaxWrapper + implements AsyncContext +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxAsyncContext(javax.servlet.AsyncContext javax) + { + super(javax); + } + + @Override + public ServletRequest getRequest() + { + return JakartaServletBridge.toJakarta(this.javax.getRequest()); + } + + @Override + public ServletResponse getResponse() + { + return JakartaServletBridge.toJakarta(this.javax.getResponse()); + } + + @Override + public boolean hasOriginalRequestAndResponse() + { + return this.javax.hasOriginalRequestAndResponse(); + } + + @Override + public void dispatch() + { + this.javax.dispatch(); + } + + @Override + public void dispatch(String path) + { + this.javax.dispatch(path); + } + + @Override + public void dispatch(ServletContext context, String path) + { + this.javax.dispatch(JakartaServletBridge.toJavax(context), path); + } + + @Override + public void complete() + { + this.javax.complete(); + } + + @Override + public void start(Runnable run) + { + this.javax.start(run); + } + + @Override + public void addListener(AsyncListener listener) + { + this.javax.addListener(JakartaServletBridge.toJavax(listener)); + } + + @Override + public void addListener(AsyncListener listener, ServletRequest servletRequest, ServletResponse servletResponse) + { + this.javax.addListener(JakartaServletBridge.toJavax(listener), JakartaServletBridge.toJavax(servletRequest), + JakartaServletBridge.toJavax(servletResponse)); + } + + @Override + public T createListener(Class clazz) throws ServletException + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public void setTimeout(long timeout) + { + this.javax.setTimeout(timeout); + } + + @Override + public long getTimeout() + { + return this.javax.getTimeout(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxAsyncListener.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxAsyncListener.java new file mode 100644 index 0000000000..3e169b27bf --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxAsyncListener.java @@ -0,0 +1,68 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxAsyncListener extends AbstractJakartaToJavaxWrapper + implements AsyncListener +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxAsyncListener(javax.servlet.AsyncListener javax) + { + super(javax); + } + + @Override + public void onComplete(AsyncEvent event) throws IOException + { + this.javax.onComplete(JakartaServletBridge.toJavax(event)); + } + + @Override + public void onTimeout(AsyncEvent event) throws IOException + { + this.javax.onTimeout(JakartaServletBridge.toJavax(event)); + } + + @Override + public void onError(AsyncEvent event) throws IOException + { + this.javax.onError(JakartaServletBridge.toJavax(event)); + } + + @Override + public void onStartAsync(AsyncEvent event) throws IOException + { + this.javax.onStartAsync(JakartaServletBridge.toJavax(event)); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxCookie.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxCookie.java new file mode 100644 index 0000000000..999bc007d6 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxCookie.java @@ -0,0 +1,166 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import org.xwiki.jakartabridge.JakartaToJavaxWrapper; + +import jakarta.servlet.http.Cookie; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxCookie extends Cookie implements JakartaToJavaxWrapper +{ + private static final long serialVersionUID = 869891252570863118L; + + private final javax.servlet.http.Cookie javax; + + /** + * @param javax the wrapped version + * @see Cookie#Cookie(String, String) + */ + public JakartaToJavaxCookie(javax.servlet.http.Cookie javax) + { + super("name", "value"); + + this.javax = javax; + } + + @Override + public javax.servlet.http.Cookie getJavax() + { + return this.javax; + } + + @Override + public String getComment() + { + return this.javax.getComment(); + } + + @Override + public String getDomain() + { + return this.javax.getDomain(); + } + + @Override + public int getMaxAge() + { + return this.javax.getMaxAge(); + } + + @Override + public String getName() + { + return this.javax.getName(); + } + + @Override + public String getPath() + { + return this.javax.getPath(); + } + + @Override + public boolean getSecure() + { + return this.javax.getSecure(); + } + + @Override + public String getValue() + { + return this.javax.getValue(); + } + + @Override + public int getVersion() + { + return this.javax.getVersion(); + } + + @Override + public boolean isHttpOnly() + { + return this.javax.isHttpOnly(); + } + + @Override + public void setComment(String purpose) + { + this.javax.setComment(purpose); + } + + @Override + public void setDomain(String domain) + { + this.javax.setDomain(domain); + } + + @Override + public void setHttpOnly(boolean isHttpOnly) + { + this.javax.setHttpOnly(isHttpOnly); + } + + @Override + public void setMaxAge(int expiry) + { + this.javax.setMaxAge(expiry); + } + + @Override + public void setPath(String uri) + { + this.javax.setPath(uri); + } + + @Override + public void setSecure(boolean flag) + { + this.javax.setSecure(flag); + } + + @Override + public void setValue(String newValue) + { + this.javax.setValue(newValue); + } + + @Override + public void setVersion(int v) + { + this.javax.setVersion(v); + } + + @Override + public Object clone() + { + return new JakartaToJavaxCookie((javax.servlet.http.Cookie) this.javax.clone()); + } + + @Override + public String toString() + { + return this.javax.toString(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilter.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilter.java new file mode 100644 index 0000000000..123ebc8c8f --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilter.java @@ -0,0 +1,75 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxFilter extends AbstractJakartaToJavaxWrapper implements Filter +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxFilter(javax.servlet.Filter javax) + { + super(javax); + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException + { + try { + this.javax.init(JakartaServletBridge.toJavax(filterConfig)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException + { + try { + this.javax.doFilter(JakartaServletBridge.toJavax(request), JakartaServletBridge.toJavax(response), + JakartaServletBridge.toJavax(chain)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void destroy() + { + this.javax.destroy(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilterChain.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilterChain.java new file mode 100644 index 0000000000..1f779d8ae5 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilterChain.java @@ -0,0 +1,56 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxFilterChain extends AbstractJakartaToJavaxWrapper + implements FilterChain +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxFilterChain(javax.servlet.FilterChain javax) + { + super(javax); + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException + { + try { + this.javax.doFilter(JakartaServletBridge.toJavax(request), JakartaServletBridge.toJavax(response)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilterConfig.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilterConfig.java new file mode 100644 index 0000000000..4349210f22 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilterConfig.java @@ -0,0 +1,68 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Enumeration; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletContext; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxFilterConfig extends AbstractJakartaToJavaxWrapper + implements FilterConfig +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxFilterConfig(javax.servlet.FilterConfig javax) + { + super(javax); + } + + @Override + public String getFilterName() + { + return this.javax.getFilterName(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJakarta(this.javax.getServletContext()); + } + + @Override + public String getInitParameter(String name) + { + return this.javax.getInitParameter(name); + } + + @Override + public Enumeration getInitParameterNames() + { + return this.javax.getInitParameterNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilterRegistration.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilterRegistration.java new file mode 100644 index 0000000000..3628074777 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxFilterRegistration.java @@ -0,0 +1,132 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Collection; +import java.util.EnumSet; +import java.util.Map; +import java.util.Set; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.DispatcherType; +import jakarta.servlet.FilterRegistration; + +/** + * @param the exact type of jakarta.servlet.FilterRegistration + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxFilterRegistration + extends AbstractJakartaToJavaxWrapper implements FilterRegistration +{ + /** + * @version $Id$ + */ + public static class Dynamic extends JakartaToJavaxFilterRegistration + implements FilterRegistration.Dynamic + { + /** + * @param javax the wrapped version + */ + public Dynamic(javax.servlet.FilterRegistration.Dynamic javax) + { + super(javax); + } + + @Override + public void setAsyncSupported(boolean isAsyncSupported) + { + this.javax.setAsyncSupported(isAsyncSupported); + } + } + + /** + * @param javax the wrapped version + */ + public JakartaToJavaxFilterRegistration(T javax) + { + super(javax); + } + + @Override + public String getName() + { + return this.javax.getName(); + } + + @Override + public String getClassName() + { + return this.javax.getClassName(); + } + + @Override + public boolean setInitParameter(String name, String value) + { + return this.javax.setInitParameter(name, value); + } + + @Override + public String getInitParameter(String name) + { + return this.javax.getInitParameter(name); + } + + @Override + public Set setInitParameters(Map initParameters) + { + return this.javax.setInitParameters(initParameters); + } + + @Override + public Map getInitParameters() + { + return this.javax.getInitParameters(); + } + + @Override + public void addMappingForServletNames(EnumSet dispatcherTypes, boolean isMatchAfter, + String... servletNames) + { + this.javax.addMappingForServletNames(JakartaServletBridge.toJavax(dispatcherTypes), isMatchAfter, + servletNames); + } + + @Override + public Collection getServletNameMappings() + { + return this.javax.getServletNameMappings(); + } + + @Override + public void addMappingForUrlPatterns(EnumSet dispatcherTypes, boolean isMatchAfter, + String... urlPatterns) + { + this.javax.addMappingForUrlPatterns(JakartaServletBridge.toJavax(dispatcherTypes), isMatchAfter, urlPatterns); + } + + @Override + public Collection getUrlPatternMappings() + { + return this.javax.getUrlPatternMappings(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletRequest.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletRequest.java new file mode 100644 index 0000000000..63274896fb --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletRequest.java @@ -0,0 +1,265 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.security.Principal; +import java.util.Collection; +import java.util.Enumeration; + +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpUpgradeHandler; +import jakarta.servlet.http.Part; + +/** + * @param the type of http servlet request + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxHttpServletRequest + extends JakartaToJavaxServletRequest implements HttpServletRequest +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxHttpServletRequest(R javax) + { + super(javax); + } + + @Override + public String getAuthType() + { + return this.javax.getAuthType(); + } + + @Override + public Cookie[] getCookies() + { + return JakartaServletBridge.toJakarta(this.javax.getCookies()); + } + + @Override + public long getDateHeader(String name) + { + return this.javax.getDateHeader(name); + } + + @Override + public String getHeader(String name) + { + return this.javax.getHeader(name); + } + + @Override + public Enumeration getHeaders(String name) + { + return this.javax.getHeaders(name); + } + + @Override + public Enumeration getHeaderNames() + { + return this.javax.getHeaderNames(); + } + + @Override + public int getIntHeader(String name) + { + return this.javax.getIntHeader(name); + } + + @Override + public String getMethod() + { + return this.javax.getMethod(); + } + + @Override + public String getPathInfo() + { + return this.javax.getPathInfo(); + } + + @Override + public String getPathTranslated() + { + return this.javax.getPathTranslated(); + } + + @Override + public String getContextPath() + { + return this.javax.getContextPath(); + } + + @Override + public String getQueryString() + { + return this.javax.getQueryString(); + } + + @Override + public String getRemoteUser() + { + return this.javax.getRemoteUser(); + } + + @Override + public boolean isUserInRole(String role) + { + return this.javax.isUserInRole(role); + } + + @Override + public Principal getUserPrincipal() + { + return this.javax.getUserPrincipal(); + } + + @Override + public String getRequestedSessionId() + { + return this.javax.getRequestedSessionId(); + } + + @Override + public String getRequestURI() + { + return this.javax.getRequestURI(); + } + + @Override + public StringBuffer getRequestURL() + { + return this.javax.getRequestURL(); + } + + @Override + public String getServletPath() + { + return this.javax.getServletPath(); + } + + @Override + public HttpSession getSession(boolean create) + { + return JakartaServletBridge.toJakarta(this.javax.getSession(create)); + } + + @Override + public HttpSession getSession() + { + return JakartaServletBridge.toJakarta(this.javax.getSession()); + } + + @Override + public String changeSessionId() + { + return this.javax.changeSessionId(); + } + + @Override + public boolean isRequestedSessionIdValid() + { + return this.javax.isRequestedSessionIdValid(); + } + + @Override + public boolean isRequestedSessionIdFromCookie() + { + return this.javax.isRequestedSessionIdFromCookie(); + } + + @Override + public boolean isRequestedSessionIdFromURL() + { + return this.javax.isRequestedSessionIdFromURL(); + } + + @Override + public boolean isRequestedSessionIdFromUrl() + { + return this.javax.isRequestedSessionIdFromUrl(); + } + + @Override + public boolean authenticate(HttpServletResponse response) throws IOException, ServletException + { + try { + return this.javax.authenticate(JakartaServletBridge.toJavax(response)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void login(String username, String password) throws ServletException + { + try { + this.javax.login(username, password); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void logout() throws ServletException + { + try { + this.javax.logout(); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Collection getParts() throws IOException, ServletException + { + try { + return JakartaServletBridge.toJakarta(this.javax.getParts()); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Part getPart(String name) throws IOException, ServletException + { + try { + return JakartaServletBridge.toJakarta(this.javax.getPart(name)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public T upgrade(Class handlerClass) throws IOException, ServletException + { + // TODO + throw new UnsupportedOperationException(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletRequestWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletRequestWrapper.java new file mode 100644 index 0000000000..83cdf0f844 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletRequestWrapper.java @@ -0,0 +1,515 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.Principal; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +import org.xwiki.jakartabridge.JakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequestWrapper; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpUpgradeHandler; +import jakarta.servlet.http.Part; + +/** + * @param the type of http servlet request + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxHttpServletRequestWrapper + extends HttpServletRequestWrapper implements JakartaToJavaxWrapper +{ + protected final R javax; + + /** + * @param javax the wrapped version + */ + public JakartaToJavaxHttpServletRequestWrapper(R javax) + { + super(JakartaServletBridge.toJakarta((javax.servlet.http.HttpServletRequest) javax.getRequest())); + + this.javax = javax; + } + + // JakartaToJavaxWrapper + + @Override + public R getJavax() + { + return this.javax; + } + + // HttpServletRequest + + @Override + public Object getAttribute(String name) + { + return this.javax.getAttribute(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.javax.getAttributeNames(); + } + + @Override + public String getCharacterEncoding() + { + return this.javax.getCharacterEncoding(); + } + + @Override + public void setCharacterEncoding(String env) throws UnsupportedEncodingException + { + this.javax.setCharacterEncoding(env); + } + + @Override + public int getContentLength() + { + return this.javax.getContentLength(); + } + + @Override + public long getContentLengthLong() + { + return this.javax.getContentLengthLong(); + } + + @Override + public String getContentType() + { + return this.javax.getContentType(); + } + + @Override + public ServletInputStream getInputStream() throws IOException + { + return JakartaServletBridge.toJakarta(this.javax.getInputStream()); + } + + @Override + public String getParameter(String name) + { + return this.javax.getParameter(name); + } + + @Override + public Enumeration getParameterNames() + { + return this.javax.getParameterNames(); + } + + @Override + public String[] getParameterValues(String name) + { + return this.javax.getParameterValues(name); + } + + @Override + public Map getParameterMap() + { + return this.javax.getParameterMap(); + } + + @Override + public String getProtocol() + { + return this.javax.getProtocol(); + } + + @Override + public String getScheme() + { + return this.javax.getScheme(); + } + + @Override + public String getServerName() + { + return this.javax.getServerName(); + } + + @Override + public int getServerPort() + { + return this.javax.getServerPort(); + } + + @Override + public BufferedReader getReader() throws IOException + { + return this.javax.getReader(); + } + + @Override + public String getRemoteAddr() + { + return this.javax.getRemoteAddr(); + } + + @Override + public String getRemoteHost() + { + return this.javax.getRemoteHost(); + } + + @Override + public void setAttribute(String name, Object o) + { + this.javax.setAttribute(name, o); + } + + @Override + public void removeAttribute(String name) + { + this.javax.removeAttribute(name); + } + + @Override + public Locale getLocale() + { + return this.javax.getLocale(); + } + + @Override + public Enumeration getLocales() + { + return this.javax.getLocales(); + } + + @Override + public boolean isSecure() + { + return this.javax.isSecure(); + } + + @Override + public RequestDispatcher getRequestDispatcher(String path) + { + return JakartaServletBridge.toJakarta(this.javax.getRequestDispatcher(path)); + } + + @Override + public String getRealPath(String path) + { + return this.javax.getRealPath(path); + } + + @Override + public int getRemotePort() + { + return this.javax.getRemotePort(); + } + + @Override + public String getLocalName() + { + return this.javax.getLocalName(); + } + + @Override + public String getLocalAddr() + { + return this.javax.getLocalAddr(); + } + + @Override + public int getLocalPort() + { + return this.javax.getLocalPort(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJakarta(this.javax.getServletContext()); + } + + @Override + public AsyncContext startAsync() throws IllegalStateException + { + return JakartaServletBridge.toJakarta(this.javax.startAsync()); + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) + throws IllegalStateException + { + return JakartaServletBridge.toJakarta(this.javax.startAsync(JakartaServletBridge.toJavax(servletRequest), + JakartaServletBridge.toJavax(servletResponse))); + } + + @Override + public boolean isAsyncStarted() + { + return this.javax.isAsyncStarted(); + } + + @Override + public boolean isAsyncSupported() + { + return this.javax.isAsyncSupported(); + } + + @Override + public AsyncContext getAsyncContext() + { + return JakartaServletBridge.toJakarta(this.javax.getAsyncContext()); + } + + @Override + public DispatcherType getDispatcherType() + { + return JakartaServletBridge.toJakarta(this.javax.getDispatcherType()); + } + + @Override + public String getAuthType() + { + return this.javax.getAuthType(); + } + + @Override + public Cookie[] getCookies() + { + return JakartaServletBridge.toJakarta(this.javax.getCookies()); + } + + @Override + public long getDateHeader(String name) + { + return this.javax.getDateHeader(name); + } + + @Override + public String getHeader(String name) + { + return this.javax.getHeader(name); + } + + @Override + public Enumeration getHeaders(String name) + { + return this.javax.getHeaders(name); + } + + @Override + public Enumeration getHeaderNames() + { + return this.javax.getHeaderNames(); + } + + @Override + public int getIntHeader(String name) + { + return this.javax.getIntHeader(name); + } + + @Override + public String getMethod() + { + return this.javax.getMethod(); + } + + @Override + public String getPathInfo() + { + return this.javax.getPathInfo(); + } + + @Override + public String getPathTranslated() + { + return this.javax.getPathTranslated(); + } + + @Override + public String getContextPath() + { + return this.javax.getContextPath(); + } + + @Override + public String getQueryString() + { + return this.javax.getQueryString(); + } + + @Override + public String getRemoteUser() + { + return this.javax.getRemoteUser(); + } + + @Override + public boolean isUserInRole(String role) + { + return this.javax.isUserInRole(role); + } + + @Override + public Principal getUserPrincipal() + { + return this.javax.getUserPrincipal(); + } + + @Override + public String getRequestedSessionId() + { + return this.javax.getRequestedSessionId(); + } + + @Override + public String getRequestURI() + { + return this.javax.getRequestURI(); + } + + @Override + public StringBuffer getRequestURL() + { + return this.javax.getRequestURL(); + } + + @Override + public String getServletPath() + { + return this.javax.getServletPath(); + } + + @Override + public HttpSession getSession(boolean create) + { + return JakartaServletBridge.toJakarta(this.javax.getSession(create)); + } + + @Override + public HttpSession getSession() + { + return JakartaServletBridge.toJakarta(this.javax.getSession()); + } + + @Override + public String changeSessionId() + { + return this.javax.changeSessionId(); + } + + @Override + public boolean isRequestedSessionIdValid() + { + return this.javax.isRequestedSessionIdValid(); + } + + @Override + public boolean isRequestedSessionIdFromCookie() + { + return this.javax.isRequestedSessionIdFromCookie(); + } + + @Override + public boolean isRequestedSessionIdFromURL() + { + return this.javax.isRequestedSessionIdFromURL(); + } + + @Override + public boolean isRequestedSessionIdFromUrl() + { + return this.javax.isRequestedSessionIdFromUrl(); + } + + @Override + public boolean authenticate(HttpServletResponse response) throws IOException, ServletException + { + try { + return this.javax.authenticate(JakartaServletBridge.toJavax(response)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void login(String username, String password) throws ServletException + { + try { + this.javax.login(username, password); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void logout() throws ServletException + { + try { + this.javax.logout(); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Collection getParts() throws IOException, ServletException + { + try { + return JakartaServletBridge.toJakarta(this.javax.getParts()); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Part getPart(String name) throws IOException, ServletException + { + try { + return JakartaServletBridge.toJakarta(this.javax.getPart(name)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public T upgrade(Class handlerClass) throws IOException, ServletException + { + // TODO + throw new UnsupportedOperationException(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletResponse.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletResponse.java new file mode 100644 index 0000000000..4c1cd0e61e --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletResponse.java @@ -0,0 +1,171 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.util.Collection; + +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletResponse; + +/** + * @param the type of http servlet response + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxHttpServletResponse + extends JakartaToJavaxServletResponse implements HttpServletResponse +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxHttpServletResponse(R javax) + { + super(javax); + } + + @Override + public void addCookie(Cookie cookie) + { + this.javax.addCookie(JakartaServletBridge.toJavax(cookie)); + } + + @Override + public boolean containsHeader(String name) + { + return this.javax.containsHeader(name); + } + + @Override + public String encodeURL(String url) + { + return this.javax.encodeURL(url); + } + + @Override + public String encodeRedirectURL(String url) + { + return this.javax.encodeRedirectURL(url); + } + + @Override + public String encodeUrl(String url) + { + return this.javax.encodeUrl(url); + } + + @Override + public String encodeRedirectUrl(String url) + { + return this.javax.encodeRedirectUrl(url); + } + + @Override + public void sendError(int sc, String msg) throws IOException + { + this.javax.sendError(sc, msg); + } + + @Override + public void sendError(int sc) throws IOException + { + this.javax.sendError(sc); + } + + @Override + public void sendRedirect(String location) throws IOException + { + this.javax.sendRedirect(location); + } + + @Override + public void setDateHeader(String name, long date) + { + this.javax.setDateHeader(name, date); + } + + @Override + public void addDateHeader(String name, long date) + { + this.javax.addDateHeader(name, date); + } + + @Override + public void setHeader(String name, String value) + { + this.javax.setHeader(name, value); + } + + @Override + public void addHeader(String name, String value) + { + this.javax.addHeader(name, value); + } + + @Override + public void setIntHeader(String name, int value) + { + this.javax.setIntHeader(name, value); + } + + @Override + public void addIntHeader(String name, int value) + { + this.javax.addIntHeader(name, value); + } + + @Override + public void setStatus(int sc) + { + this.javax.setStatus(sc); + } + + @Override + public void setStatus(int sc, String sm) + { + this.javax.setStatus(sc, sm); + } + + @Override + public int getStatus() + { + return this.javax.getStatus(); + } + + @Override + public String getHeader(String name) + { + return this.javax.getHeader(name); + } + + @Override + public Collection getHeaders(String name) + { + return this.javax.getHeaders(name); + } + + @Override + public Collection getHeaderNames() + { + return this.javax.getHeaderNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletResponseWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletResponseWrapper.java new file mode 100644 index 0000000000..1b43d8c349 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpServletResponseWrapper.java @@ -0,0 +1,285 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Collection; +import java.util.Locale; + +import org.xwiki.jakartabridge.JakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletResponseWrapper; + +/** + * @param the type of http servlet response + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxHttpServletResponseWrapper + extends HttpServletResponseWrapper implements JakartaToJavaxWrapper +{ + protected final R javax; + + /** + * @param javax the wrapped version + */ + public JakartaToJavaxHttpServletResponseWrapper(R javax) + { + super(JakartaServletBridge.toJakarta((javax.servlet.http.HttpServletResponse) javax.getResponse())); + + this.javax = javax; + } + + // JakartaToJavaxWrapper + + @Override + public R getJavax() + { + return this.javax; + } + + // HttpServletResponse + + @Override + public String getCharacterEncoding() + { + return this.javax.getCharacterEncoding(); + } + + @Override + public String getContentType() + { + return this.javax.getContentType(); + } + + @Override + public ServletOutputStream getOutputStream() throws IOException + { + return JakartaServletBridge.toJakarta(this.javax.getOutputStream()); + } + + @Override + public PrintWriter getWriter() throws IOException + { + return this.javax.getWriter(); + } + + @Override + public void setCharacterEncoding(String charset) + { + this.javax.setCharacterEncoding(charset); + } + + @Override + public void setContentLength(int len) + { + this.javax.setContentLength(len); + } + + @Override + public void setContentLengthLong(long len) + { + this.javax.setContentLengthLong(len); + } + + @Override + public void setContentType(String type) + { + this.javax.setContentType(type); + } + + @Override + public void setBufferSize(int size) + { + this.javax.setBufferSize(size); + } + + @Override + public int getBufferSize() + { + return this.javax.getBufferSize(); + } + + @Override + public void flushBuffer() throws IOException + { + this.javax.flushBuffer(); + } + + @Override + public void resetBuffer() + { + this.javax.resetBuffer(); + } + + @Override + public boolean isCommitted() + { + return this.javax.isCommitted(); + } + + @Override + public void reset() + { + this.javax.reset(); + } + + @Override + public void setLocale(Locale loc) + { + this.javax.setLocale(loc); + } + + @Override + public Locale getLocale() + { + return this.javax.getLocale(); + } + + @Override + public void addCookie(Cookie cookie) + { + this.javax.addCookie(JakartaServletBridge.toJavax(cookie)); + } + + @Override + public boolean containsHeader(String name) + { + return this.javax.containsHeader(name); + } + + @Override + public String encodeURL(String url) + { + return this.javax.encodeURL(url); + } + + @Override + public String encodeRedirectURL(String url) + { + return this.javax.encodeRedirectURL(url); + } + + @Override + public String encodeUrl(String url) + { + return this.javax.encodeUrl(url); + } + + @Override + public String encodeRedirectUrl(String url) + { + return this.javax.encodeRedirectUrl(url); + } + + @Override + public void sendError(int sc, String msg) throws IOException + { + this.javax.sendError(sc, msg); + } + + @Override + public void sendError(int sc) throws IOException + { + this.javax.sendError(sc); + } + + @Override + public void sendRedirect(String location) throws IOException + { + this.javax.sendRedirect(location); + } + + @Override + public void setDateHeader(String name, long date) + { + this.javax.setDateHeader(name, date); + } + + @Override + public void addDateHeader(String name, long date) + { + this.javax.addDateHeader(name, date); + } + + @Override + public void setHeader(String name, String value) + { + this.javax.setHeader(name, value); + } + + @Override + public void addHeader(String name, String value) + { + this.javax.addHeader(name, value); + } + + @Override + public void setIntHeader(String name, int value) + { + this.javax.setIntHeader(name, value); + } + + @Override + public void addIntHeader(String name, int value) + { + this.javax.addIntHeader(name, value); + } + + @Override + public void setStatus(int sc) + { + this.javax.setStatus(sc); + } + + @Override + public void setStatus(int sc, String sm) + { + this.javax.setStatus(sc, sm); + } + + @Override + public int getStatus() + { + return this.javax.getStatus(); + } + + @Override + public String getHeader(String name) + { + return this.javax.getHeader(name); + } + + @Override + public Collection getHeaders(String name) + { + return this.javax.getHeaders(name); + } + + @Override + public Collection getHeaderNames() + { + return this.javax.getHeaderNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpSession.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpSession.java new file mode 100644 index 0000000000..668ebc9b98 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpSession.java @@ -0,0 +1,148 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Enumeration; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpSessionContext; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxHttpSession extends AbstractJakartaToJavaxWrapper + implements HttpSession +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxHttpSession(javax.servlet.http.HttpSession javax) + { + super(javax); + } + + @Override + public long getCreationTime() + { + return this.javax.getCreationTime(); + } + + @Override + public String getId() + { + return this.javax.getId(); + } + + @Override + public long getLastAccessedTime() + { + return this.javax.getLastAccessedTime(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJakarta(this.javax.getServletContext()); + } + + @Override + public void setMaxInactiveInterval(int interval) + { + this.javax.setMaxInactiveInterval(interval); + } + + @Override + public int getMaxInactiveInterval() + { + return this.javax.getMaxInactiveInterval(); + } + + @Override + public HttpSessionContext getSessionContext() + { + return JakartaServletBridge.toJakarta(this.javax.getSessionContext()); + } + + @Override + public Object getAttribute(String name) + { + return this.javax.getAttribute(name); + } + + @Override + public Object getValue(String name) + { + return this.javax.getValue(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.javax.getAttributeNames(); + } + + @Override + public String[] getValueNames() + { + return this.javax.getValueNames(); + } + + @Override + public void setAttribute(String name, Object value) + { + this.javax.setAttribute(name, value); + } + + @Override + public void putValue(String name, Object value) + { + this.javax.putValue(name, value); + } + + @Override + public void removeAttribute(String name) + { + this.javax.removeAttribute(name); + } + + @Override + public void removeValue(String name) + { + this.javax.removeValue(name); + } + + @Override + public void invalidate() + { + this.javax.invalidate(); + } + + @Override + public boolean isNew() + { + return this.javax.isNew(); + } + +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpSessionContext.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpSessionContext.java new file mode 100644 index 0000000000..8a5db71408 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxHttpSessionContext.java @@ -0,0 +1,57 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Enumeration; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpSessionContext; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxHttpSessionContext + extends AbstractJakartaToJavaxWrapper implements HttpSessionContext +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxHttpSessionContext(javax.servlet.http.HttpSessionContext javax) + { + super(javax); + } + + @Override + public HttpSession getSession(String sessionId) + { + return JakartaServletBridge.toJakarta(this.javax.getSession(sessionId)); + } + + @Override + public Enumeration getIds() + { + return this.javax.getIds(); + } + +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxPart.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxPart.java new file mode 100644 index 0000000000..0195f0a382 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxPart.java @@ -0,0 +1,103 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; + +import jakarta.servlet.http.Part; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxPart extends AbstractJakartaToJavaxWrapper implements Part +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxPart(javax.servlet.http.Part javax) + { + super(javax); + } + + @Override + public InputStream getInputStream() throws IOException + { + return this.javax.getInputStream(); + } + + @Override + public String getContentType() + { + return this.javax.getContentType(); + } + + @Override + public String getName() + { + return this.javax.getName(); + } + + @Override + public String getSubmittedFileName() + { + return this.javax.getSubmittedFileName(); + } + + @Override + public long getSize() + { + return this.javax.getSize(); + } + + @Override + public void write(String fileName) throws IOException + { + this.javax.write(fileName); + } + + @Override + public void delete() throws IOException + { + this.javax.delete(); + } + + @Override + public String getHeader(String name) + { + return this.javax.getHeader(name); + } + + @Override + public Collection getHeaders(String name) + { + return this.javax.getHeaders(name); + } + + @Override + public Collection getHeaderNames() + { + return this.javax.getHeaderNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxReadListener.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxReadListener.java new file mode 100644 index 0000000000..f2c560c871 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxReadListener.java @@ -0,0 +1,60 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; + +import jakarta.servlet.ReadListener; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxReadListener extends AbstractJakartaToJavaxWrapper + implements ReadListener +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxReadListener(javax.servlet.ReadListener javax) + { + super(javax); + } + + @Override + public void onDataAvailable() throws IOException + { + this.javax.onDataAvailable(); + } + + @Override + public void onAllDataRead() throws IOException + { + this.javax.onAllDataRead(); + } + + @Override + public void onError(Throwable t) + { + this.javax.onError(t); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxRequestDispatcher.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxRequestDispatcher.java new file mode 100644 index 0000000000..4fe9573c8e --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxRequestDispatcher.java @@ -0,0 +1,66 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxRequestDispatcher extends AbstractJakartaToJavaxWrapper + implements RequestDispatcher +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxRequestDispatcher(javax.servlet.RequestDispatcher javax) + { + super(javax); + } + + @Override + public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException + { + try { + this.javax.forward(JakartaServletBridge.toJavax(request), JakartaServletBridge.toJavax(response)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException + { + try { + this.javax.include(JakartaServletBridge.toJavax(request), JakartaServletBridge.toJavax(response)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServlet.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServlet.java new file mode 100644 index 0000000000..d01e6c555e --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServlet.java @@ -0,0 +1,84 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServlet extends AbstractJakartaToJavaxWrapper implements Servlet +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServlet(javax.servlet.Servlet javax) + { + super(javax); + } + + @Override + public void init(ServletConfig config) throws ServletException + { + try { + this.javax.init(JakartaServletBridge.toJavax(config)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public ServletConfig getServletConfig() + { + return JakartaServletBridge.toJakarta(this.javax.getServletConfig()); + } + + @Override + public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException + { + try { + this.javax.service(JakartaServletBridge.toJavax(req), JakartaServletBridge.toJavax(res)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public String getServletInfo() + { + return this.javax.getServletInfo(); + } + + @Override + public void destroy() + { + this.javax.destroy(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletConfig.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletConfig.java new file mode 100644 index 0000000000..cc128c4722 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletConfig.java @@ -0,0 +1,68 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Enumeration; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServletConfig extends AbstractJakartaToJavaxWrapper + implements ServletConfig +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServletConfig(javax.servlet.ServletConfig javax) + { + super(javax); + } + + @Override + public String getServletName() + { + return this.javax.getServletName(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJakarta(this.javax.getServletContext()); + } + + @Override + public String getInitParameter(String name) + { + return this.javax.getInitParameter(name); + } + + @Override + public Enumeration getInitParameterNames() + { + return this.javax.getInitParameterNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletContext.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletContext.java new file mode 100644 index 0000000000..447e1f2f2c --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletContext.java @@ -0,0 +1,428 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Enumeration; +import java.util.EventListener; +import java.util.Map; +import java.util.Set; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRegistration; +import jakarta.servlet.ServletRegistration.Dynamic; +import jakarta.servlet.SessionCookieConfig; +import jakarta.servlet.SessionTrackingMode; +import jakarta.servlet.descriptor.JspConfigDescriptor; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServletContext extends AbstractJakartaToJavaxWrapper + implements ServletContext +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServletContext(javax.servlet.ServletContext javax) + { + super(javax); + } + + @Override + public String getContextPath() + { + return this.javax.getContextPath(); + } + + @Override + public ServletContext getContext(String uripath) + { + return new JakartaToJavaxServletContext(this.javax.getContext(uripath)); + } + + @Override + public int getMajorVersion() + { + return this.javax.getMajorVersion(); + } + + @Override + public int getMinorVersion() + { + return this.javax.getMinorVersion(); + } + + @Override + public int getEffectiveMajorVersion() + { + return this.javax.getEffectiveMajorVersion(); + } + + @Override + public int getEffectiveMinorVersion() + { + return this.javax.getEffectiveMinorVersion(); + } + + @Override + public String getMimeType(String file) + { + return this.javax.getMimeType(file); + } + + @Override + public Set getResourcePaths(String path) + { + return this.javax.getResourcePaths(path); + } + + @Override + public URL getResource(String path) throws MalformedURLException + { + return this.javax.getResource(path); + } + + @Override + public InputStream getResourceAsStream(String path) + { + return this.javax.getResourceAsStream(path); + } + + @Override + public RequestDispatcher getRequestDispatcher(String path) + { + return JakartaServletBridge.toJakarta(this.javax.getRequestDispatcher(path)); + } + + @Override + public RequestDispatcher getNamedDispatcher(String name) + { + return JakartaServletBridge.toJakarta(this.javax.getNamedDispatcher(name)); + } + + @Override + public Servlet getServlet(String name) throws ServletException + { + try { + return JakartaServletBridge.toJakarta(this.javax.getServlet(name)); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Enumeration getServlets() + { + return JakartaServletBridge.toJakarta(this.javax.getServlets()); + } + + @Override + public Enumeration getServletNames() + { + return this.javax.getServletNames(); + } + + @Override + public void log(String msg) + { + this.javax.log(msg); + } + + @Override + public void log(Exception exception, String msg) + { + this.javax.log(exception, msg); + } + + @Override + public void log(String message, Throwable throwable) + { + this.javax.log(message, throwable); + } + + @Override + public String getRealPath(String path) + { + return this.javax.getRealPath(path); + } + + @Override + public String getServerInfo() + { + return this.javax.getServerInfo(); + } + + @Override + public String getInitParameter(String name) + { + return this.javax.getInitParameter(name); + } + + @Override + public Enumeration getInitParameterNames() + { + return this.javax.getInitParameterNames(); + } + + @Override + public boolean setInitParameter(String name, String value) + { + return this.javax.setInitParameter(name, value); + } + + @Override + public Object getAttribute(String name) + { + return this.javax.getAttribute(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.javax.getAttributeNames(); + } + + @Override + public void setAttribute(String name, Object object) + { + this.javax.setAttribute(name, object); + } + + @Override + public void removeAttribute(String name) + { + this.javax.removeAttribute(name); + } + + @Override + public String getServletContextName() + { + return this.javax.getServletContextName(); + } + + @Override + public Dynamic addServlet(String servletName, String className) + { + return JakartaServletBridge.toJakarta(this.javax.addServlet(servletName, className)); + } + + @Override + public Dynamic addServlet(String servletName, Servlet servlet) + { + return JakartaServletBridge + .toJakarta(this.javax.addServlet(servletName, JakartaServletBridge.toJavax(servlet))); + } + + @Override + public Dynamic addServlet(String servletName, Class servletClass) + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public T createServlet(Class clazz) throws ServletException + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public ServletRegistration getServletRegistration(String servletName) + { + return JakartaServletBridge.toJakarta(this.javax.getServletRegistration(servletName)); + } + + @Override + public Map getServletRegistrations() + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public FilterRegistration.Dynamic addFilter(String filterName, String className) + { + return JakartaServletBridge.toJakarta(this.javax.addFilter(filterName, className)); + } + + @Override + public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) + { + return JakartaServletBridge.toJakarta(this.javax.addFilter(filterName, JakartaServletBridge.toJavax(filter))); + } + + @Override + public FilterRegistration.Dynamic addFilter(String filterName, Class filterClass) + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public T createFilter(Class clazz) throws ServletException + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public FilterRegistration getFilterRegistration(String filterName) + { + return JakartaServletBridge.toJakarta(this.javax.getFilterRegistration(filterName)); + } + + @Override + public Map getFilterRegistrations() + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public SessionCookieConfig getSessionCookieConfig() + { + return JakartaServletBridge.toJakarta(this.javax.getSessionCookieConfig()); + } + + @Override + public void setSessionTrackingModes(Set sessionTrackingModes) + { + this.javax.setSessionTrackingModes(JakartaServletBridge.toJavax(sessionTrackingModes)); + } + + @Override + public Set getDefaultSessionTrackingModes() + { + return JakartaServletBridge.toJakarta(this.javax.getDefaultSessionTrackingModes()); + } + + @Override + public Set getEffectiveSessionTrackingModes() + { + return JakartaServletBridge.toJakarta(this.javax.getEffectiveSessionTrackingModes()); + } + + @Override + public void addListener(String className) + { + this.javax.addListener(className); + } + + @Override + public void addListener(T t) + { + this.javax.addListener(t); + } + + @Override + public void addListener(Class listenerClass) + { + this.javax.addListener(listenerClass); + } + + @Override + public T createListener(Class clazz) throws ServletException + { + try { + return this.javax.createListener(clazz); + } catch (javax.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public JspConfigDescriptor getJspConfigDescriptor() + { + return JakartaServletBridge.toJakarta(this.javax.getJspConfigDescriptor()); + } + + @Override + public ClassLoader getClassLoader() + { + return this.javax.getClassLoader(); + } + + @Override + public void declareRoles(String... roleNames) + { + this.javax.declareRoles(roleNames); + } + + @Override + public String getVirtualServerName() + { + return this.javax.getVirtualServerName(); + } + + @Override + public Dynamic addJspFile(String servletName, String jspFile) + { + throw new UnsupportedOperationException(); + } + + @Override + public int getSessionTimeout() + { + throw new UnsupportedOperationException(); + } + + @Override + public void setSessionTimeout(int sessionTimeout) + { + throw new UnsupportedOperationException(); + } + + @Override + public String getRequestCharacterEncoding() + { + throw new UnsupportedOperationException(); + } + + @Override + public void setRequestCharacterEncoding(String encoding) + { + throw new UnsupportedOperationException(); + } + + @Override + public String getResponseCharacterEncoding() + { + throw new UnsupportedOperationException(); + } + + @Override + public void setResponseCharacterEncoding(String encoding) + { + throw new UnsupportedOperationException(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletInputStream.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletInputStream.java new file mode 100644 index 0000000000..38a775c25f --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletInputStream.java @@ -0,0 +1,82 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import org.xwiki.jakartabridge.JakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.ReadListener; +import jakarta.servlet.ServletInputStream; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServletInputStream extends ServletInputStream + implements JakartaToJavaxWrapper +{ + private final javax.servlet.ServletInputStream javax; + + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServletInputStream(javax.servlet.ServletInputStream javax) + { + this.javax = javax; + } + + @Override + public javax.servlet.ServletInputStream getJavax() + { + return this.javax; + } + + @Override + public boolean isFinished() + { + return this.javax.isFinished(); + } + + @Override + public boolean isReady() + { + return this.javax.isReady(); + } + + @Override + public void setReadListener(ReadListener readListener) + { + this.javax.setReadListener(JakartaServletBridge.toJavax(readListener)); + } + + @Override + public int read() throws IOException + { + return this.javax.read(); + } + + @Override + public int readLine(byte[] b, int off, int len) throws IOException + { + return this.javax.readLine(b, off, len); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletOutputStream.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletOutputStream.java new file mode 100644 index 0000000000..f95ebc85fb --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletOutputStream.java @@ -0,0 +1,165 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import org.xwiki.jakartabridge.JakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.WriteListener; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServletOutputStream extends ServletOutputStream + implements JakartaToJavaxWrapper +{ + private final javax.servlet.ServletOutputStream javax; + + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServletOutputStream(javax.servlet.ServletOutputStream javax) + { + this.javax = javax; + } + + @Override + public javax.servlet.ServletOutputStream getJavax() + { + return this.javax; + } + + @Override + public boolean isReady() + { + return this.javax.isReady(); + } + + @Override + public void setWriteListener(WriteListener writeListener) + { + this.javax.setWriteListener(JakartaServletBridge.toJavax(writeListener)); + } + + @Override + public void write(int b) throws IOException + { + this.javax.write(b); + } + + @Override + public void print(String s) throws IOException + { + this.javax.print(s); + } + + @Override + + public void print(boolean b) throws IOException + { + this.javax.print(b); + } + + @Override + public void print(char c) throws IOException + { + this.javax.print(c); + } + + @Override + + public void print(int i) throws IOException + { + this.javax.print(i); + } + + @Override + public void print(long l) throws IOException + { + this.javax.print(l); + } + + @Override + public void print(float f) throws IOException + { + this.javax.print(f); + } + + @Override + + public void print(double d) throws IOException + { + this.javax.print(d); + } + + @Override + public void println() throws IOException + { + this.javax.println(); + } + + @Override + public void println(String s) throws IOException + { + this.javax.println(s); + } + + @Override + public void println(boolean b) throws IOException + { + this.javax.println(b); + } + + @Override + public void println(char c) throws IOException + { + this.javax.println(c); + } + + @Override + + public void println(int i) throws IOException + { + this.javax.println(i); + } + + @Override + + public void println(long l) throws IOException + { + this.javax.println(l); + } + + @Override + public void println(float f) throws IOException + { + this.javax.println(f); + } + + @Override + public void println(double d) throws IOException + { + this.javax.println(d); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletRegistration.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletRegistration.java new file mode 100644 index 0000000000..6817aec9f0 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletRegistration.java @@ -0,0 +1,147 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.MultipartConfigElement; +import jakarta.servlet.ServletRegistration; +import jakarta.servlet.ServletSecurityElement; + +/** + * @param the exact type of jakarta.servlet.ServletRegistration + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServletRegistration + extends AbstractJakartaToJavaxWrapper implements ServletRegistration +{ + /** + * @version $Id$ + */ + public static class Dynamic extends JakartaToJavaxServletRegistration + implements ServletRegistration.Dynamic + { + /** + * @param javax + */ + public Dynamic(javax.servlet.ServletRegistration.Dynamic javax) + { + super(javax); + } + + @Override + public void setLoadOnStartup(int loadOnStartup) + { + this.javax.setLoadOnStartup(loadOnStartup); + } + + @Override + public Set setServletSecurity(ServletSecurityElement constraint) + { + return this.javax.setServletSecurity(JakartaServletBridge.toJavax(constraint)); + } + + @Override + public void setMultipartConfig(MultipartConfigElement multipartConfig) + { + this.javax.setMultipartConfig(JakartaServletBridge.toJavax(multipartConfig)); + } + + @Override + public void setRunAsRole(String roleName) + { + this.javax.setRunAsRole(roleName); + } + + @Override + public void setAsyncSupported(boolean isAsyncSupported) + { + this.javax.setAsyncSupported(isAsyncSupported); + } + } + + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServletRegistration(T javax) + { + super(javax); + } + + @Override + public String getName() + { + return this.javax.getName(); + } + + @Override + public String getClassName() + { + return this.javax.getClassName(); + } + + @Override + public boolean setInitParameter(String name, String value) + { + return this.javax.setInitParameter(name, value); + } + + @Override + public String getInitParameter(String name) + { + return this.javax.getInitParameter(name); + } + + @Override + public Set setInitParameters(Map initParameters) + { + return this.javax.setInitParameters(initParameters); + } + + @Override + public Map getInitParameters() + { + return this.javax.getInitParameters(); + } + + @Override + public Set addMapping(String... urlPatterns) + { + return this.javax.addMapping(urlPatterns); + } + + @Override + public Collection getMappings() + { + return this.javax.getMappings(); + } + + @Override + public String getRunAsRole() + { + return this.javax.getRunAsRole(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletRequest.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletRequest.java new file mode 100644 index 0000000000..509c8ae126 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletRequest.java @@ -0,0 +1,279 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * @param the type of servlet request + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServletRequest + extends AbstractJakartaToJavaxWrapper implements ServletRequest +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServletRequest(R javax) + { + super(javax); + } + + @Override + public Object getAttribute(String name) + { + return this.javax.getAttribute(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.javax.getAttributeNames(); + } + + @Override + public String getCharacterEncoding() + { + return this.javax.getCharacterEncoding(); + } + + @Override + public void setCharacterEncoding(String env) throws UnsupportedEncodingException + { + this.javax.setCharacterEncoding(env); + } + + @Override + public int getContentLength() + { + return this.javax.getContentLength(); + } + + @Override + public long getContentLengthLong() + { + return this.javax.getContentLengthLong(); + } + + @Override + public String getContentType() + { + return this.javax.getContentType(); + } + + @Override + public ServletInputStream getInputStream() throws IOException + { + return JakartaServletBridge.toJakarta(this.javax.getInputStream()); + } + + @Override + public String getParameter(String name) + { + return this.javax.getParameter(name); + } + + @Override + public Enumeration getParameterNames() + { + return this.javax.getParameterNames(); + } + + @Override + public String[] getParameterValues(String name) + { + return this.javax.getParameterValues(name); + } + + @Override + public Map getParameterMap() + { + return this.javax.getParameterMap(); + } + + @Override + public String getProtocol() + { + return this.javax.getProtocol(); + } + + @Override + public String getScheme() + { + return this.javax.getScheme(); + } + + @Override + public String getServerName() + { + return this.javax.getServerName(); + } + + @Override + public int getServerPort() + { + return this.javax.getServerPort(); + } + + @Override + public BufferedReader getReader() throws IOException + { + return this.javax.getReader(); + } + + @Override + public String getRemoteAddr() + { + return this.javax.getRemoteAddr(); + } + + @Override + public String getRemoteHost() + { + return this.javax.getRemoteHost(); + } + + @Override + public void setAttribute(String name, Object o) + { + this.javax.setAttribute(name, o); + } + + @Override + public void removeAttribute(String name) + { + this.javax.removeAttribute(name); + } + + @Override + public Locale getLocale() + { + return this.javax.getLocale(); + } + + @Override + public Enumeration getLocales() + { + return this.javax.getLocales(); + } + + @Override + public boolean isSecure() + { + return this.javax.isSecure(); + } + + @Override + public RequestDispatcher getRequestDispatcher(String path) + { + return JakartaServletBridge.toJakarta(this.javax.getRequestDispatcher(path)); + } + + @Override + public String getRealPath(String path) + { + return this.javax.getRealPath(path); + } + + @Override + public int getRemotePort() + { + return this.javax.getRemotePort(); + } + + @Override + public String getLocalName() + { + return this.javax.getLocalName(); + } + + @Override + public String getLocalAddr() + { + return this.javax.getLocalAddr(); + } + + @Override + public int getLocalPort() + { + return this.javax.getLocalPort(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJakarta(this.javax.getServletContext()); + } + + @Override + public AsyncContext startAsync() throws IllegalStateException + { + return JakartaServletBridge.toJakarta(this.javax.startAsync()); + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) + throws IllegalStateException + { + return JakartaServletBridge.toJakarta(this.javax.startAsync(JakartaServletBridge.toJavax(servletRequest), + JakartaServletBridge.toJavax(servletResponse))); + } + + @Override + public boolean isAsyncStarted() + { + return this.javax.isAsyncStarted(); + } + + @Override + public boolean isAsyncSupported() + { + return this.javax.isAsyncSupported(); + } + + @Override + public AsyncContext getAsyncContext() + { + return JakartaServletBridge.toJakarta(this.javax.getAsyncContext()); + } + + @Override + public DispatcherType getDispatcherType() + { + return JakartaServletBridge.toJakarta(this.javax.getDispatcherType()); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletRequestWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletRequestWrapper.java new file mode 100644 index 0000000000..7e6f22a696 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletRequestWrapper.java @@ -0,0 +1,294 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +import org.xwiki.jakartabridge.JakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +/** + * @param the type of http servlet request + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServletRequestWrapper + extends ServletRequestWrapper implements JakartaToJavaxWrapper +{ + protected final R javax; + + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServletRequestWrapper(R javax) + { + super(JakartaServletBridge.toJakarta(javax.getRequest())); + + this.javax = javax; + } + + // JakartaToJavaxWrapper + + @Override + public R getJavax() + { + return this.javax; + } + + // ServletRequest + + @Override + public Object getAttribute(String name) + { + return this.javax.getAttribute(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.javax.getAttributeNames(); + } + + @Override + public String getCharacterEncoding() + { + return this.javax.getCharacterEncoding(); + } + + @Override + public void setCharacterEncoding(String env) throws UnsupportedEncodingException + { + this.javax.setCharacterEncoding(env); + } + + @Override + public int getContentLength() + { + return this.javax.getContentLength(); + } + + @Override + public long getContentLengthLong() + { + return this.javax.getContentLengthLong(); + } + + @Override + public String getContentType() + { + return this.javax.getContentType(); + } + + @Override + public ServletInputStream getInputStream() throws IOException + { + return JakartaServletBridge.toJakarta(this.javax.getInputStream()); + } + + @Override + public String getParameter(String name) + { + return this.javax.getParameter(name); + } + + @Override + public Enumeration getParameterNames() + { + return this.javax.getParameterNames(); + } + + @Override + public String[] getParameterValues(String name) + { + return this.javax.getParameterValues(name); + } + + @Override + public Map getParameterMap() + { + return this.javax.getParameterMap(); + } + + @Override + public String getProtocol() + { + return this.javax.getProtocol(); + } + + @Override + public String getScheme() + { + return this.javax.getScheme(); + } + + @Override + public String getServerName() + { + return this.javax.getServerName(); + } + + @Override + public int getServerPort() + { + return this.javax.getServerPort(); + } + + @Override + public BufferedReader getReader() throws IOException + { + return this.javax.getReader(); + } + + @Override + public String getRemoteAddr() + { + return this.javax.getRemoteAddr(); + } + + @Override + public String getRemoteHost() + { + return this.javax.getRemoteHost(); + } + + @Override + public void setAttribute(String name, Object o) + { + this.javax.setAttribute(name, o); + } + + @Override + public void removeAttribute(String name) + { + this.javax.removeAttribute(name); + } + + @Override + public Locale getLocale() + { + return this.javax.getLocale(); + } + + @Override + public Enumeration getLocales() + { + return this.javax.getLocales(); + } + + @Override + public boolean isSecure() + { + return this.javax.isSecure(); + } + + @Override + public RequestDispatcher getRequestDispatcher(String path) + { + return JakartaServletBridge.toJakarta(this.javax.getRequestDispatcher(path)); + } + + @Override + public String getRealPath(String path) + { + return this.javax.getRealPath(path); + } + + @Override + public int getRemotePort() + { + return this.javax.getRemotePort(); + } + + @Override + public String getLocalName() + { + return this.javax.getLocalName(); + } + + @Override + public String getLocalAddr() + { + return this.javax.getLocalAddr(); + } + + @Override + public int getLocalPort() + { + return this.javax.getLocalPort(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJakarta(this.javax.getServletContext()); + } + + @Override + public AsyncContext startAsync() throws IllegalStateException + { + return JakartaServletBridge.toJakarta(this.javax.startAsync()); + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) + throws IllegalStateException + { + return JakartaServletBridge.toJakarta(this.javax.startAsync(JakartaServletBridge.toJavax(servletRequest), + JakartaServletBridge.toJavax(servletResponse))); + } + + @Override + public boolean isAsyncStarted() + { + return this.javax.isAsyncStarted(); + } + + @Override + public boolean isAsyncSupported() + { + return this.javax.isAsyncSupported(); + } + + @Override + public AsyncContext getAsyncContext() + { + return JakartaServletBridge.toJakarta(this.javax.getAsyncContext()); + } + + @Override + public DispatcherType getDispatcherType() + { + return JakartaServletBridge.toJakarta(this.javax.getDispatcherType()); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletResponse.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletResponse.java new file mode 100644 index 0000000000..bb94c78212 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletResponse.java @@ -0,0 +1,143 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.ServletResponse; + +/** + * @param the type of servlet response + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServletResponse + extends AbstractJakartaToJavaxWrapper implements ServletResponse +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServletResponse(R javax) + { + super(javax); + } + + @Override + public String getCharacterEncoding() + { + return this.javax.getCharacterEncoding(); + } + + @Override + public String getContentType() + { + return this.javax.getContentType(); + } + + @Override + public ServletOutputStream getOutputStream() throws IOException + { + return JakartaServletBridge.toJakarta(this.javax.getOutputStream()); + } + + @Override + public PrintWriter getWriter() throws IOException + { + return this.javax.getWriter(); + } + + @Override + public void setCharacterEncoding(String charset) + { + this.javax.setCharacterEncoding(charset); + } + + @Override + public void setContentLength(int len) + { + this.javax.setContentLength(len); + } + + @Override + public void setContentLengthLong(long len) + { + this.javax.setContentLengthLong(len); + } + + @Override + public void setContentType(String type) + { + this.javax.setContentType(type); + } + + @Override + public void setBufferSize(int size) + { + this.javax.setBufferSize(size); + } + + @Override + public int getBufferSize() + { + return this.javax.getBufferSize(); + } + + @Override + public void flushBuffer() throws IOException + { + this.javax.flushBuffer(); + } + + @Override + public void resetBuffer() + { + this.javax.resetBuffer(); + } + + @Override + public boolean isCommitted() + { + return this.javax.isCommitted(); + } + + @Override + public void reset() + { + this.javax.reset(); + } + + @Override + public void setLocale(Locale loc) + { + this.javax.setLocale(loc); + } + + @Override + public Locale getLocale() + { + return this.javax.getLocale(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletResponseWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletResponseWrapper.java new file mode 100644 index 0000000000..d3575a00f4 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxServletResponseWrapper.java @@ -0,0 +1,157 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; + +import org.xwiki.jakartabridge.JakartaToJavaxWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.ServletResponseWrapper; + +/** + * @param the type of http servlet response + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxServletResponseWrapper + extends ServletResponseWrapper implements JakartaToJavaxWrapper +{ + protected final R javax; + + /** + * @param javax the wrapped version + */ + public JakartaToJavaxServletResponseWrapper(R javax) + { + super(JakartaServletBridge.toJakarta(javax.getResponse())); + + this.javax = javax; + } + + // JakartaToJavaxWrapper + + @Override + public R getJavax() + { + return this.javax; + } + + // ServletResponse + + @Override + public String getCharacterEncoding() + { + return this.javax.getCharacterEncoding(); + } + + @Override + public String getContentType() + { + return this.javax.getContentType(); + } + + @Override + public ServletOutputStream getOutputStream() throws IOException + { + return JakartaServletBridge.toJakarta(this.javax.getOutputStream()); + } + + @Override + public PrintWriter getWriter() throws IOException + { + return this.javax.getWriter(); + } + + @Override + public void setCharacterEncoding(String charset) + { + this.javax.setCharacterEncoding(charset); + } + + @Override + public void setContentLength(int len) + { + this.javax.setContentLength(len); + } + + @Override + public void setContentLengthLong(long len) + { + this.javax.setContentLengthLong(len); + } + + @Override + public void setContentType(String type) + { + this.javax.setContentType(type); + } + + @Override + public void setBufferSize(int size) + { + this.javax.setBufferSize(size); + } + + @Override + public int getBufferSize() + { + return this.javax.getBufferSize(); + } + + @Override + public void flushBuffer() throws IOException + { + this.javax.flushBuffer(); + } + + @Override + public void resetBuffer() + { + this.javax.resetBuffer(); + } + + @Override + public boolean isCommitted() + { + return this.javax.isCommitted(); + } + + @Override + public void reset() + { + this.javax.reset(); + } + + @Override + public void setLocale(Locale loc) + { + this.javax.setLocale(loc); + } + + @Override + public Locale getLocale() + { + return this.javax.getLocale(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxSessionCookieConfig.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxSessionCookieConfig.java new file mode 100644 index 0000000000..a8c640768c --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxSessionCookieConfig.java @@ -0,0 +1,124 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; + +import jakarta.servlet.SessionCookieConfig; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxSessionCookieConfig extends AbstractJakartaToJavaxWrapper + implements SessionCookieConfig +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxSessionCookieConfig(javax.servlet.SessionCookieConfig javax) + { + super(javax); + } + + @Override + public void setName(String name) + { + this.javax.setName(name); + } + + @Override + public String getName() + { + return this.javax.getName(); + } + + @Override + public void setDomain(String domain) + { + this.javax.setDomain(domain); + } + + @Override + public String getDomain() + { + return this.javax.getDomain(); + } + + @Override + public void setPath(String path) + { + this.javax.setPath(path); + } + + @Override + public String getPath() + { + return this.javax.getPath(); + } + + @Override + public void setComment(String comment) + { + this.javax.setComment(comment); + } + + @Override + public String getComment() + { + return this.javax.getComment(); + } + + @Override + public void setHttpOnly(boolean httpOnly) + { + this.javax.setHttpOnly(httpOnly); + } + + @Override + public boolean isHttpOnly() + { + return this.javax.isHttpOnly(); + } + + @Override + public void setSecure(boolean secure) + { + this.javax.setSecure(secure); + } + + @Override + public boolean isSecure() + { + return this.javax.isSecure(); + } + + @Override + public void setMaxAge(int maxAge) + { + this.javax.setMaxAge(maxAge); + } + + @Override + public int getMaxAge() + { + return this.javax.getMaxAge(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxWriteListener.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxWriteListener.java new file mode 100644 index 0000000000..12a67ac5f4 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JakartaToJavaxWriteListener.java @@ -0,0 +1,54 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import org.xwiki.jakartabridge.internal.AbstractJakartaToJavaxWrapper; + +import jakarta.servlet.WriteListener; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JakartaToJavaxWriteListener extends AbstractJakartaToJavaxWrapper + implements WriteListener +{ + /** + * @param javax the wrapped version + */ + public JakartaToJavaxWriteListener(javax.servlet.WriteListener javax) + { + super(javax); + } + + @Override + public void onWritePossible() throws IOException + { + this.javax.onWritePossible(); + } + + @Override + public void onError(Throwable t) + { + this.javax.onError(t); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaAsyncContext.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaAsyncContext.java new file mode 100644 index 0000000000..e6ff091053 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaAsyncContext.java @@ -0,0 +1,126 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import javax.servlet.AsyncContext; +import javax.servlet.AsyncListener; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaAsyncContext extends AbstractJavaxToJakartaWrapper + implements AsyncContext +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaAsyncContext(jakarta.servlet.AsyncContext jakarta) + { + super(jakarta); + } + + @Override + public ServletRequest getRequest() + { + return JakartaServletBridge.toJavax(this.jakarta.getRequest()); + } + + @Override + public ServletResponse getResponse() + { + return JakartaServletBridge.toJavax(this.jakarta.getResponse()); + } + + @Override + public boolean hasOriginalRequestAndResponse() + { + return this.jakarta.hasOriginalRequestAndResponse(); + } + + @Override + public void dispatch() + { + this.jakarta.dispatch(); + } + + @Override + public void dispatch(String path) + { + this.jakarta.dispatch(path); + } + + @Override + public void dispatch(ServletContext context, String path) + { + this.jakarta.dispatch(JakartaServletBridge.toJakarta(context), path); + } + + @Override + public void complete() + { + this.jakarta.complete(); + } + + @Override + public void start(Runnable run) + { + this.jakarta.start(run); + } + + @Override + public void addListener(AsyncListener listener) + { + this.jakarta.addListener(JakartaServletBridge.toJakarta(listener)); + } + + @Override + public void addListener(AsyncListener listener, ServletRequest servletRequest, ServletResponse servletResponse) + { + this.jakarta.addListener(JakartaServletBridge.toJakarta(listener), + JakartaServletBridge.toJakarta(servletRequest), JakartaServletBridge.toJakarta(servletResponse)); + } + + @Override + public T createListener(Class clazz) throws ServletException + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public void setTimeout(long timeout) + { + this.jakarta.setTimeout(timeout); + } + + @Override + public long getTimeout() + { + return this.jakarta.getTimeout(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaAsyncListener.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaAsyncListener.java new file mode 100644 index 0000000000..b606824677 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaAsyncListener.java @@ -0,0 +1,68 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import javax.servlet.AsyncEvent; +import javax.servlet.AsyncListener; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaAsyncListener extends AbstractJavaxToJakartaWrapper + implements AsyncListener +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaAsyncListener(jakarta.servlet.AsyncListener jakarta) + { + super(jakarta); + } + + @Override + public void onComplete(AsyncEvent event) throws IOException + { + this.jakarta.onComplete(JakartaServletBridge.toJakarta(event)); + } + + @Override + public void onTimeout(AsyncEvent event) throws IOException + { + this.jakarta.onTimeout(JakartaServletBridge.toJakarta(event)); + } + + @Override + public void onError(AsyncEvent event) throws IOException + { + this.jakarta.onError(JakartaServletBridge.toJakarta(event)); + } + + @Override + public void onStartAsync(AsyncEvent event) throws IOException + { + this.jakarta.onStartAsync(JakartaServletBridge.toJakarta(event)); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaCookie.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaCookie.java new file mode 100644 index 0000000000..cb9ec80926 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaCookie.java @@ -0,0 +1,166 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import javax.servlet.http.Cookie; + +import org.xwiki.jakartabridge.JavaxToJakartaWrapper; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaCookie extends Cookie implements JavaxToJakartaWrapper +{ + private static final long serialVersionUID = 869891252570863118L; + + private final jakarta.servlet.http.Cookie jakarta; + + /** + * @param jakarta the wrapped version + * @see Cookie#Cookie(String, String) + */ + public JavaxToJakartaCookie(jakarta.servlet.http.Cookie jakarta) + { + super("name", "value"); + + this.jakarta = jakarta; + } + + @Override + public jakarta.servlet.http.Cookie getJakarta() + { + return this.jakarta; + } + + @Override + public String getComment() + { + return this.jakarta.getComment(); + } + + @Override + public String getDomain() + { + return this.jakarta.getDomain(); + } + + @Override + public int getMaxAge() + { + return this.jakarta.getMaxAge(); + } + + @Override + public String getName() + { + return this.jakarta.getName(); + } + + @Override + public String getPath() + { + return this.jakarta.getPath(); + } + + @Override + public boolean getSecure() + { + return this.jakarta.getSecure(); + } + + @Override + public String getValue() + { + return this.jakarta.getValue(); + } + + @Override + public int getVersion() + { + return this.jakarta.getVersion(); + } + + @Override + public boolean isHttpOnly() + { + return this.jakarta.isHttpOnly(); + } + + @Override + public void setComment(String purpose) + { + this.jakarta.setComment(purpose); + } + + @Override + public void setDomain(String domain) + { + this.jakarta.setDomain(domain); + } + + @Override + public void setHttpOnly(boolean isHttpOnly) + { + this.jakarta.setHttpOnly(isHttpOnly); + } + + @Override + public void setMaxAge(int expiry) + { + this.jakarta.setMaxAge(expiry); + } + + @Override + public void setPath(String uri) + { + this.jakarta.setPath(uri); + } + + @Override + public void setSecure(boolean flag) + { + this.jakarta.setSecure(flag); + } + + @Override + public void setValue(String newValue) + { + this.jakarta.setValue(newValue); + } + + @Override + public void setVersion(int v) + { + this.jakarta.setVersion(v); + } + + @Override + public Object clone() + { + return new JavaxToJakartaCookie((jakarta.servlet.http.Cookie) this.jakarta.clone()); + } + + @Override + public String toString() + { + return this.jakarta.toString(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilter.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilter.java new file mode 100644 index 0000000000..368b5b3651 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilter.java @@ -0,0 +1,75 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaFilter extends AbstractJavaxToJakartaWrapper implements Filter +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaFilter(jakarta.servlet.Filter jakarta) + { + super(jakarta); + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException + { + try { + this.jakarta.init(JakartaServletBridge.toJakarta(filterConfig)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException + { + try { + this.jakarta.doFilter(JakartaServletBridge.toJakarta(request), JakartaServletBridge.toJakarta(response), + JakartaServletBridge.toJakarta(chain)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void destroy() + { + this.jakarta.destroy(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilterChain.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilterChain.java new file mode 100644 index 0000000000..333fb84555 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilterChain.java @@ -0,0 +1,56 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaFilterChain extends AbstractJavaxToJakartaWrapper + implements FilterChain +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaFilterChain(jakarta.servlet.FilterChain jakarta) + { + super(jakarta); + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException + { + try { + this.jakarta.doFilter(JakartaServletBridge.toJakarta(request), JakartaServletBridge.toJakarta(response)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilterConfig.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilterConfig.java new file mode 100644 index 0000000000..d5f9af3333 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilterConfig.java @@ -0,0 +1,68 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Enumeration; + +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaFilterConfig extends AbstractJavaxToJakartaWrapper + implements FilterConfig +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaFilterConfig(jakarta.servlet.FilterConfig jakarta) + { + super(jakarta); + } + + @Override + public String getFilterName() + { + return this.jakarta.getFilterName(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJavax(this.jakarta.getServletContext()); + } + + @Override + public String getInitParameter(String name) + { + return this.jakarta.getInitParameter(name); + } + + @Override + public Enumeration getInitParameterNames() + { + return this.jakarta.getInitParameterNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilterRegistration.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilterRegistration.java new file mode 100644 index 0000000000..e5744dbd1a --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaFilterRegistration.java @@ -0,0 +1,133 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Collection; +import java.util.EnumSet; +import java.util.Map; +import java.util.Set; + +import javax.servlet.DispatcherType; +import javax.servlet.FilterRegistration; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the exact type of jakarta.servlet.FilterRegistration + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaFilterRegistration + extends AbstractJavaxToJakartaWrapper implements FilterRegistration +{ + /** + * @version $Id$ + */ + public static class Dynamic extends JavaxToJakartaFilterRegistration + implements FilterRegistration.Dynamic + { + /** + * @param jakarta the wrapped version + */ + public Dynamic(jakarta.servlet.FilterRegistration.Dynamic jakarta) + { + super(jakarta); + } + + @Override + public void setAsyncSupported(boolean isAsyncSupported) + { + this.jakarta.setAsyncSupported(isAsyncSupported); + } + } + + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaFilterRegistration(T jakarta) + { + super(jakarta); + } + + @Override + public String getName() + { + return this.jakarta.getName(); + } + + @Override + public String getClassName() + { + return this.jakarta.getClassName(); + } + + @Override + public boolean setInitParameter(String name, String value) + { + return this.jakarta.setInitParameter(name, value); + } + + @Override + public String getInitParameter(String name) + { + return this.jakarta.getInitParameter(name); + } + + @Override + public Set setInitParameters(Map initParameters) + { + return this.jakarta.setInitParameters(initParameters); + } + + @Override + public Map getInitParameters() + { + return this.jakarta.getInitParameters(); + } + + @Override + public void addMappingForServletNames(EnumSet dispatcherTypes, boolean isMatchAfter, + String... servletNames) + { + this.jakarta.addMappingForServletNames(JakartaServletBridge.toJakarta(dispatcherTypes), isMatchAfter, + servletNames); + } + + @Override + public Collection getServletNameMappings() + { + return this.jakarta.getServletNameMappings(); + } + + @Override + public void addMappingForUrlPatterns(EnumSet dispatcherTypes, boolean isMatchAfter, + String... urlPatterns) + { + this.jakarta.addMappingForUrlPatterns(JakartaServletBridge.toJakarta(dispatcherTypes), isMatchAfter, + urlPatterns); + } + + @Override + public Collection getUrlPatternMappings() + { + return this.jakarta.getUrlPatternMappings(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletRequest.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletRequest.java new file mode 100644 index 0000000000..2bcd72a055 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletRequest.java @@ -0,0 +1,266 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.security.Principal; +import java.util.Collection; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpUpgradeHandler; +import javax.servlet.http.Part; + +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the type of http servlet request + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaHttpServletRequest + extends JavaxToJakartaServletRequest implements HttpServletRequest +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaHttpServletRequest(R jakarta) + { + super(jakarta); + } + + @Override + public String getAuthType() + { + return this.jakarta.getAuthType(); + } + + @Override + public Cookie[] getCookies() + { + return JakartaServletBridge.toJavax(this.jakarta.getCookies()); + } + + @Override + public long getDateHeader(String name) + { + return this.jakarta.getDateHeader(name); + } + + @Override + public String getHeader(String name) + { + return this.jakarta.getHeader(name); + } + + @Override + public Enumeration getHeaders(String name) + { + return this.jakarta.getHeaders(name); + } + + @Override + public Enumeration getHeaderNames() + { + return this.jakarta.getHeaderNames(); + } + + @Override + public int getIntHeader(String name) + { + return this.jakarta.getIntHeader(name); + } + + @Override + public String getMethod() + { + return this.jakarta.getMethod(); + } + + @Override + public String getPathInfo() + { + return this.jakarta.getPathInfo(); + } + + @Override + public String getPathTranslated() + { + return this.jakarta.getPathTranslated(); + } + + @Override + public String getContextPath() + { + return this.jakarta.getContextPath(); + } + + @Override + public String getQueryString() + { + return this.jakarta.getQueryString(); + } + + @Override + public String getRemoteUser() + { + return this.jakarta.getRemoteUser(); + } + + @Override + public boolean isUserInRole(String role) + { + return this.jakarta.isUserInRole(role); + } + + @Override + public Principal getUserPrincipal() + { + return this.jakarta.getUserPrincipal(); + } + + @Override + public String getRequestedSessionId() + { + return this.jakarta.getRequestedSessionId(); + } + + @Override + public String getRequestURI() + { + return this.jakarta.getRequestURI(); + } + + @Override + public StringBuffer getRequestURL() + { + return this.jakarta.getRequestURL(); + } + + @Override + public String getServletPath() + { + return this.jakarta.getServletPath(); + } + + @Override + public HttpSession getSession(boolean create) + { + return JakartaServletBridge.toJavax(this.jakarta.getSession(create)); + } + + @Override + public HttpSession getSession() + { + return JakartaServletBridge.toJavax(this.jakarta.getSession()); + } + + @Override + public String changeSessionId() + { + return this.jakarta.changeSessionId(); + } + + @Override + public boolean isRequestedSessionIdValid() + { + return this.jakarta.isRequestedSessionIdValid(); + } + + @Override + public boolean isRequestedSessionIdFromCookie() + { + return this.jakarta.isRequestedSessionIdFromCookie(); + } + + @Override + public boolean isRequestedSessionIdFromURL() + { + return this.jakarta.isRequestedSessionIdFromURL(); + } + + @Override + public boolean isRequestedSessionIdFromUrl() + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.isRequestedSessionIdFromURL(); + } + + @Override + public boolean authenticate(HttpServletResponse response) throws IOException, ServletException + { + try { + return this.jakarta.authenticate(JakartaServletBridge.toJakarta(response)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void login(String username, String password) throws ServletException + { + try { + this.jakarta.login(username, password); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void logout() throws ServletException + { + try { + this.jakarta.logout(); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Collection getParts() throws IOException, ServletException + { + try { + return JakartaServletBridge.toJavax(this.jakarta.getParts()); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Part getPart(String name) throws IOException, ServletException + { + try { + return JakartaServletBridge.toJavax(this.jakarta.getPart(name)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public T upgrade(Class handlerClass) throws IOException, ServletException + { + // TODO + throw new UnsupportedOperationException(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletRequestWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletRequestWrapper.java new file mode 100644 index 0000000000..fc901804d4 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletRequestWrapper.java @@ -0,0 +1,520 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.Principal; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.AsyncContext; +import javax.servlet.DispatcherType; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpUpgradeHandler; +import javax.servlet.http.Part; + +import org.xwiki.jakartabridge.JavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the type of http servlet request + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaHttpServletRequestWrapper + extends HttpServletRequestWrapper implements JavaxToJakartaWrapper +{ + protected final R jakarta; + + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaHttpServletRequestWrapper(R jakarta) + { + // Make sure that HttpServletRequestWrapper#getRequest returns something accurate + super(JakartaServletBridge.toJavax((jakarta.servlet.http.HttpServletRequest) jakarta.getRequest())); + + this.jakarta = jakarta; + } + + // JavaxToJakartaWrapper + + /** + * @return the jakarta version + */ + public R getJakarta() + { + return this.jakarta; + } + + // HttpServletRequest + + @Override + public Object getAttribute(String name) + { + return this.jakarta.getAttribute(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.jakarta.getAttributeNames(); + } + + @Override + public String getCharacterEncoding() + { + return this.jakarta.getCharacterEncoding(); + } + + @Override + public void setCharacterEncoding(String env) throws UnsupportedEncodingException + { + this.jakarta.setCharacterEncoding(env); + } + + @Override + public int getContentLength() + { + return this.jakarta.getContentLength(); + } + + @Override + public long getContentLengthLong() + { + return this.jakarta.getContentLengthLong(); + } + + @Override + public String getContentType() + { + return this.jakarta.getContentType(); + } + + @Override + public ServletInputStream getInputStream() throws IOException + { + return JakartaServletBridge.toJavax(this.jakarta.getInputStream()); + } + + @Override + public String getParameter(String name) + { + return this.jakarta.getParameter(name); + } + + @Override + public Enumeration getParameterNames() + { + return this.jakarta.getParameterNames(); + } + + @Override + public String[] getParameterValues(String name) + { + return this.jakarta.getParameterValues(name); + } + + @Override + public Map getParameterMap() + { + return this.jakarta.getParameterMap(); + } + + @Override + public String getProtocol() + { + return this.jakarta.getProtocol(); + } + + @Override + public String getScheme() + { + return this.jakarta.getScheme(); + } + + @Override + public String getServerName() + { + return this.jakarta.getServerName(); + } + + @Override + public int getServerPort() + { + return this.jakarta.getServerPort(); + } + + @Override + public BufferedReader getReader() throws IOException + { + return this.jakarta.getReader(); + } + + @Override + public String getRemoteAddr() + { + return this.jakarta.getRemoteAddr(); + } + + @Override + public String getRemoteHost() + { + return this.jakarta.getRemoteHost(); + } + + @Override + public void setAttribute(String name, Object o) + { + this.jakarta.setAttribute(name, o); + } + + @Override + public void removeAttribute(String name) + { + this.jakarta.removeAttribute(name); + } + + @Override + public Locale getLocale() + { + return this.jakarta.getLocale(); + } + + @Override + public Enumeration getLocales() + { + return this.jakarta.getLocales(); + } + + @Override + public boolean isSecure() + { + return this.jakarta.isSecure(); + } + + @Override + public RequestDispatcher getRequestDispatcher(String path) + { + return JakartaServletBridge.toJavax(this.jakarta.getRequestDispatcher(path)); + } + + @Override + public String getRealPath(String path) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.getServletContext().getRealPath(path); + } + + @Override + public int getRemotePort() + { + return this.jakarta.getRemotePort(); + } + + @Override + public String getLocalName() + { + return this.jakarta.getLocalName(); + } + + @Override + public String getLocalAddr() + { + return this.jakarta.getLocalAddr(); + } + + @Override + public int getLocalPort() + { + return this.jakarta.getLocalPort(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJavax(this.jakarta.getServletContext()); + } + + @Override + public AsyncContext startAsync() throws IllegalStateException + { + return JakartaServletBridge.toJavax(this.jakarta.startAsync()); + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) + throws IllegalStateException + { + return JakartaServletBridge.toJavax(this.jakarta.startAsync(JakartaServletBridge.toJakarta(servletRequest), + JakartaServletBridge.toJakarta(servletResponse))); + } + + @Override + public boolean isAsyncStarted() + { + return this.jakarta.isAsyncStarted(); + } + + @Override + public boolean isAsyncSupported() + { + return this.jakarta.isAsyncSupported(); + } + + @Override + public AsyncContext getAsyncContext() + { + return JakartaServletBridge.toJavax(this.jakarta.getAsyncContext()); + } + + @Override + public DispatcherType getDispatcherType() + { + return JakartaServletBridge.toJavax(this.jakarta.getDispatcherType()); + } + + @Override + public String getAuthType() + { + return this.jakarta.getAuthType(); + } + + @Override + public Cookie[] getCookies() + { + return JakartaServletBridge.toJavax(this.jakarta.getCookies()); + } + + @Override + public long getDateHeader(String name) + { + return this.jakarta.getDateHeader(name); + } + + @Override + public String getHeader(String name) + { + return this.jakarta.getHeader(name); + } + + @Override + public Enumeration getHeaders(String name) + { + return this.jakarta.getHeaders(name); + } + + @Override + public Enumeration getHeaderNames() + { + return this.jakarta.getHeaderNames(); + } + + @Override + public int getIntHeader(String name) + { + return this.jakarta.getIntHeader(name); + } + + @Override + public String getMethod() + { + return this.jakarta.getMethod(); + } + + @Override + public String getPathInfo() + { + return this.jakarta.getPathInfo(); + } + + @Override + public String getPathTranslated() + { + return this.jakarta.getPathTranslated(); + } + + @Override + public String getContextPath() + { + return this.jakarta.getContextPath(); + } + + @Override + public String getQueryString() + { + return this.jakarta.getQueryString(); + } + + @Override + public String getRemoteUser() + { + return this.jakarta.getRemoteUser(); + } + + @Override + public boolean isUserInRole(String role) + { + return this.jakarta.isUserInRole(role); + } + + @Override + public Principal getUserPrincipal() + { + return this.jakarta.getUserPrincipal(); + } + + @Override + public String getRequestedSessionId() + { + return this.jakarta.getRequestedSessionId(); + } + + @Override + public String getRequestURI() + { + return this.jakarta.getRequestURI(); + } + + @Override + public StringBuffer getRequestURL() + { + return this.jakarta.getRequestURL(); + } + + @Override + public String getServletPath() + { + return this.jakarta.getServletPath(); + } + + @Override + public HttpSession getSession(boolean create) + { + return JakartaServletBridge.toJavax(this.jakarta.getSession(create)); + } + + @Override + public HttpSession getSession() + { + return JakartaServletBridge.toJavax(this.jakarta.getSession()); + } + + @Override + public String changeSessionId() + { + return this.jakarta.changeSessionId(); + } + + @Override + public boolean isRequestedSessionIdValid() + { + return this.jakarta.isRequestedSessionIdValid(); + } + + @Override + public boolean isRequestedSessionIdFromCookie() + { + return this.jakarta.isRequestedSessionIdFromCookie(); + } + + @Override + public boolean isRequestedSessionIdFromURL() + { + return this.jakarta.isRequestedSessionIdFromURL(); + } + + @Override + public boolean isRequestedSessionIdFromUrl() + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.isRequestedSessionIdFromURL(); + } + + @Override + public boolean authenticate(HttpServletResponse response) throws IOException, ServletException + { + try { + return this.jakarta.authenticate(JakartaServletBridge.toJakarta(response)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void login(String username, String password) throws ServletException + { + try { + this.jakarta.login(username, password); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void logout() throws ServletException + { + try { + this.jakarta.logout(); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Collection getParts() throws IOException, ServletException + { + try { + return JakartaServletBridge.toJavax(this.jakarta.getParts()); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Part getPart(String name) throws IOException, ServletException + { + try { + return JakartaServletBridge.toJavax(this.jakarta.getPart(name)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public T upgrade(Class handlerClass) throws IOException, ServletException + { + // TODO + throw new UnsupportedOperationException(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletResponse.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletResponse.java new file mode 100644 index 0000000000..ddfa5bcf72 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletResponse.java @@ -0,0 +1,174 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.util.Collection; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletResponse; + +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the type of http servlet response + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaHttpServletResponse + extends JavaxToJakartaServletResponse implements HttpServletResponse +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaHttpServletResponse(R jakarta) + { + super(jakarta); + } + + @Override + public void addCookie(Cookie cookie) + { + this.jakarta.addCookie(JakartaServletBridge.toJakarta(cookie)); + } + + @Override + public boolean containsHeader(String name) + { + return this.jakarta.containsHeader(name); + } + + @Override + public String encodeURL(String url) + { + return this.jakarta.encodeURL(url); + } + + @Override + public String encodeRedirectURL(String url) + { + return this.jakarta.encodeRedirectURL(url); + } + + @Override + public String encodeUrl(String url) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.encodeURL(url); + } + + @Override + public String encodeRedirectUrl(String url) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.encodeRedirectURL(url); + } + + @Override + public void sendError(int sc, String msg) throws IOException + { + this.jakarta.sendError(sc, msg); + } + + @Override + public void sendError(int sc) throws IOException + { + this.jakarta.sendError(sc); + } + + @Override + public void sendRedirect(String location) throws IOException + { + this.jakarta.sendRedirect(location); + } + + @Override + public void setDateHeader(String name, long date) + { + this.jakarta.setDateHeader(name, date); + } + + @Override + public void addDateHeader(String name, long date) + { + this.jakarta.addDateHeader(name, date); + } + + @Override + public void setHeader(String name, String value) + { + this.jakarta.setHeader(name, value); + } + + @Override + public void addHeader(String name, String value) + { + this.jakarta.addHeader(name, value); + } + + @Override + public void setIntHeader(String name, int value) + { + this.jakarta.setIntHeader(name, value); + } + + @Override + public void addIntHeader(String name, int value) + { + this.jakarta.addIntHeader(name, value); + } + + @Override + public void setStatus(int sc) + { + this.jakarta.setStatus(sc); + } + + @Override + public void setStatus(int sc, String sm) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + this.jakarta.setStatus(sc); + } + + @Override + public int getStatus() + { + return this.jakarta.getStatus(); + } + + @Override + public String getHeader(String name) + { + return this.jakarta.getHeader(name); + } + + @Override + public Collection getHeaders(String name) + { + return this.jakarta.getHeaders(name); + } + + @Override + public Collection getHeaderNames() + { + return this.jakarta.getHeaderNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletResponseWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletResponseWrapper.java new file mode 100644 index 0000000000..41d79ea1dd --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpServletResponseWrapper.java @@ -0,0 +1,291 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Collection; +import java.util.Locale; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletResponseWrapper; + +import org.xwiki.jakartabridge.JavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the type of http servlet response + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaHttpServletResponseWrapper + extends HttpServletResponseWrapper implements JavaxToJakartaWrapper +{ + protected final R jakarta; + + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaHttpServletResponseWrapper(R jakarta) + { + // Make sure that HttpServletRequestWrapper#getResponse returns something accurate + super(JakartaServletBridge.toJavax((jakarta.servlet.http.HttpServletResponse) jakarta.getResponse())); + + this.jakarta = jakarta; + } + + // JavaxToJakartaWrapper + + /** + * @return the jakarta version + */ + public R getJakarta() + { + return this.jakarta; + } + + // HttpServletResponse + + @Override + public String getCharacterEncoding() + { + return this.jakarta.getCharacterEncoding(); + } + + @Override + public String getContentType() + { + return this.jakarta.getContentType(); + } + + @Override + public ServletOutputStream getOutputStream() throws IOException + { + return JakartaServletBridge.toJavax(this.jakarta.getOutputStream()); + } + + @Override + public PrintWriter getWriter() throws IOException + { + return this.jakarta.getWriter(); + } + + @Override + public void setCharacterEncoding(String charset) + { + this.jakarta.setCharacterEncoding(charset); + } + + @Override + public void setContentLength(int len) + { + this.jakarta.setContentLength(len); + } + + @Override + public void setContentLengthLong(long len) + { + this.jakarta.setContentLengthLong(len); + } + + @Override + public void setContentType(String type) + { + this.jakarta.setContentType(type); + } + + @Override + public void setBufferSize(int size) + { + this.jakarta.setBufferSize(size); + } + + @Override + public int getBufferSize() + { + return this.jakarta.getBufferSize(); + } + + @Override + public void flushBuffer() throws IOException + { + this.jakarta.flushBuffer(); + } + + @Override + public void resetBuffer() + { + this.jakarta.resetBuffer(); + } + + @Override + public boolean isCommitted() + { + return this.jakarta.isCommitted(); + } + + @Override + public void reset() + { + this.jakarta.reset(); + } + + @Override + public void setLocale(Locale loc) + { + this.jakarta.setLocale(loc); + } + + @Override + public Locale getLocale() + { + return this.jakarta.getLocale(); + } + + @Override + public void addCookie(Cookie cookie) + { + this.jakarta.addCookie(JakartaServletBridge.toJakarta(cookie)); + } + + @Override + public boolean containsHeader(String name) + { + return this.jakarta.containsHeader(name); + } + + @Override + public String encodeURL(String url) + { + return this.jakarta.encodeURL(url); + } + + @Override + public String encodeRedirectURL(String url) + { + return this.jakarta.encodeRedirectURL(url); + } + + @Override + public String encodeUrl(String url) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.encodeURL(url); + } + + @Override + public String encodeRedirectUrl(String url) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.encodeRedirectURL(url); + } + + @Override + public void sendError(int sc, String msg) throws IOException + { + this.jakarta.sendError(sc, msg); + } + + @Override + public void sendError(int sc) throws IOException + { + this.jakarta.sendError(sc); + } + + @Override + public void sendRedirect(String location) throws IOException + { + this.jakarta.sendRedirect(location); + } + + @Override + public void setDateHeader(String name, long date) + { + this.jakarta.setDateHeader(name, date); + } + + @Override + public void addDateHeader(String name, long date) + { + this.jakarta.addDateHeader(name, date); + } + + @Override + public void setHeader(String name, String value) + { + this.jakarta.setHeader(name, value); + } + + @Override + public void addHeader(String name, String value) + { + this.jakarta.addHeader(name, value); + } + + @Override + public void setIntHeader(String name, int value) + { + this.jakarta.setIntHeader(name, value); + } + + @Override + public void addIntHeader(String name, int value) + { + this.jakarta.addIntHeader(name, value); + } + + @Override + public void setStatus(int sc) + { + this.jakarta.setStatus(sc); + } + + @Override + public void setStatus(int sc, String sm) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + this.jakarta.setStatus(sc); + } + + @Override + public int getStatus() + { + return this.jakarta.getStatus(); + } + + @Override + public String getHeader(String name) + { + return this.jakarta.getHeader(name); + } + + @Override + public Collection getHeaders(String name) + { + return this.jakarta.getHeaders(name); + } + + @Override + public Collection getHeaderNames() + { + return this.jakarta.getHeaderNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpSession.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpSession.java new file mode 100644 index 0000000000..83780f31c9 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpSession.java @@ -0,0 +1,156 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Collections; +import java.util.Enumeration; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionContext; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaHttpSession extends AbstractJavaxToJakartaWrapper + implements HttpSession +{ + private static final String[] EMPTY_ARRAY = new String[0]; + + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaHttpSession(jakarta.servlet.http.HttpSession jakarta) + { + super(jakarta); + } + + @Override + public long getCreationTime() + { + return this.jakarta.getCreationTime(); + } + + @Override + public String getId() + { + return this.jakarta.getId(); + } + + @Override + public long getLastAccessedTime() + { + return this.jakarta.getLastAccessedTime(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJavax(this.jakarta.getServletContext()); + } + + @Override + public void setMaxInactiveInterval(int interval) + { + this.jakarta.setMaxInactiveInterval(interval); + } + + @Override + public int getMaxInactiveInterval() + { + return this.jakarta.getMaxInactiveInterval(); + } + + @Override + public HttpSessionContext getSessionContext() + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return EmptyJakartaHttpSessionContext.EMPTY; + } + + @Override + public Object getAttribute(String name) + { + return this.jakarta.getAttribute(name); + } + + @Override + public Object getValue(String name) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.getAttribute(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.jakarta.getAttributeNames(); + } + + @Override + public String[] getValueNames() + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return Collections.list(this.jakarta.getAttributeNames()).toArray(EMPTY_ARRAY); + } + + @Override + public void setAttribute(String name, Object value) + { + this.jakarta.setAttribute(name, value); + } + + @Override + public void putValue(String name, Object value) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + this.jakarta.setAttribute(name, value); + } + + @Override + public void removeAttribute(String name) + { + this.jakarta.removeAttribute(name); + } + + @Override + public void removeValue(String name) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + this.jakarta.removeAttribute(name); + } + + @Override + public void invalidate() + { + this.jakarta.invalidate(); + } + + @Override + public boolean isNew() + { + return this.jakarta.isNew(); + } + +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpSessionContext.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpSessionContext.java new file mode 100644 index 0000000000..438ab1e710 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaHttpSessionContext.java @@ -0,0 +1,57 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Enumeration; + +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionContext; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaHttpSessionContext + extends AbstractJavaxToJakartaWrapper implements HttpSessionContext +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaHttpSessionContext(jakarta.servlet.http.HttpSessionContext jakarta) + { + super(jakarta); + } + + @Override + public HttpSession getSession(String sessionId) + { + return JakartaServletBridge.toJavax(this.jakarta.getSession(sessionId)); + } + + @Override + public Enumeration getIds() + { + return this.jakarta.getIds(); + } + +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaPart.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaPart.java new file mode 100644 index 0000000000..995a670cda --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaPart.java @@ -0,0 +1,103 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; + +import javax.servlet.http.Part; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaPart extends AbstractJavaxToJakartaWrapper implements Part +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaPart(jakarta.servlet.http.Part jakarta) + { + super(jakarta); + } + + @Override + public InputStream getInputStream() throws IOException + { + return this.jakarta.getInputStream(); + } + + @Override + public String getContentType() + { + return this.jakarta.getContentType(); + } + + @Override + public String getName() + { + return this.jakarta.getName(); + } + + @Override + public String getSubmittedFileName() + { + return this.jakarta.getSubmittedFileName(); + } + + @Override + public long getSize() + { + return this.jakarta.getSize(); + } + + @Override + public void write(String fileName) throws IOException + { + this.jakarta.write(fileName); + } + + @Override + public void delete() throws IOException + { + this.jakarta.delete(); + } + + @Override + public String getHeader(String name) + { + return this.jakarta.getHeader(name); + } + + @Override + public Collection getHeaders(String name) + { + return this.jakarta.getHeaders(name); + } + + @Override + public Collection getHeaderNames() + { + return this.jakarta.getHeaderNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaReadListener.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaReadListener.java new file mode 100644 index 0000000000..47af21a7d6 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaReadListener.java @@ -0,0 +1,60 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import javax.servlet.ReadListener; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaReadListener extends AbstractJavaxToJakartaWrapper + implements ReadListener +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaReadListener(jakarta.servlet.ReadListener jakarta) + { + super(jakarta); + } + + @Override + public void onDataAvailable() throws IOException + { + this.jakarta.onDataAvailable(); + } + + @Override + public void onAllDataRead() throws IOException + { + this.jakarta.onAllDataRead(); + } + + @Override + public void onError(Throwable t) + { + this.jakarta.onError(t); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaRequestDispatcher.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaRequestDispatcher.java new file mode 100644 index 0000000000..9086b1499a --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaRequestDispatcher.java @@ -0,0 +1,74 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaRequestDispatcher extends AbstractJavaxToJakartaWrapper + implements RequestDispatcher +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaRequestDispatcher(jakarta.servlet.RequestDispatcher jakarta) + { + super(jakarta); + } + + /** + * @return the wrapped version + */ + public jakarta.servlet.RequestDispatcher getJakarta() + { + return this.jakarta; + } + + @Override + public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException + { + try { + this.jakarta.forward(JakartaServletBridge.toJakarta(request), JakartaServletBridge.toJakarta(response)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException + { + try { + this.jakarta.include(JakartaServletBridge.toJakarta(request), JakartaServletBridge.toJakarta(response)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServlet.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServlet.java new file mode 100644 index 0000000000..1fa9cb960d --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServlet.java @@ -0,0 +1,84 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServlet extends AbstractJavaxToJakartaWrapper implements Servlet +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServlet(jakarta.servlet.Servlet jakarta) + { + super(jakarta); + } + + @Override + public void init(ServletConfig config) throws ServletException + { + try { + this.jakarta.init(JakartaServletBridge.toJakarta(config)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public ServletConfig getServletConfig() + { + return new JavaxToJakartaServletConfig(this.jakarta.getServletConfig()); + } + + @Override + public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException + { + try { + this.jakarta.service(JakartaServletBridge.toJakarta(req), JakartaServletBridge.toJakarta(res)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public String getServletInfo() + { + return this.jakarta.getServletInfo(); + } + + @Override + public void destroy() + { + this.jakarta.destroy(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletConfig.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletConfig.java new file mode 100644 index 0000000000..fb7e7fa6f9 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletConfig.java @@ -0,0 +1,68 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Enumeration; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServletConfig extends AbstractJavaxToJakartaWrapper + implements ServletConfig +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServletConfig(jakarta.servlet.ServletConfig jakarta) + { + super(jakarta); + } + + @Override + public String getServletName() + { + return this.jakarta.getServletName(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJavax(this.jakarta.getServletContext()); + } + + @Override + public String getInitParameter(String name) + { + return this.jakarta.getInitParameter(name); + } + + @Override + public Enumeration getInitParameterNames() + { + return this.jakarta.getInitParameterNames(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletContext.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletContext.java new file mode 100644 index 0000000000..9132735df4 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletContext.java @@ -0,0 +1,386 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Enumeration; +import java.util.EventListener; +import java.util.Map; +import java.util.Set; + +import javax.servlet.Filter; +import javax.servlet.FilterRegistration; +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; +import javax.servlet.ServletRegistration.Dynamic; +import javax.servlet.SessionCookieConfig; +import javax.servlet.SessionTrackingMode; +import javax.servlet.descriptor.JspConfigDescriptor; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServletContext extends AbstractJavaxToJakartaWrapper + implements ServletContext +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServletContext(jakarta.servlet.ServletContext jakarta) + { + super(jakarta); + } + + @Override + public String getContextPath() + { + return this.jakarta.getContextPath(); + } + + @Override + public ServletContext getContext(String uripath) + { + return JakartaServletBridge.toJavax(this.jakarta.getContext(uripath)); + } + + @Override + public int getMajorVersion() + { + return this.jakarta.getMajorVersion(); + } + + @Override + public int getMinorVersion() + { + return this.jakarta.getMinorVersion(); + } + + @Override + public int getEffectiveMajorVersion() + { + return this.jakarta.getEffectiveMajorVersion(); + } + + @Override + public int getEffectiveMinorVersion() + { + return this.jakarta.getEffectiveMinorVersion(); + } + + @Override + public String getMimeType(String file) + { + return this.jakarta.getMimeType(file); + } + + @Override + public Set getResourcePaths(String path) + { + return this.jakarta.getResourcePaths(path); + } + + @Override + public URL getResource(String path) throws MalformedURLException + { + return this.jakarta.getResource(path); + } + + @Override + public InputStream getResourceAsStream(String path) + { + return this.jakarta.getResourceAsStream(path); + } + + @Override + public RequestDispatcher getRequestDispatcher(String path) + { + return JakartaServletBridge.toJavax(this.jakarta.getRequestDispatcher(path)); + } + + @Override + public RequestDispatcher getNamedDispatcher(String name) + { + return new JavaxToJakartaRequestDispatcher(this.jakarta.getNamedDispatcher(name)); + } + + @Override + public Servlet getServlet(String name) throws ServletException + { + try { + return JakartaServletBridge.toJavax(this.jakarta.getServlet(name)); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public Enumeration getServlets() + { + return JakartaServletBridge.toJavax(this.jakarta.getServlets()); + } + + @Override + public Enumeration getServletNames() + { + return this.jakarta.getServletNames(); + } + + @Override + public void log(String msg) + { + this.jakarta.log(msg); + } + + @Override + public void log(Exception exception, String msg) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + this.jakarta.log(msg, exception); + } + + @Override + public void log(String message, Throwable throwable) + { + this.jakarta.log(message, throwable); + } + + @Override + public String getRealPath(String path) + { + return this.jakarta.getRealPath(path); + } + + @Override + public String getServerInfo() + { + return this.jakarta.getServerInfo(); + } + + @Override + public String getInitParameter(String name) + { + return this.jakarta.getInitParameter(name); + } + + @Override + public Enumeration getInitParameterNames() + { + return this.jakarta.getInitParameterNames(); + } + + @Override + public boolean setInitParameter(String name, String value) + { + return this.jakarta.setInitParameter(name, value); + } + + @Override + public Object getAttribute(String name) + { + return this.jakarta.getAttribute(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.jakarta.getAttributeNames(); + } + + @Override + public void setAttribute(String name, Object object) + { + this.jakarta.setAttribute(name, object); + } + + @Override + public void removeAttribute(String name) + { + this.jakarta.removeAttribute(name); + } + + @Override + public String getServletContextName() + { + return this.jakarta.getServletContextName(); + } + + @Override + public Dynamic addServlet(String servletName, String className) + { + return JakartaServletBridge.toJavax(this.jakarta.addServlet(servletName, className)); + } + + @Override + public Dynamic addServlet(String servletName, Servlet servlet) + { + return JakartaServletBridge.toJavax(this.jakarta.addServlet(servletName, JakartaServletBridge.toJakarta(servlet))); + } + + @Override + public Dynamic addServlet(String servletName, Class servletClass) + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public T createServlet(Class clazz) throws ServletException + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public ServletRegistration getServletRegistration(String servletName) + { + return JakartaServletBridge.toJavax(this.jakarta.getServletRegistration(servletName)); + } + + @Override + public Map getServletRegistrations() + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public FilterRegistration.Dynamic addFilter(String filterName, String className) + { + return JakartaServletBridge.toJavax(this.jakarta.addFilter(filterName, className)); + } + + @Override + public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) + { + return JakartaServletBridge.toJavax(this.jakarta.addFilter(filterName, JakartaServletBridge.toJakarta(filter))); + } + + @Override + public FilterRegistration.Dynamic addFilter(String filterName, Class filterClass) + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public T createFilter(Class clazz) throws ServletException + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public FilterRegistration getFilterRegistration(String filterName) + { + return JakartaServletBridge.toJavax(this.jakarta.getFilterRegistration(filterName)); + } + + @Override + public Map getFilterRegistrations() + { + // TODO + throw new UnsupportedOperationException(); + } + + @Override + public SessionCookieConfig getSessionCookieConfig() + { + return JakartaServletBridge.toJavax(this.jakarta.getSessionCookieConfig()); + } + + @Override + public void setSessionTrackingModes(Set sessionTrackingModes) + { + this.jakarta.setSessionTrackingModes(JakartaServletBridge.toJakarta(sessionTrackingModes)); + } + + @Override + public Set getDefaultSessionTrackingModes() + { + return JakartaServletBridge.toJavax(this.jakarta.getDefaultSessionTrackingModes()); + } + + @Override + public Set getEffectiveSessionTrackingModes() + { + return JakartaServletBridge.toJavax(this.jakarta.getEffectiveSessionTrackingModes()); + } + + @Override + public void addListener(String className) + { + this.jakarta.addListener(className); + } + + @Override + public void addListener(T t) + { + this.jakarta.addListener(t); + } + + @Override + public void addListener(Class listenerClass) + { + this.jakarta.addListener(listenerClass); + } + + @Override + public T createListener(Class clazz) throws ServletException + { + try { + return this.jakarta.createListener(clazz); + } catch (jakarta.servlet.ServletException e) { + throw new ServletException(e.getMessage(), e); + } + } + + @Override + public JspConfigDescriptor getJspConfigDescriptor() + { + return JakartaServletBridge.toJavax(this.jakarta.getJspConfigDescriptor()); + } + + @Override + public ClassLoader getClassLoader() + { + return this.jakarta.getClassLoader(); + } + + @Override + public void declareRoles(String... roleNames) + { + this.jakarta.declareRoles(roleNames); + } + + @Override + public String getVirtualServerName() + { + return this.jakarta.getVirtualServerName(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletInputStream.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletInputStream.java new file mode 100644 index 0000000000..bfe13708b0 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletInputStream.java @@ -0,0 +1,82 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; + +import org.xwiki.jakartabridge.JavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServletInputStream extends ServletInputStream + implements JavaxToJakartaWrapper +{ + private final jakarta.servlet.ServletInputStream jakarta; + + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServletInputStream(jakarta.servlet.ServletInputStream jakarta) + { + this.jakarta = jakarta; + } + + @Override + public jakarta.servlet.ServletInputStream getJakarta() + { + return this.jakarta; + } + + @Override + public boolean isFinished() + { + return this.jakarta.isFinished(); + } + + @Override + public boolean isReady() + { + return this.jakarta.isReady(); + } + + @Override + public void setReadListener(ReadListener readListener) + { + this.jakarta.setReadListener(JakartaServletBridge.toJakarta(readListener)); + } + + @Override + public int read() throws IOException + { + return this.jakarta.read(); + } + + @Override + public int readLine(byte[] b, int off, int len) throws IOException + { + return this.jakarta.readLine(b, off, len); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletOutputStream.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletOutputStream.java new file mode 100644 index 0000000000..a2860236bf --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletOutputStream.java @@ -0,0 +1,165 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import javax.servlet.ServletOutputStream; +import javax.servlet.WriteListener; + +import org.xwiki.jakartabridge.JavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServletOutputStream extends ServletOutputStream + implements JavaxToJakartaWrapper +{ + private final jakarta.servlet.ServletOutputStream jakarta; + + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServletOutputStream(jakarta.servlet.ServletOutputStream jakarta) + { + this.jakarta = jakarta; + } + + @Override + public jakarta.servlet.ServletOutputStream getJakarta() + { + return this.jakarta; + } + + @Override + public boolean isReady() + { + return this.jakarta.isReady(); + } + + @Override + public void setWriteListener(WriteListener writeListener) + { + this.jakarta.setWriteListener(JakartaServletBridge.toJakarta(writeListener)); + } + + @Override + public void write(int b) throws IOException + { + this.jakarta.write(b); + } + + @Override + public void print(String s) throws IOException + { + this.jakarta.print(s); + } + + @Override + + public void print(boolean b) throws IOException + { + this.jakarta.print(b); + } + + @Override + public void print(char c) throws IOException + { + this.jakarta.print(c); + } + + @Override + + public void print(int i) throws IOException + { + this.jakarta.print(i); + } + + @Override + public void print(long l) throws IOException + { + this.jakarta.print(l); + } + + @Override + public void print(float f) throws IOException + { + this.jakarta.print(f); + } + + @Override + + public void print(double d) throws IOException + { + this.jakarta.print(d); + } + + @Override + public void println() throws IOException + { + this.jakarta.println(); + } + + @Override + public void println(String s) throws IOException + { + this.jakarta.println(s); + } + + @Override + public void println(boolean b) throws IOException + { + this.jakarta.println(b); + } + + @Override + public void println(char c) throws IOException + { + this.jakarta.println(c); + } + + @Override + + public void println(int i) throws IOException + { + this.jakarta.println(i); + } + + @Override + + public void println(long l) throws IOException + { + this.jakarta.println(l); + } + + @Override + public void println(float f) throws IOException + { + this.jakarta.println(f); + } + + @Override + public void println(double d) throws IOException + { + this.jakarta.println(d); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletRegistration.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletRegistration.java new file mode 100644 index 0000000000..23c4f9539b --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletRegistration.java @@ -0,0 +1,147 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import javax.servlet.MultipartConfigElement; +import javax.servlet.ServletRegistration; +import javax.servlet.ServletSecurityElement; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the exact type of jakarta.servlet.ServletRegistration + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServletRegistration + extends AbstractJavaxToJakartaWrapper implements ServletRegistration +{ + /** + * @version $Id$ + */ + public static class Dynamic extends JavaxToJakartaServletRegistration + implements ServletRegistration.Dynamic + { + /** + * @param jakarta + */ + public Dynamic(jakarta.servlet.ServletRegistration.Dynamic jakarta) + { + super(jakarta); + } + + @Override + public void setLoadOnStartup(int loadOnStartup) + { + this.jakarta.setLoadOnStartup(loadOnStartup); + } + + @Override + public Set setServletSecurity(ServletSecurityElement constraint) + { + return this.jakarta.setServletSecurity(JakartaServletBridge.toJakarta(constraint)); + } + + @Override + public void setMultipartConfig(MultipartConfigElement multipartConfig) + { + this.jakarta.setMultipartConfig(JakartaServletBridge.toJakarta(multipartConfig)); + } + + @Override + public void setRunAsRole(String roleName) + { + this.jakarta.setRunAsRole(roleName); + } + + @Override + public void setAsyncSupported(boolean isAsyncSupported) + { + this.jakarta.setAsyncSupported(isAsyncSupported); + } + } + + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServletRegistration(T jakarta) + { + super(jakarta); + } + + @Override + public String getName() + { + return this.jakarta.getName(); + } + + @Override + public String getClassName() + { + return this.jakarta.getClassName(); + } + + @Override + public boolean setInitParameter(String name, String value) + { + return this.jakarta.setInitParameter(name, value); + } + + @Override + public String getInitParameter(String name) + { + return this.jakarta.getInitParameter(name); + } + + @Override + public Set setInitParameters(Map initParameters) + { + return this.jakarta.setInitParameters(initParameters); + } + + @Override + public Map getInitParameters() + { + return this.jakarta.getInitParameters(); + } + + @Override + public Set addMapping(String... urlPatterns) + { + return this.jakarta.addMapping(urlPatterns); + } + + @Override + public Collection getMappings() + { + return this.jakarta.getMappings(); + } + + @Override + public String getRunAsRole() + { + return this.jakarta.getRunAsRole(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletRequest.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletRequest.java new file mode 100644 index 0000000000..d205b4e7d1 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletRequest.java @@ -0,0 +1,280 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.AsyncContext; +import javax.servlet.DispatcherType; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the type of servlet request + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServletRequest + extends AbstractJavaxToJakartaWrapper implements ServletRequest +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServletRequest(R jakarta) + { + super(jakarta); + } + + @Override + public Object getAttribute(String name) + { + return this.jakarta.getAttribute(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.jakarta.getAttributeNames(); + } + + @Override + public String getCharacterEncoding() + { + return this.jakarta.getCharacterEncoding(); + } + + @Override + public void setCharacterEncoding(String env) throws UnsupportedEncodingException + { + this.jakarta.setCharacterEncoding(env); + } + + @Override + public int getContentLength() + { + return this.jakarta.getContentLength(); + } + + @Override + public long getContentLengthLong() + { + return this.jakarta.getContentLengthLong(); + } + + @Override + public String getContentType() + { + return this.jakarta.getContentType(); + } + + @Override + public ServletInputStream getInputStream() throws IOException + { + return JakartaServletBridge.toJavax(this.jakarta.getInputStream()); + } + + @Override + public String getParameter(String name) + { + return this.jakarta.getParameter(name); + } + + @Override + public Enumeration getParameterNames() + { + return this.jakarta.getParameterNames(); + } + + @Override + public String[] getParameterValues(String name) + { + return this.jakarta.getParameterValues(name); + } + + @Override + public Map getParameterMap() + { + return this.jakarta.getParameterMap(); + } + + @Override + public String getProtocol() + { + return this.jakarta.getProtocol(); + } + + @Override + public String getScheme() + { + return this.jakarta.getScheme(); + } + + @Override + public String getServerName() + { + return this.jakarta.getServerName(); + } + + @Override + public int getServerPort() + { + return this.jakarta.getServerPort(); + } + + @Override + public BufferedReader getReader() throws IOException + { + return this.jakarta.getReader(); + } + + @Override + public String getRemoteAddr() + { + return this.jakarta.getRemoteAddr(); + } + + @Override + public String getRemoteHost() + { + return this.jakarta.getRemoteHost(); + } + + @Override + public void setAttribute(String name, Object o) + { + this.jakarta.setAttribute(name, o); + } + + @Override + public void removeAttribute(String name) + { + this.jakarta.removeAttribute(name); + } + + @Override + public Locale getLocale() + { + return this.jakarta.getLocale(); + } + + @Override + public Enumeration getLocales() + { + return this.jakarta.getLocales(); + } + + @Override + public boolean isSecure() + { + return this.jakarta.isSecure(); + } + + @Override + public RequestDispatcher getRequestDispatcher(String path) + { + return JakartaServletBridge.toJavax(this.jakarta.getRequestDispatcher(path)); + } + + @Override + public String getRealPath(String path) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.getServletContext().getRealPath(path); + } + + @Override + public int getRemotePort() + { + return this.jakarta.getRemotePort(); + } + + @Override + public String getLocalName() + { + return this.jakarta.getLocalName(); + } + + @Override + public String getLocalAddr() + { + return this.jakarta.getLocalAddr(); + } + + @Override + public int getLocalPort() + { + return this.jakarta.getLocalPort(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJavax(this.jakarta.getServletContext()); + } + + @Override + public AsyncContext startAsync() throws IllegalStateException + { + return JakartaServletBridge.toJavax(this.jakarta.startAsync()); + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) + throws IllegalStateException + { + return JakartaServletBridge.toJavax(this.jakarta.startAsync(JakartaServletBridge.toJakarta(servletRequest), + JakartaServletBridge.toJakarta(servletResponse))); + } + + @Override + public boolean isAsyncStarted() + { + return this.jakarta.isAsyncStarted(); + } + + @Override + public boolean isAsyncSupported() + { + return this.jakarta.isAsyncSupported(); + } + + @Override + public AsyncContext getAsyncContext() + { + return JakartaServletBridge.toJavax(this.jakarta.getAsyncContext()); + } + + @Override + public DispatcherType getDispatcherType() + { + return JakartaServletBridge.toJavax(this.jakarta.getDispatcherType()); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletRequestWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletRequestWrapper.java new file mode 100644 index 0000000000..2d20dcafec --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletRequestWrapper.java @@ -0,0 +1,298 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.AsyncContext; +import javax.servlet.DispatcherType; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletRequestWrapper; +import javax.servlet.ServletResponse; + +import org.xwiki.jakartabridge.JavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the type of http servlet request + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServletRequestWrapper + extends ServletRequestWrapper implements JavaxToJakartaWrapper +{ + protected final R jakarta; + + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServletRequestWrapper(R jakarta) + { + // Make sure that HttpServletRequestWrapper#getRequest returns something accurate + super(JakartaServletBridge.toJavax(jakarta.getRequest())); + + this.jakarta = jakarta; + } + + // JavaxToJakartaWrapper + + /** + * @return the jakarta version + */ + public R getJakarta() + { + return this.jakarta; + } + + // HttpServletRequest + + @Override + public Object getAttribute(String name) + { + return this.jakarta.getAttribute(name); + } + + @Override + public Enumeration getAttributeNames() + { + return this.jakarta.getAttributeNames(); + } + + @Override + public String getCharacterEncoding() + { + return this.jakarta.getCharacterEncoding(); + } + + @Override + public void setCharacterEncoding(String env) throws UnsupportedEncodingException + { + this.jakarta.setCharacterEncoding(env); + } + + @Override + public int getContentLength() + { + return this.jakarta.getContentLength(); + } + + @Override + public long getContentLengthLong() + { + return this.jakarta.getContentLengthLong(); + } + + @Override + public String getContentType() + { + return this.jakarta.getContentType(); + } + + @Override + public ServletInputStream getInputStream() throws IOException + { + return JakartaServletBridge.toJavax(this.jakarta.getInputStream()); + } + + @Override + public String getParameter(String name) + { + return this.jakarta.getParameter(name); + } + + @Override + public Enumeration getParameterNames() + { + return this.jakarta.getParameterNames(); + } + + @Override + public String[] getParameterValues(String name) + { + return this.jakarta.getParameterValues(name); + } + + @Override + public Map getParameterMap() + { + return this.jakarta.getParameterMap(); + } + + @Override + public String getProtocol() + { + return this.jakarta.getProtocol(); + } + + @Override + public String getScheme() + { + return this.jakarta.getScheme(); + } + + @Override + public String getServerName() + { + return this.jakarta.getServerName(); + } + + @Override + public int getServerPort() + { + return this.jakarta.getServerPort(); + } + + @Override + public BufferedReader getReader() throws IOException + { + return this.jakarta.getReader(); + } + + @Override + public String getRemoteAddr() + { + return this.jakarta.getRemoteAddr(); + } + + @Override + public String getRemoteHost() + { + return this.jakarta.getRemoteHost(); + } + + @Override + public void setAttribute(String name, Object o) + { + this.jakarta.setAttribute(name, o); + } + + @Override + public void removeAttribute(String name) + { + this.jakarta.removeAttribute(name); + } + + @Override + public Locale getLocale() + { + return this.jakarta.getLocale(); + } + + @Override + public Enumeration getLocales() + { + return this.jakarta.getLocales(); + } + + @Override + public boolean isSecure() + { + return this.jakarta.isSecure(); + } + + @Override + public RequestDispatcher getRequestDispatcher(String path) + { + return JakartaServletBridge.toJavax(this.jakarta.getRequestDispatcher(path)); + } + + @Override + public String getRealPath(String path) + { + // Since deprecated APIs where removed in Servlet 6, it's safer to use alternatives + return this.jakarta.getServletContext().getRealPath(path); + } + + @Override + public int getRemotePort() + { + return this.jakarta.getRemotePort(); + } + + @Override + public String getLocalName() + { + return this.jakarta.getLocalName(); + } + + @Override + public String getLocalAddr() + { + return this.jakarta.getLocalAddr(); + } + + @Override + public int getLocalPort() + { + return this.jakarta.getLocalPort(); + } + + @Override + public ServletContext getServletContext() + { + return JakartaServletBridge.toJavax(this.jakarta.getServletContext()); + } + + @Override + public AsyncContext startAsync() throws IllegalStateException + { + return JakartaServletBridge.toJavax(this.jakarta.startAsync()); + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) + throws IllegalStateException + { + return JakartaServletBridge.toJavax(this.jakarta.startAsync(JakartaServletBridge.toJakarta(servletRequest), + JakartaServletBridge.toJakarta(servletResponse))); + } + + @Override + public boolean isAsyncStarted() + { + return this.jakarta.isAsyncStarted(); + } + + @Override + public boolean isAsyncSupported() + { + return this.jakarta.isAsyncSupported(); + } + + @Override + public AsyncContext getAsyncContext() + { + return JakartaServletBridge.toJavax(this.jakarta.getAsyncContext()); + } + + @Override + public DispatcherType getDispatcherType() + { + return JakartaServletBridge.toJavax(this.jakarta.getDispatcherType()); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletResponse.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletResponse.java new file mode 100644 index 0000000000..c5d2d9b025 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletResponse.java @@ -0,0 +1,143 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; + +import javax.servlet.ServletOutputStream; +import javax.servlet.ServletResponse; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the type of servlet response + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServletResponse + extends AbstractJavaxToJakartaWrapper implements ServletResponse +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServletResponse(R jakarta) + { + super(jakarta); + } + + @Override + public String getCharacterEncoding() + { + return this.jakarta.getCharacterEncoding(); + } + + @Override + public String getContentType() + { + return this.jakarta.getContentType(); + } + + @Override + public ServletOutputStream getOutputStream() throws IOException + { + return JakartaServletBridge.toJavax(this.jakarta.getOutputStream()); + } + + @Override + public PrintWriter getWriter() throws IOException + { + return this.jakarta.getWriter(); + } + + @Override + public void setCharacterEncoding(String charset) + { + this.jakarta.setCharacterEncoding(charset); + } + + @Override + public void setContentLength(int len) + { + this.jakarta.setContentLength(len); + } + + @Override + public void setContentLengthLong(long len) + { + this.jakarta.setContentLengthLong(len); + } + + @Override + public void setContentType(String type) + { + this.jakarta.setContentType(type); + } + + @Override + public void setBufferSize(int size) + { + this.jakarta.setBufferSize(size); + } + + @Override + public int getBufferSize() + { + return this.jakarta.getBufferSize(); + } + + @Override + public void flushBuffer() throws IOException + { + this.jakarta.flushBuffer(); + } + + @Override + public void resetBuffer() + { + this.jakarta.resetBuffer(); + } + + @Override + public boolean isCommitted() + { + return this.jakarta.isCommitted(); + } + + @Override + public void reset() + { + this.jakarta.reset(); + } + + @Override + public void setLocale(Locale loc) + { + this.jakarta.setLocale(loc); + } + + @Override + public Locale getLocale() + { + return this.jakarta.getLocale(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletResponseWrapper.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletResponseWrapper.java new file mode 100644 index 0000000000..21e0977683 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaServletResponseWrapper.java @@ -0,0 +1,159 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; + +import javax.servlet.ServletOutputStream; +import javax.servlet.ServletResponseWrapper; + +import org.xwiki.jakartabridge.JavaxToJakartaWrapper; +import org.xwiki.jakartabridge.servlet.JakartaServletBridge; + +/** + * @param the type of http servlet response + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaServletResponseWrapper + extends ServletResponseWrapper implements JavaxToJakartaWrapper +{ + protected final R jakarta; + + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaServletResponseWrapper(R jakarta) + { + super(JakartaServletBridge.toJavax(jakarta.getResponse())); + + this.jakarta = jakarta; + } + + // JavaxToJakartaWrapper + + /** + * @return the jakarta version + */ + public R getJakarta() + { + return this.jakarta; + } + + // HttpServletResponse + + @Override + public String getCharacterEncoding() + { + return this.jakarta.getCharacterEncoding(); + } + + @Override + public String getContentType() + { + return this.jakarta.getContentType(); + } + + @Override + public ServletOutputStream getOutputStream() throws IOException + { + return JakartaServletBridge.toJavax(this.jakarta.getOutputStream()); + } + + @Override + public PrintWriter getWriter() throws IOException + { + return this.jakarta.getWriter(); + } + + @Override + public void setCharacterEncoding(String charset) + { + this.jakarta.setCharacterEncoding(charset); + } + + @Override + public void setContentLength(int len) + { + this.jakarta.setContentLength(len); + } + + @Override + public void setContentLengthLong(long len) + { + this.jakarta.setContentLengthLong(len); + } + + @Override + public void setContentType(String type) + { + this.jakarta.setContentType(type); + } + + @Override + public void setBufferSize(int size) + { + this.jakarta.setBufferSize(size); + } + + @Override + public int getBufferSize() + { + return this.jakarta.getBufferSize(); + } + + @Override + public void flushBuffer() throws IOException + { + this.jakarta.flushBuffer(); + } + + @Override + public void resetBuffer() + { + this.jakarta.resetBuffer(); + } + + @Override + public boolean isCommitted() + { + return this.jakarta.isCommitted(); + } + + @Override + public void reset() + { + this.jakarta.reset(); + } + + @Override + public void setLocale(Locale loc) + { + this.jakarta.setLocale(loc); + } + + @Override + public Locale getLocale() + { + return this.jakarta.getLocale(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaSessionCookieConfig.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaSessionCookieConfig.java new file mode 100644 index 0000000000..eadb83ad61 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaSessionCookieConfig.java @@ -0,0 +1,124 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import javax.servlet.SessionCookieConfig; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaSessionCookieConfig + extends AbstractJavaxToJakartaWrapper implements SessionCookieConfig +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaSessionCookieConfig(jakarta.servlet.SessionCookieConfig jakarta) + { + super(jakarta); + } + + @Override + public void setName(String name) + { + this.jakarta.setName(name); + } + + @Override + public String getName() + { + return this.jakarta.getName(); + } + + @Override + public void setDomain(String domain) + { + this.jakarta.setDomain(domain); + } + + @Override + public String getDomain() + { + return this.jakarta.getDomain(); + } + + @Override + public void setPath(String path) + { + this.jakarta.setPath(path); + } + + @Override + public String getPath() + { + return this.jakarta.getPath(); + } + + @Override + public void setComment(String comment) + { + this.jakarta.setComment(comment); + } + + @Override + public String getComment() + { + return this.jakarta.getComment(); + } + + @Override + public void setHttpOnly(boolean httpOnly) + { + this.jakarta.setHttpOnly(httpOnly); + } + + @Override + public boolean isHttpOnly() + { + return this.jakarta.isHttpOnly(); + } + + @Override + public void setSecure(boolean secure) + { + this.jakarta.setSecure(secure); + } + + @Override + public boolean isSecure() + { + return this.jakarta.isSecure(); + } + + @Override + public void setMaxAge(int maxAge) + { + this.jakarta.setMaxAge(maxAge); + } + + @Override + public int getMaxAge() + { + return this.jakarta.getMaxAge(); + } +} diff --git a/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaWriteListener.java b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaWriteListener.java new file mode 100644 index 0000000000..94918c93c1 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-jakartabridge/xwiki-commons-jakartabridge-servlet/src/main/java/org/xwiki/jakartabridge/servlet/internal/JavaxToJakartaWriteListener.java @@ -0,0 +1,54 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.jakartabridge.servlet.internal; + +import java.io.IOException; + +import javax.servlet.WriteListener; + +import org.xwiki.jakartabridge.internal.AbstractJavaxToJakartaWrapper; + +/** + * @version $Id$ + * @since 42.0.0 + */ +public class JavaxToJakartaWriteListener extends AbstractJavaxToJakartaWrapper + implements WriteListener +{ + /** + * @param jakarta the wrapped version + */ + public JavaxToJakartaWriteListener(jakarta.servlet.WriteListener jakarta) + { + super(jakarta); + } + + @Override + public void onWritePossible() throws IOException + { + this.jakarta.onWritePossible(); + } + + @Override + public void onError(Throwable t) + { + this.jakarta.onError(t); + } +} diff --git a/xwiki-commons-core/xwiki-commons-legacy/xwiki-commons-legacy-component/xwiki-commons-legacy-component-default/src/main/java/org/xwiki/component/embed/GenericProvider.java b/xwiki-commons-core/xwiki-commons-legacy/xwiki-commons-legacy-component/xwiki-commons-legacy-component-default/src/main/java/org/xwiki/component/embed/GenericProvider.java new file mode 100644 index 0000000000..b35c7edc09 --- /dev/null +++ b/xwiki-commons-core/xwiki-commons-legacy/xwiki-commons-legacy-component/xwiki-commons-legacy-component-default/src/main/java/org/xwiki/component/embed/GenericProvider.java @@ -0,0 +1,57 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.component.embed; + +import javax.inject.Provider; + +import org.xwiki.component.internal.AbstractGenericProvider; +import org.xwiki.component.internal.JavaXGenericProvider; +import org.xwiki.component.internal.RoleHint; +import org.xwiki.component.manager.ComponentManager; + +/** + * Default provider used when the Component Manager needs to inject a {@link Provider} field but no custom Provider has + * been registered. The default behavior is simply to look up the Component role class when {@link Provider#get()} is + * called. This is useful for example when you wish to do "lazy injection". + * + * @param the role type + * @version $Id$ + * @since 3.3M2 + * @deprecated + */ +@Deprecated(since = "42.0.0") +public class GenericProvider extends JavaXGenericProvider +{ + /** + * @param componentManager the Component Manager instance that we'll use to look up the Component Role during + * {@link javax.inject.Provider#get()} + * @param roleHint the Component Role and Hint that uniquely identify the Component we wish to provide for + */ + public GenericProvider(ComponentManager componentManager, RoleHint roleHint) + { + super(componentManager, roleHint); + } + + @Override + protected AbstractGenericProvider newProvider(ComponentManager componentManager, RoleHint roleHint) + { + return new GenericProvider<>(componentManager, roleHint); + } +} diff --git a/xwiki-commons-core/xwiki-commons-netflux/pom.xml b/xwiki-commons-core/xwiki-commons-netflux/pom.xml index c44105fb51..55bf1c86f5 100644 --- a/xwiki-commons-core/xwiki-commons-netflux/pom.xml +++ b/xwiki-commons-core/xwiki-commons-netflux/pom.xml @@ -48,8 +48,12 @@ ${project.version} - javax.websocket - javax.websocket-api + jakarta.websocket + jakarta.websocket-api + + + jakarta.websocket + jakarta.websocket-client-api com.fasterxml.jackson.core diff --git a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/JsonConverter.java b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/JsonConverter.java index c07e587852..2115e1e950 100644 --- a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/JsonConverter.java +++ b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/JsonConverter.java @@ -21,11 +21,11 @@ import java.util.List; -import javax.websocket.DecodeException; -import javax.websocket.Decoder; -import javax.websocket.EncodeException; -import javax.websocket.Encoder; -import javax.websocket.EndpointConfig; +import jakarta.websocket.DecodeException; +import jakarta.websocket.Decoder; +import jakarta.websocket.EncodeException; +import jakarta.websocket.Encoder; +import jakarta.websocket.EndpointConfig; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/MessageDispatcher.java b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/MessageDispatcher.java index d65dd9440a..419ced6a65 100644 --- a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/MessageDispatcher.java +++ b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/MessageDispatcher.java @@ -24,8 +24,8 @@ import javax.inject.Inject; import javax.inject.Singleton; -import javax.websocket.DecodeException; -import javax.websocket.EncodeException; +import jakarta.websocket.DecodeException; +import jakarta.websocket.EncodeException; import org.slf4j.Logger; import org.xwiki.component.annotation.Component; diff --git a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/NetfluxEndpoint.java b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/NetfluxEndpoint.java index f50312175c..8f30750c10 100644 --- a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/NetfluxEndpoint.java +++ b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/NetfluxEndpoint.java @@ -33,10 +33,10 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import javax.websocket.CloseReason; -import javax.websocket.Endpoint; -import javax.websocket.EndpointConfig; -import javax.websocket.Session; +import jakarta.websocket.CloseReason; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.Session; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; diff --git a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/User.java b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/User.java index e9ef5ed251..09b560af70 100644 --- a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/User.java +++ b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/User.java @@ -24,7 +24,7 @@ import java.util.Queue; import java.util.Set; -import javax.websocket.Session; +import jakarta.websocket.Session; /** * Represents an user connected to a Netflux channel. diff --git a/xwiki-commons-core/xwiki-commons-netflux/src/test/java/org/xwiki/netflux/internal/ChannelTest.java b/xwiki-commons-core/xwiki-commons-netflux/src/test/java/org/xwiki/netflux/internal/ChannelTest.java index a42964c3af..9453bda2e9 100644 --- a/xwiki-commons-core/xwiki-commons-netflux/src/test/java/org/xwiki/netflux/internal/ChannelTest.java +++ b/xwiki-commons-core/xwiki-commons-netflux/src/test/java/org/xwiki/netflux/internal/ChannelTest.java @@ -28,7 +28,7 @@ import java.util.HashSet; import java.util.Set; -import javax.websocket.Session; +import jakarta.websocket.Session; import org.junit.jupiter.api.Test; diff --git a/xwiki-commons-core/xwiki-commons-netflux/src/test/java/org/xwiki/netflux/internal/NetfluxEndpointTest.java b/xwiki-commons-core/xwiki-commons-netflux/src/test/java/org/xwiki/netflux/internal/NetfluxEndpointTest.java index eb92b9c373..7b2fbcfc43 100644 --- a/xwiki-commons-core/xwiki-commons-netflux/src/test/java/org/xwiki/netflux/internal/NetfluxEndpointTest.java +++ b/xwiki-commons-core/xwiki-commons-netflux/src/test/java/org/xwiki/netflux/internal/NetfluxEndpointTest.java @@ -31,9 +31,9 @@ import java.util.Set; import java.util.stream.Collectors; -import javax.websocket.CloseReason; -import javax.websocket.RemoteEndpoint.Basic; -import javax.websocket.Session; +import jakarta.websocket.CloseReason; +import jakarta.websocket.RemoteEndpoint.Basic; +import jakarta.websocket.Session; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; diff --git a/xwiki-commons-core/xwiki-commons-properties/pom.xml b/xwiki-commons-core/xwiki-commons-properties/pom.xml index 50c17b0d67..824d1250c1 100644 --- a/xwiki-commons-core/xwiki-commons-properties/pom.xml +++ b/xwiki-commons-core/xwiki-commons-properties/pom.xml @@ -73,11 +73,9 @@ hibernate-validator test - - org.mortbay.jasper - apache-el + org.glassfish.expressly + expressly test diff --git a/xwiki-commons-core/xwiki-commons-properties/src/main/java/org/xwiki/properties/internal/DefaultBeanManager.java b/xwiki-commons-core/xwiki-commons-properties/src/main/java/org/xwiki/properties/internal/DefaultBeanManager.java index fdaf32ee85..17622d545d 100644 --- a/xwiki-commons-core/xwiki-commons-properties/src/main/java/org/xwiki/properties/internal/DefaultBeanManager.java +++ b/xwiki-commons-core/xwiki-commons-properties/src/main/java/org/xwiki/properties/internal/DefaultBeanManager.java @@ -28,12 +28,12 @@ import javax.inject.Inject; import javax.inject.Singleton; -import javax.validation.ConstraintViolation; -import javax.validation.NoProviderFoundException; -import javax.validation.Validation; -import javax.validation.ValidationException; -import javax.validation.Validator; -import javax.validation.ValidatorFactory; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.NoProviderFoundException; +import jakarta.validation.Validation; +import jakarta.validation.ValidationException; +import jakarta.validation.Validator; +import jakarta.validation.ValidatorFactory; import org.slf4j.Logger; import org.xwiki.collection.SoftCache; diff --git a/xwiki-commons-core/xwiki-commons-properties/src/test/java/org/xwiki/properties/test/TestBeanValidation.java b/xwiki-commons-core/xwiki-commons-properties/src/test/java/org/xwiki/properties/test/TestBeanValidation.java index 7750a62944..c611e797c3 100644 --- a/xwiki-commons-core/xwiki-commons-properties/src/test/java/org/xwiki/properties/test/TestBeanValidation.java +++ b/xwiki-commons-core/xwiki-commons-properties/src/test/java/org/xwiki/properties/test/TestBeanValidation.java @@ -19,7 +19,7 @@ */ package org.xwiki.properties.test; -import javax.validation.constraints.AssertTrue; +import jakarta.validation.constraints.AssertTrue; public class TestBeanValidation { diff --git a/xwiki-commons-core/xwiki-commons-websocket/pom.xml b/xwiki-commons-core/xwiki-commons-websocket/pom.xml index 9442a544bc..50e81b73b0 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/pom.xml +++ b/xwiki-commons-core/xwiki-commons-websocket/pom.xml @@ -38,33 +38,38 @@ - ${project.groupId} + org.xwiki.commons xwiki-commons-component-api ${project.version} - ${project.groupId} + org.xwiki.commons xwiki-commons-observation-api ${project.version} - ${project.groupId} + org.xwiki.commons xwiki-commons-job-api ${project.version} - ${project.groupId} + org.xwiki.commons xwiki-commons-environment-servlet ${project.version} - javax.servlet - javax.servlet-api + jakarta.servlet + jakarta.servlet-api - javax.websocket - javax.websocket-api + jakarta.websocket + jakarta.websocket-api + + jakarta.websocket + jakarta.websocket-client-api + + ${project.groupId} diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/AbstractPartialMessageHandler.java b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/AbstractPartialMessageHandler.java index 6c553adf10..34106a5c02 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/AbstractPartialMessageHandler.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/AbstractPartialMessageHandler.java @@ -23,7 +23,7 @@ import java.util.LinkedList; import java.util.List; -import javax.websocket.MessageHandler; +import jakarta.websocket.MessageHandler; /** * Base class for partial message handlers that want to handle messages when all their parts have been received. diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/EndpointComponent.java b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/EndpointComponent.java index c5a20bd473..3f87cb22d4 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/EndpointComponent.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/EndpointComponent.java @@ -19,8 +19,8 @@ */ package org.xwiki.websocket; -import javax.websocket.Endpoint; -import javax.websocket.server.ServerEndpoint; +import jakarta.websocket.Endpoint; +import jakarta.websocket.server.ServerEndpoint; import org.xwiki.component.annotation.Role; diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/WebSocketContext.java b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/WebSocketContext.java index 1dbca68165..7fca72d324 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/WebSocketContext.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/WebSocketContext.java @@ -21,13 +21,13 @@ import java.util.concurrent.Callable; -import javax.websocket.HandshakeResponse; -import javax.websocket.Session; -import javax.websocket.server.HandshakeRequest; -import javax.websocket.server.ServerEndpointConfig; - import org.xwiki.component.annotation.Role; +import jakarta.websocket.HandshakeResponse; +import jakarta.websocket.Session; +import jakarta.websocket.server.HandshakeRequest; +import jakarta.websocket.server.ServerEndpointConfig; + /** * Component used to initialize and bind a WebSocket execution context to a WebSocket session, and to run code within * that context when a WebSocket session is opened or when receiving messages. diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointConfigurator.java b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointConfigurator.java index 37a160d44f..fc15b3de0d 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointConfigurator.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointConfigurator.java @@ -19,14 +19,6 @@ */ package org.xwiki.websocket.internal; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Provider; -import javax.inject.Singleton; -import javax.websocket.HandshakeResponse; -import javax.websocket.server.HandshakeRequest; -import javax.websocket.server.ServerEndpointConfig; - import org.apache.commons.lang3.exception.ExceptionUtils; import org.xwiki.component.annotation.Component; import org.xwiki.component.manager.ComponentLookupException; @@ -34,6 +26,14 @@ import org.xwiki.websocket.EndpointComponent; import org.xwiki.websocket.WebSocketContext; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Provider; +import jakarta.inject.Singleton; +import jakarta.websocket.HandshakeResponse; +import jakarta.websocket.server.HandshakeRequest; +import jakarta.websocket.server.ServerEndpointConfig; + /** * Used to instantiate WebSocket end-points as XWiki components. * diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointDispatcher.java b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointDispatcher.java index 2710353fd1..b1f79050f6 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointDispatcher.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointDispatcher.java @@ -28,10 +28,10 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Provider; -import javax.websocket.CloseReason; -import javax.websocket.Endpoint; -import javax.websocket.EndpointConfig; -import javax.websocket.Session; +import jakarta.websocket.CloseReason; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.Session; import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointInitializer.java b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointInitializer.java index 4a638a3327..0ccd1f12d9 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointInitializer.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointInitializer.java @@ -27,11 +27,11 @@ import javax.inject.Named; import javax.inject.Provider; import javax.inject.Singleton; -import javax.websocket.DeploymentException; -import javax.websocket.Endpoint; -import javax.websocket.server.ServerContainer; -import javax.websocket.server.ServerEndpoint; -import javax.websocket.server.ServerEndpointConfig; +import jakarta.websocket.DeploymentException; +import jakarta.websocket.Endpoint; +import jakarta.websocket.server.ServerContainer; +import jakarta.websocket.server.ServerEndpoint; +import jakarta.websocket.server.ServerEndpointConfig; import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; @@ -81,7 +81,7 @@ public void initialize() throws InitializationException private ServerContainer getServerContainer() { if (this.environment instanceof ServletEnvironment) { - return (ServerContainer) ((ServletEnvironment) this.environment).getServletContext() + return (ServerContainer) ((ServletEnvironment) this.environment).getJakartaServletContext() .getAttribute(ServerContainer.class.getName()); } else { this.logger.warn("We can't initialize the WebSocket end-points in a non-servlet environment."); diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointListener.java b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointListener.java index cb22b9fd11..ada16295f9 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointListener.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiEndpointListener.java @@ -22,7 +22,7 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import javax.websocket.CloseReason; +import jakarta.websocket.CloseReason; import org.slf4j.Logger; import org.xwiki.component.annotation.Component; diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiServerApplicationConfig.java b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiServerApplicationConfig.java index 3b4acd529e..a960694ed0 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiServerApplicationConfig.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/main/java/org/xwiki/websocket/internal/XWikiServerApplicationConfig.java @@ -22,9 +22,9 @@ import java.util.Collections; import java.util.Set; -import javax.websocket.Endpoint; -import javax.websocket.server.ServerApplicationConfig; -import javax.websocket.server.ServerEndpointConfig; +import jakarta.websocket.Endpoint; +import jakarta.websocket.server.ServerApplicationConfig; +import jakarta.websocket.server.ServerEndpointConfig; /** * Disable the automatic WebSocket end-point registration because we want to register the end-points ourselves in diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointConfiguratorTest.java b/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointConfiguratorTest.java index ea22a2bf79..b7562b7f67 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointConfiguratorTest.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointConfiguratorTest.java @@ -20,9 +20,9 @@ package org.xwiki.websocket.internal; import javax.inject.Named; -import javax.websocket.HandshakeResponse; -import javax.websocket.server.HandshakeRequest; -import javax.websocket.server.ServerEndpointConfig; +import jakarta.websocket.HandshakeResponse; +import jakarta.websocket.server.HandshakeRequest; +import jakarta.websocket.server.ServerEndpointConfig; import org.junit.jupiter.api.Test; import org.xwiki.component.manager.ComponentLookupException; diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointDispatcherTest.java b/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointDispatcherTest.java index 696ff5be8c..aa40f8920a 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointDispatcherTest.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointDispatcherTest.java @@ -22,10 +22,10 @@ import java.util.Collections; import javax.inject.Named; -import javax.websocket.CloseReason; -import javax.websocket.Endpoint; -import javax.websocket.EndpointConfig; -import javax.websocket.Session; +import jakarta.websocket.CloseReason; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.Session; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointInitializerTest.java b/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointInitializerTest.java index 1522b07f22..d00866843b 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointInitializerTest.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointInitializerTest.java @@ -24,15 +24,15 @@ import java.util.Collections; import javax.inject.Named; -import javax.servlet.ServletContext; -import javax.websocket.DecodeException; -import javax.websocket.Decoder; -import javax.websocket.EncodeException; -import javax.websocket.Encoder; -import javax.websocket.EndpointConfig; -import javax.websocket.server.ServerContainer; -import javax.websocket.server.ServerEndpoint; -import javax.websocket.server.ServerEndpointConfig; +import jakarta.servlet.ServletContext; +import jakarta.websocket.DecodeException; +import jakarta.websocket.Decoder; +import jakarta.websocket.EncodeException; +import jakarta.websocket.Encoder; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.server.ServerContainer; +import jakarta.websocket.server.ServerEndpoint; +import jakarta.websocket.server.ServerEndpointConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; @@ -152,7 +152,7 @@ void setup() throws Exception when(servletContext.getAttribute(ServerContainer.class.getName())).thenReturn(this.serverContainer); ServletEnvironment environment = mock(ServletEnvironment.class); - when(environment.getServletContext()).thenReturn(servletContext); + when(environment.getJakartaServletContext()).thenReturn(servletContext); this.componentManager.registerComponent(Environment.class, environment); } diff --git a/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointListenerTest.java b/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointListenerTest.java index 54e850d432..49217fa5b5 100644 --- a/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointListenerTest.java +++ b/xwiki-commons-core/xwiki-commons-websocket/src/test/java/org/xwiki/websocket/internal/XWikiEndpointListenerTest.java @@ -22,10 +22,10 @@ import java.util.Collections; import javax.inject.Named; -import javax.websocket.CloseReason; -import javax.websocket.Endpoint; -import javax.websocket.EndpointConfig; -import javax.websocket.Session; +import jakarta.websocket.CloseReason; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.Session; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/xwiki-commons-tools/xwiki-commons-tool-spoon/xwiki-commons-tool-spoon-checks/src/main/java/org/xwiki/tool/spoon/ComponentAnnotationProcessor.java b/xwiki-commons-tools/xwiki-commons-tool-spoon/xwiki-commons-tool-spoon-checks/src/main/java/org/xwiki/tool/spoon/ComponentAnnotationProcessor.java index 3831b47d0d..068a7464a7 100644 --- a/xwiki-commons-tools/xwiki-commons-tool-spoon/xwiki-commons-tool-spoon-checks/src/main/java/org/xwiki/tool/spoon/ComponentAnnotationProcessor.java +++ b/xwiki-commons-tools/xwiki-commons-tool-spoon/xwiki-commons-tool-spoon-checks/src/main/java/org/xwiki/tool/spoon/ComponentAnnotationProcessor.java @@ -26,7 +26,9 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; @@ -68,7 +70,8 @@ public class ComponentAnnotationProcessor extends AbstractXWikiProcessor SINGLETON_ANNOTATIONS = + new LinkedHashSet<>(List.of("javax.inject.Singleton", "jakarta.inject.Singleton")); private static final String INSTANTIATION_STRATEGY_ANNOTATION = "org.xwiki.component.annotation.InstantiationStrategy"; @@ -104,7 +107,7 @@ public void process(CtClass ctClass) } } else if (INSTANTIATION_STRATEGY_ANNOTATION.equals(annotation.getAnnotationType().getQualifiedName())) { hasInstantiationStrategyAnnotation = true; - } else if (SINGLETON_ANNOTATION.equals(annotation.getAnnotationType().getQualifiedName())) { + } else if (SINGLETON_ANNOTATIONS.contains(annotation.getAnnotationType().getQualifiedName())) { hasSingletonAnnotation = true; } } @@ -161,8 +164,8 @@ private void check3A(String qualifiedName, boolean hasInstantiationStrategyAnnot { if (!hasInstantiationStrategyAnnotation && !hasSingletonAnnotation) { registerError(String.format( - "Component class [%s] must have either the [%s] or the [%s] annotation defined on it.", - qualifiedName, SINGLETON_ANNOTATION, INSTANTIATION_STRATEGY_ANNOTATION)); + "Component class [%s] must have either one of %s or the [%s] annotation defined on it.", + qualifiedName, SINGLETON_ANNOTATIONS, INSTANTIATION_STRATEGY_ANNOTATION)); } } diff --git a/xwiki-commons-tools/xwiki-commons-tool-spoon/xwiki-commons-tool-spoon-tests/src/test/java/org/xwiki/tool/spoon/ComponentAnnotationProcessorTest.java b/xwiki-commons-tools/xwiki-commons-tool-spoon/xwiki-commons-tool-spoon-tests/src/test/java/org/xwiki/tool/spoon/ComponentAnnotationProcessorTest.java index 4a32a53632..ac9d3a38e8 100644 --- a/xwiki-commons-tools/xwiki-commons-tool-spoon/xwiki-commons-tool-spoon-tests/src/test/java/org/xwiki/tool/spoon/ComponentAnnotationProcessorTest.java +++ b/xwiki-commons-tools/xwiki-commons-tool-spoon/xwiki-commons-tool-spoon-tests/src/test/java/org/xwiki/tool/spoon/ComponentAnnotationProcessorTest.java @@ -46,13 +46,13 @@ void process() + "\\Q- Component [org.xwiki.tool.spoon.component.ComponentAnnotationWithOverrideAndDeclared] is " + "registered several times in [\\E.*\\Q]\\E\n" + "\\Q- Component class [org.xwiki.tool.spoon.component.ComponentAnnotationWithoutSingletonOrInstantation" - + "StrategyAndDeclared] must have either the [javax.inject.Singleton] or the " + + "StrategyAndDeclared] must have either one of [javax.inject.Singleton, jakarta.inject.Singleton] or the " + "[org.xwiki.component.annotation.InstantiationStrategy] annotation defined on it.\\E\n" + "\\Q- Component [org.xwiki.tool.spoon.component.ComponentAnnotationWithoutStaticRegistrationAndDeclared] " + "is declared in [\\E.*\\Q] but it is also declared with a \"staticRegistration\" parameter with a " + "[false] value, e.g. \"@Component(staticRegistration = false\". You need to fix that!\\E\n" + "\\Q- Component class [org.xwiki.tool.spoon.component.ComponentAnnotationWithoutStaticRegistrationAnd" - + "Declared] must have either the [javax.inject.Singleton] or the " + + "Declared] must have either one of [javax.inject.Singleton, jakarta.inject.Singleton] or the " + "[org.xwiki.component.annotation.InstantiationStrategy] annotation defined on it.\\E\n" + "\\Q- Component [some.component.class.NotInThisModule1] is declared in [\\E.*\\Q] but it's missing a " + "@Component declaration or its source code wasn't found in the current Maven module\\E\n" diff --git a/xwiki-commons-tools/xwiki-commons-tool-test/xwiki-commons-tool-test-component/src/main/java/org/xwiki/test/mockito/MockitoComponentMocker.java b/xwiki-commons-tools/xwiki-commons-tool-test/xwiki-commons-tool-test-component/src/main/java/org/xwiki/test/mockito/MockitoComponentMocker.java index f3a7fded95..96943fab86 100644 --- a/xwiki-commons-tools/xwiki-commons-tool-test/xwiki-commons-tool-test-component/src/main/java/org/xwiki/test/mockito/MockitoComponentMocker.java +++ b/xwiki-commons-tools/xwiki-commons-tool-test/xwiki-commons-tool-test-component/src/main/java/org/xwiki/test/mockito/MockitoComponentMocker.java @@ -19,6 +19,9 @@ */ package org.xwiki.test.mockito; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; @@ -27,8 +30,6 @@ import java.util.Map; import java.util.Set; -import javax.inject.Provider; - import org.slf4j.Logger; import org.xwiki.component.annotation.ComponentAnnotationLoader; import org.xwiki.component.annotation.ComponentDescriptorFactory; @@ -39,8 +40,7 @@ import org.xwiki.component.internal.RoleHint; import org.xwiki.component.util.ReflectionUtils; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import jakarta.inject.Provider; /** * See javadoc for {@link MockitoComponentMockingRule}. @@ -237,6 +237,7 @@ private void registerMockDependencies(ComponentDescriptor descriptor) throws // TODO: Handle multiple roles/hints. if (!this.excludedComponentRoleDependencies.contains(roleTypeClass) && Logger.class != roleTypeClass && !roleTypeClass.isAssignableFrom(List.class) && !roleTypeClass.isAssignableFrom(Map.class) + && ComponentDescriptor.class != roleTypeClass && !this.componentManager.hasComponent(dependencyDescriptor.getRoleType(), dependencyDescriptor.getRoleHint())) { @@ -252,7 +253,7 @@ private void registerMockDependencies(ComponentDescriptor descriptor) throws Object dependencyMock = mock(roleTypeClass, dependencyDescriptor.getName()); - if (Provider.class == roleTypeClass) { + if (javax.inject.Provider.class == roleTypeClass || Provider.class == roleTypeClass) { Type providedType = ReflectionUtils.getLastTypeGenericArgument(dependencyDescriptor.getRoleType()); Class providedClass = ReflectionUtils.getTypeClass(providedType); @@ -269,8 +270,13 @@ private void registerMockDependencies(ComponentDescriptor descriptor) throws } else { // If the dependency is a Provider not targeting a @Role register a mock Provider which provide // a mock - Provider provider = (Provider) dependencyMock; - when(provider.get()).thenReturn(mock(providedClass, providedType.toString())); + if (javax.inject.Provider.class == roleTypeClass) { + javax.inject.Provider provider = (javax.inject.Provider) dependencyMock; + when(provider.get()).thenReturn(mock(providedClass, providedType.toString())); + } else { + Provider provider = (Provider) dependencyMock; + when(provider.get()).thenReturn(mock(providedClass, providedType.toString())); + } } }