sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [sling-org-apache-sling-servlets-resolver] branch master updated: SLING-9714: Ignore default resource super type for servlet registrati… (#12)
Date Tue, 01 Sep 2020 15:51:38 GMT
This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new c0f8228  SLING-9714: Ignore default resource super type for servlet registrati…
(#12)
c0f8228 is described below

commit c0f822813dbe1f668950fd9a98d5b0ef3e413745
Author: Karl Pauls <pauls@apache.org>
AuthorDate: Tue Sep 1 17:51:30 2020 +0200

    SLING-9714: Ignore default resource super type for servlet registrati… (#12)
    
    * SLING-9714: Ignore default resource super type for servlet registrations.
    
    Co-authored-by: Radu Cotescu radu@apache.org
---
 .../internal/resource/ServletResource.java         |  6 ++--
 .../resource/ServletResourceProviderFactory.java   |  2 +-
 .../ServletResourceProviderCreateTest.java         | 37 +++++++++++++++++++---
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResource.java
b/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResource.java
index ab63f8b..883e40f 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResource.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResource.java
@@ -35,6 +35,8 @@ import org.apache.sling.servlets.resolver.bundle.tracker.internal.BundledScriptS
 
 public class ServletResource extends AbstractResource {
 
+    public static final String DEFAULT_RESOURCE_SUPER_TYPE = "sling/bundle/resource";
+
     private final ResourceResolver resourceResolver;
 
     private final Servlet servlet;
@@ -60,7 +62,7 @@ public class ServletResource extends AbstractResource {
         this.servlet = servlet;
         this.path = path;
         this.resourceType = ServletResourceProviderFactory.ensureServletNameExtension(path);
-        this.resourceSuperType = StringUtils.isEmpty(resourceSuperType) ? "sling/bundle/resource"
: resourceSuperType;
+        this.resourceSuperType = StringUtils.isEmpty(resourceSuperType) ? DEFAULT_RESOURCE_SUPER_TYPE
: resourceSuperType;
         this.metadata = new ResourceMetadata();
         this.metadata.put("sling.servlet.resource", "true");
     }
@@ -86,8 +88,6 @@ public class ServletResource extends AbstractResource {
         return resourceType;
     }
 
-    /** Servlet Resources always returns "sling/bundle/resource" as
-     * the super type. */
     @Override
     public String getResourceSuperType() {
         return resourceSuperType;
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java
b/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java
index 629d25b..a7881d4 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java
@@ -149,7 +149,7 @@ public class ServletResourceProviderFactory {
         }
         String resourceSuperType = PropertiesUtil.toString(ref.getProperty(SLING_SERVLET_RESOURCE_SUPER_TYPE),
null);
         Set<String> resourceSuperTypeMarkers = new HashSet<>();
-        if (StringUtils.isNotEmpty(resourceSuperType)) {
+        if (StringUtils.isNotEmpty(resourceSuperType) && !ServletResource.DEFAULT_RESOURCE_SUPER_TYPE.equals(resourceSuperType))
{
             for (String rt : PropertiesUtil.toStringArray(ref.getProperty(SLING_SERVLET_RESOURCE_TYPES)))
{
                 if (!rt.startsWith("/")) {
                     rt = getPrefix(ref).concat(ResourceUtil.resourceTypeToPath(rt));
diff --git a/src/test/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderCreateTest.java
b/src/test/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderCreateTest.java
index a1c25e5..8b11b6c 100644
--- a/src/test/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderCreateTest.java
+++ b/src/test/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderCreateTest.java
@@ -18,11 +18,6 @@
  */
 package org.apache.sling.servlets.resolver.internal.resource;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 import java.util.Collections;
 import java.util.Set;
 
@@ -42,6 +37,11 @@ import org.mockito.Mockito;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
 public class ServletResourceProviderCreateTest {
 
     private static final Servlet TEST_SERVLET = new GenericServlet() {
@@ -213,4 +213,31 @@ public class ServletResourceProviderCreateTest {
         assertEquals(TEST_SERVLET, servletResource.adaptTo(Servlet.class));
     }
 
+    @Test
+    public void testCreateWithDefaultResourceSuperType() {
+        @SuppressWarnings("unchecked")
+        final ServiceReference<Servlet> msr = Mockito.mock(ServiceReference.class);
+        Mockito.when(msr.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
+        Mockito.when(msr.getProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES)).thenReturn(RES_TYPE);
+        Mockito.when(msr.getProperty(ServletResolverConstants.SLING_SERVLET_SELECTORS)).thenReturn("sel");
+        Mockito.when(msr.getProperty(ServletResolverConstants.SLING_SERVLET_EXTENSIONS)).thenReturn(new
String[] {"html"});
+        Mockito.when(msr.getProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_SUPER_TYPE))
+                .thenReturn(new String[]{ServletResource.DEFAULT_RESOURCE_SUPER_TYPE});
+        final ServletResourceProvider srp = factory.create(msr, TEST_SERVLET);
+        final Set<String> paths = srp.getServletPaths();
+        assertEquals(1, paths.size());
+        assertTrue(paths.contains(ROOT + RES_TYPE_PATH + "/sel.html" + ServletResourceProviderFactory.SERVLET_PATH_EXTENSION));
+        @SuppressWarnings("unchecked")
+        Resource superTypeMarkingResource = srp.getResource(Mockito.mock(ResolveContext.class),
"/apps/sling/sample",
+                Mockito.mock(ResourceContext.class), Mockito.mock(Resource.class));
+        assertNull(superTypeMarkingResource);
+
+        @SuppressWarnings("unchecked")
+        Resource servletResource = srp.getResource(Mockito.mock(ResolveContext.class), "/apps/sling/sample/sel.html.servlet",
+                Mockito.mock(ResourceContext.class), Mockito.mock(Resource.class));
+        assertNotNull(servletResource);
+        assertEquals(ServletResource.DEFAULT_RESOURCE_SUPER_TYPE, servletResource.getResourceSuperType());
+        assertEquals(TEST_SERVLET, servletResource.adaptTo(Servlet.class));
+    }
+
 }


Mime
View raw message