This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch issue/SLING-13086 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-post.git
commit a2ab5171acc3a9093f714168ed59b4120049de01 Author: Robert Munteanu <[email protected]> AuthorDate: Fri Jan 30 14:56:58 2026 +0100 SLING-13086 - SlingPostServlet no longer register PostOperation services after the Jakarta migration Adapt the PostOperationProxyProvider to also register proxy services for the JakartaPostOperation services. --- .../post/impl/PostOperationProxyProvider.java | 40 ++++++++++++---- .../impl/wrapper/JakartaToJavaxPostOperation.java | 54 ++++++++++++++++++++++ 2 files changed, 86 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/sling/servlets/post/impl/PostOperationProxyProvider.java b/src/main/java/org/apache/sling/servlets/post/impl/PostOperationProxyProvider.java index df02e05..e2902f0 100644 --- a/src/main/java/org/apache/sling/servlets/post/impl/PostOperationProxyProvider.java +++ b/src/main/java/org/apache/sling/servlets/post/impl/PostOperationProxyProvider.java @@ -18,13 +18,16 @@ */ package org.apache.sling.servlets.post.impl; +import java.util.Arrays; import java.util.Dictionary; import java.util.Hashtable; import java.util.IdentityHashMap; +import java.util.List; import java.util.Map; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.servlets.HtmlResponse; +import org.apache.sling.servlets.post.JakartaPostOperation; import org.apache.sling.servlets.post.PostOperation; import org.apache.sling.servlets.post.PostResponse; import org.apache.sling.servlets.post.SlingPostOperation; @@ -32,6 +35,8 @@ import org.apache.sling.servlets.post.SlingPostProcessor; import org.apache.sling.servlets.post.exceptions.PreconditionViolatedPersistenceException; import org.apache.sling.servlets.post.exceptions.TemporaryPersistenceException; import org.apache.sling.servlets.post.impl.helper.HtmlResponseProxy; +import org.apache.sling.servlets.post.impl.wrapper.JakartaToJavaxPostOperation; +import org.apache.sling.servlets.post.impl.wrapper.JavaxToJakartaPostOperation; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.InvalidSyntaxException; @@ -46,20 +51,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The <code>PostOperationProxyProvider</code> listens for legacy - * {@link SlingPostOperation} services being registered and wraps them with a - * proxy for the new {@link PostOperation} API and registers the procies. + * <p>Adapter bridge for various PostOperation APIs.</p> + * + * <p>The <code>PostOperationProxyProvider</code> listens for legacy + * {@link SlingPostOperation} services and for {@link JakartaPostOperation} services + * being registered, adapts them to the {@link PostOperation} API, and registers the proxies</p> */ @Component(service = {}) +@SuppressWarnings("deprecation") public class PostOperationProxyProvider implements ServiceListener { private final Logger log = LoggerFactory.getLogger(getClass()); /** - * The service listener filter to listen for SlingPostOperation services + * The service listener filter to listen for SlingPostOperation and JakartaPostOperation services */ - private static final String REFERENCE_FILTER = - "(" + Constants.OBJECTCLASS + "=" + SlingPostOperation.SERVICE_NAME + ")"; + private static final String REFERENCE_FILTER = "(|(" + Constants.OBJECTCLASS + "=" + SlingPostOperation.SERVICE_NAME + + ")(" + Constants.OBJECTCLASS + "=" + JakartaPostOperation.class.getName() + "))"; // maps references to the SlingPostOperation services to the registrations // of the PostOperation proxies for unregistration purposes @@ -159,8 +167,24 @@ public class PostOperationProxyProvider implements ServiceListener { * Called by serviceChanged */ private void register(final ServiceReference serviceReference) { - final SlingPostOperation service = (SlingPostOperation) this.bundleContext.getService(serviceReference); - final PostOperationProxy proxy = new PostOperationProxy(service); + List<String> objectClass = + Arrays.asList((String[]) serviceReference.getProperties().get(Constants.OBJECTCLASS)); + final Object proxy; + if (objectClass.contains(SlingPostOperation.SERVICE_NAME)) { + SlingPostOperation service = (SlingPostOperation) this.bundleContext.getService(serviceReference); + proxy = new PostOperationProxy(service); + } else if (objectClass.contains(JakartaPostOperation.class.getName())) { + JakartaPostOperation service = (JakartaPostOperation) this.bundleContext.getService(serviceReference); + if (service instanceof JavaxToJakartaPostOperation) { + // registered by the SlingPostServlet because a PostOperation service was bound, do not do anything + return; + } else { + proxy = new JakartaToJavaxPostOperation(service); + } + } else { + // should not happen, log + return; + } final BundleContext bundleContext = serviceReference.getBundle().getBundleContext(); final Dictionary<String, Object> props = copyServiceProperties(serviceReference); diff --git a/src/main/java/org/apache/sling/servlets/post/impl/wrapper/JakartaToJavaxPostOperation.java b/src/main/java/org/apache/sling/servlets/post/impl/wrapper/JakartaToJavaxPostOperation.java new file mode 100644 index 0000000..b23a1d2 --- /dev/null +++ b/src/main/java/org/apache/sling/servlets/post/impl/wrapper/JakartaToJavaxPostOperation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.servlets.post.impl.wrapper; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.resource.PersistenceException; +import org.apache.sling.api.wrappers.JavaxToJakartaRequestWrapper; +import org.apache.sling.servlets.post.JakartaPostOperation; +import org.apache.sling.servlets.post.PostOperation; +import org.apache.sling.servlets.post.PostResponse; +import org.apache.sling.servlets.post.SlingJakartaPostProcessor; +import org.apache.sling.servlets.post.SlingPostProcessor; +import org.apache.sling.servlets.post.exceptions.PreconditionViolatedPersistenceException; +import org.apache.sling.servlets.post.exceptions.TemporaryPersistenceException; + +@SuppressWarnings("deprecation") +public class JakartaToJavaxPostOperation implements PostOperation { + + private final JakartaPostOperation delegate; + + public JakartaToJavaxPostOperation(final JakartaPostOperation delegate) { + this.delegate = delegate; + } + + @Override + public void run( + final SlingHttpServletRequest request, final PostResponse response, final SlingPostProcessor[] processors) + throws PreconditionViolatedPersistenceException, TemporaryPersistenceException, PersistenceException { + final SlingJakartaPostProcessor[] wrappers = new SlingJakartaPostProcessor[processors.length]; + for (int i = 0; i < processors.length; i++) { + wrappers[i] = new JavaxToSlingJakartaPostProcessor(processors[i]); + } + this.delegate.run( + JavaxToJakartaRequestWrapper.toJakartaRequest(request), + new JavaxToJakartaPostResponse(response), + wrappers); + } +}
