You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2026/01/23 12:54:16 UTC

(sling-org-apache-sling-starter-test-services) branch issue/SLING-13071 created (now d8e3ff0)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a change to branch issue/SLING-13071
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-starter-test-services.git


      at d8e3ff0  SLING-13071 - HTL use objects that adapt from the javax SlingHttpServletRequest cannot be instantiated a Jakarta context

This branch includes the following new commits:

     new d8e3ff0  SLING-13071 - HTL use objects that adapt from the javax SlingHttpServletRequest cannot be instantiated a Jakarta context

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(sling-org-apache-sling-starter-test-services) 01/01: SLING-13071 - HTL use objects that adapt from the javax SlingHttpServletRequest cannot be instantiated a Jakarta context

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch issue/SLING-13071
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-starter-test-services.git

commit d8e3ff079f480de856951c13a31c80d2873eef6f
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Jan 23 13:52:57 2026 +0100

    SLING-13071 - HTL use objects that adapt from the javax SlingHttpServletRequest cannot be instantiated a Jakarta context
    
    Add a Pojo and adapter factory that can help reproduce the problem.
---
 .../adapter/RequestHashCodeAdapterFactory.java     | 50 ++++++++++++++++++++++
 ...{package-info.java => RequestHashCodePojo.java} | 31 +++++++++++++-
 .../testservices/exported/package-info.java        |  2 +-
 3 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/starter/testservices/adapter/RequestHashCodeAdapterFactory.java b/src/main/java/org/apache/sling/starter/testservices/adapter/RequestHashCodeAdapterFactory.java
new file mode 100644
index 0000000..f29304f
--- /dev/null
+++ b/src/main/java/org/apache/sling/starter/testservices/adapter/RequestHashCodeAdapterFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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.starter.testservices.adapter;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.adapter.AdapterFactory;
+import org.apache.sling.starter.testservices.exported.RequestHashCodePojo;
+import org.jetbrains.annotations.NotNull;
+import org.osgi.service.component.annotations.Component;
+
+/**
+ * AdapterFactory that adapts SlingHttpServletRequest to RequestHashCodePojo.
+ * The POJO will contain the hash code of the request object as a string.
+ */
+@Component(
+        service = AdapterFactory.class,
+        property = {
+            AdapterFactory.ADAPTABLE_CLASSES + ":String=org.apache.sling.api.SlingHttpServletRequest",
+            AdapterFactory.ADAPTER_CLASSES
+                    + ":String=org.apache.sling.starter.testservices.exported.RequestHashCodePojo"
+        })
+public class RequestHashCodeAdapterFactory implements AdapterFactory {
+
+    @Override
+    public <AdapterType> AdapterType getAdapter(@NotNull Object adaptable, @NotNull Class<AdapterType> type) {
+        if (adaptable instanceof SlingHttpServletRequest && type == RequestHashCodePojo.class) {
+            SlingHttpServletRequest request = (SlingHttpServletRequest) adaptable;
+            String hashCodeString = String.valueOf(request.hashCode());
+            RequestHashCodePojo pojo = new RequestHashCodePojo(hashCodeString);
+            return type.cast(pojo);
+        }
+        return null;
+    }
+}
diff --git a/src/main/java/org/apache/sling/starter/testservices/exported/package-info.java b/src/main/java/org/apache/sling/starter/testservices/exported/RequestHashCodePojo.java
similarity index 57%
copy from src/main/java/org/apache/sling/starter/testservices/exported/package-info.java
copy to src/main/java/org/apache/sling/starter/testservices/exported/RequestHashCodePojo.java
index 1d1ec8a..5c54ffe 100644
--- a/src/main/java/org/apache/sling/starter/testservices/exported/package-info.java
+++ b/src/main/java/org/apache/sling/starter/testservices/exported/RequestHashCodePojo.java
@@ -16,6 +16,33 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
-@org.osgi.annotation.versioning.Version("2.2.0")
 package org.apache.sling.starter.testservices.exported;
+
+/**
+ * POJO representing a request hash code.
+ *
+ * <p>Key characteristics: does not have a no-arg constructor and its AdapterFactory adapts from
+ * the legacy SlingHttpServletRequest interface.</p>
+ */
+public class RequestHashCodePojo {
+
+    private final String hashCode;
+
+    /**
+     * Constructor that takes the hashCode.
+     *
+     * @param hashCode the hash code as a string
+     */
+    public RequestHashCodePojo(String hashCode) {
+        this.hashCode = hashCode;
+    }
+
+    /**
+     * Gets the hash code value.
+     *
+     * @return the hash code as a string
+     */
+    public String getHashCode() {
+        return hashCode;
+    }
+}
diff --git a/src/main/java/org/apache/sling/starter/testservices/exported/package-info.java b/src/main/java/org/apache/sling/starter/testservices/exported/package-info.java
index 1d1ec8a..37eaba9 100644
--- a/src/main/java/org/apache/sling/starter/testservices/exported/package-info.java
+++ b/src/main/java/org/apache/sling/starter/testservices/exported/package-info.java
@@ -17,5 +17,5 @@
  * under the License.
  */
 
-@org.osgi.annotation.versioning.Version("2.2.0")
+@org.osgi.annotation.versioning.Version("2.3.0")
 package org.apache.sling.starter.testservices.exported;