diff --git a/pom.xml b/pom.xml
index b056ab629..c93f04676 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
org.apache.sling
org.apache.sling.api
- 2.21.0
+ 2.23.1-SNAPSHOT
provided
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java b/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
index b925e65aa..4e423c25f 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
@@ -31,12 +31,11 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.jetbrains.annotations.NotNull;
-
import org.apache.commons.collections4.BidiMap;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.api.resource.path.Path;
import org.apache.sling.resourceresolver.impl.console.ResourceResolverWebConsolePlugin;
import org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker;
@@ -48,6 +47,7 @@
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker;
import org.apache.sling.serviceusermapping.ServiceUserMapper;
import org.apache.sling.spi.resource.provider.ResourceProvider;
+import org.jetbrains.annotations.NotNull;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
@@ -405,6 +405,11 @@ public ResourceAccessSecurityTracker getResourceAccessSecurityTracker () {
return this.activator.getResourceAccessSecurityTracker();
}
+ /** gets PathToUriMappingServiceImpl */
+ public PathToUriMappingService getPathToUriMappingService() {
+ return this.activator.getPathToUriMappingService();
+ }
+
@NotNull
@Override
public ResourceResolver getServiceResourceResolver(
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
index 646a0775f..6de579a2f 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
@@ -34,9 +34,11 @@
import org.apache.commons.collections4.bidimap.TreeBidiMap;
import org.apache.sling.api.resource.ResourceDecorator;
import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.api.resource.path.Path;
import org.apache.sling.api.resource.runtime.RuntimeService;
import org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker;
+import org.apache.sling.resourceresolver.impl.mapping.MapEntries;
import org.apache.sling.resourceresolver.impl.mapping.Mapping;
import org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProvider;
import org.apache.sling.resourceresolver.impl.observation.ResourceChangeListenerWhiteboard;
@@ -119,6 +121,9 @@ private static final class FactoryRegistration {
@Reference
ResourceAccessSecurityTracker resourceAccessSecurityTracker;
+ @Reference
+ PathToUriMappingService pathToUriMappingService;
+
volatile ResourceProviderTracker resourceProviderTracker;
volatile ResourceChangeListenerWhiteboard changeListenerWhiteboard;
@@ -153,6 +158,10 @@ public ResourceAccessSecurityTracker getResourceAccessSecurityTracker() {
return this.resourceAccessSecurityTracker;
}
+ public PathToUriMappingService getPathToUriMappingService() {
+ return this.pathToUriMappingService;
+ }
+
public EventAdmin getEventAdmin() {
return this.eventAdmin;
}
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
index 2fddf6531..6a565b4ec 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
@@ -30,11 +30,10 @@
import java.util.Set;
import java.util.StringTokenizer;
-import org.apache.commons.lang3.StringUtils;
-import org.jetbrains.annotations.Nullable;
import javax.jcr.Session;
import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.adapter.annotations.Adaptable;
import org.apache.sling.adapter.annotations.Adapter;
import org.apache.sling.api.SlingException;
@@ -48,6 +47,7 @@
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ResourceWrapper;
+import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.api.resource.mapping.ResourceMapper;
import org.apache.sling.resourceresolver.impl.helper.RedirectResource;
import org.apache.sling.resourceresolver.impl.helper.ResourceIteratorDecorator;
@@ -62,6 +62,7 @@
import org.apache.sling.resourceresolver.impl.params.ParsedParameters;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider;
import org.apache.sling.spi.resource.provider.ResourceProvider;
+import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -625,7 +626,7 @@ public AdapterType adaptTo(final Class type) {
if ( type == ResourceMapper.class )
return (AdapterType) new ResourceMapperImpl(this, factory.getResourceDecoratorTracker(), factory.getMapEntries(),
- factory.isOptimizeAliasResolutionEnabled(), factory.getNamespaceMangler());
+ factory.isOptimizeAliasResolutionEnabled(), factory.getNamespaceMangler(), factory.getPathToUriMappingService());
final AdapterType result = this.control.adaptTo(this.context, type);
if ( result != null ) {
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
index bc47c2653..deda9028d 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
@@ -33,7 +33,9 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.api.resource.mapping.ResourceMapper;
+import org.apache.sling.api.uri.SlingUri;
import org.apache.sling.resourceresolver.impl.JcrNamespaceMangler;
import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
import org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker;
@@ -53,15 +55,17 @@ public class ResourceMapperImpl implements ResourceMapper {
private final MapEntriesHandler mapEntries;
private final boolean optimizedAliasResolutionEnabled;
private final Object namespaceMangler;
-
+ private final PathToUriMappingService pathToUriMappingService;
public ResourceMapperImpl(ResourceResolverImpl resolver, ResourceDecoratorTracker resourceDecorator,
- MapEntriesHandler mapEntries, boolean optimizedAliasResolutionEnabled, Object namespaceMangler) {
+ MapEntriesHandler mapEntries, boolean optimizedAliasResolutionEnabled, Object namespaceMangler,
+ PathToUriMappingService pathToUriMappingService) {
this.resolver = resolver;
this.resourceDecorator = resourceDecorator;
this.mapEntries = mapEntries;
this.optimizedAliasResolutionEnabled = optimizedAliasResolutionEnabled;
this.namespaceMangler = namespaceMangler;
+ this.pathToUriMappingService = pathToUriMappingService;
}
@Override
@@ -166,6 +170,13 @@ public Collection getAllMappings(String resourcePath, HttpServletRequest
// vanity paths are prepended to make sure they get returned last
mappings.addAll(0, vanityPaths);
+
+ // Apply mappings from Resource Mappers
+ PathToUriMappingService.Result mappingResult = pathToUriMappingService.map(request, mappings.get(mappings.size() - 1));
+ for (Map.Entry mappingFromChain : mappingResult.getIntermediateMappings().entrySet()) {
+ mappings.add(mappingFromChain.getValue().toString());
+ }
+
// 7. apply context path if needed
mappings.replaceAll(new ApplyContextPath(request));
@@ -174,10 +185,10 @@ public Collection getAllMappings(String resourcePath, HttpServletRequest
mappings.replaceAll(path -> path.concat(fragmentQuery));
}
- mappings.forEach( path ->
- logger.debug("map: Returning URL {} as mapping for path {}", path, resourcePath)
- );
-
+ mappings.forEach( path -> {
+ logger.debug("map: Returning URL {} as mapping for path {}", path, resourcePath);
+ });
+
Collections.reverse(mappings);
return new LinkedHashSet<>(mappings);
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/MappingChainContextInternal.java b/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/MappingChainContextInternal.java
new file mode 100644
index 000000000..8ad49facd
--- /dev/null
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/MappingChainContextInternal.java
@@ -0,0 +1,71 @@
+/*
+ * 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.resourceresolver.impl.urimapping;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.uri.SlingUri;
+import org.apache.sling.spi.urimapping.MappingChainContext;
+
+class MappingChainContextInternal implements MappingChainContext {
+
+ private final ResourceResolver resourceResolver;
+ private final Map attributes = new HashMap<>();
+ private final Map intermediateMappings = new LinkedHashMap<>();
+ private boolean skipRemainingChain = false;
+
+
+ MappingChainContextInternal(ResourceResolver resourceResolver) {
+ this.resourceResolver = resourceResolver;
+ }
+
+ @Override
+ public void skipRemainingChain() {
+ skipRemainingChain = true;
+ }
+
+ @Override
+ public Map getAttributes() {
+ return attributes;
+ }
+
+ @Override
+ public Map getIntermediateMappings() {
+ return Collections.unmodifiableMap(intermediateMappings);
+ }
+
+ @Override
+ public ResourceResolver getResourceResolver() {
+ return resourceResolver;
+ }
+
+ boolean isMarkedAsSkipRemainingChain() {
+ return skipRemainingChain;
+ }
+
+ void addIntermediateMapping(String name, SlingUri resourceUri) {
+ intermediateMappings.put(name, resourceUri);
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/MappingChainResult.java b/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/MappingChainResult.java
new file mode 100644
index 000000000..ad27faac2
--- /dev/null
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/MappingChainResult.java
@@ -0,0 +1,45 @@
+/*
+ * 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.resourceresolver.impl.urimapping;
+
+import java.util.Map;
+
+import org.apache.sling.api.resource.mapping.PathToUriMappingService;
+import org.apache.sling.api.uri.SlingUri;
+
+class MappingChainResult implements PathToUriMappingService.Result {
+
+ private final SlingUri slingUri;
+ private final Map intermediateMappings;
+
+ public MappingChainResult(SlingUri slingUri, Map intermediateMappings) {
+ this.slingUri = slingUri;
+ this.intermediateMappings = intermediateMappings;
+ }
+
+ public SlingUri getUri() {
+ return slingUri;
+ }
+
+ public Map getIntermediateMappings() {
+ return intermediateMappings;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/PathToUriMappingServiceImpl.java b/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/PathToUriMappingServiceImpl.java
new file mode 100644
index 000000000..c0642c776
--- /dev/null
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/PathToUriMappingServiceImpl.java
@@ -0,0 +1,226 @@
+/*
+ * 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.resourceresolver.impl.urimapping;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.api.resource.mapping.PathToUriMappingService;
+import org.apache.sling.api.uri.SlingUri;
+import org.apache.sling.api.uri.SlingUriBuilder;
+import org.apache.sling.resourceresolver.impl.JcrNamespaceMangler;
+import org.apache.sling.spi.urimapping.SlingUriMapper;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component
+public class PathToUriMappingServiceImpl implements PathToUriMappingService {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PathToUriMappingServiceImpl.class);
+
+ private static final String KEY_INTIAL = "intial";
+ private static final String SUBSERVICE_NAME_MAPPING = "mapping";
+
+ @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
+ volatile List resourceMappers;
+
+ @Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
+ volatile ResourceResolverFactory resourceResolverFactory;
+
+ JcrNamespaceMangler jcrNamespaceMangler = new JcrNamespaceMangler();
+
+ @Activate
+ public void activate() {
+
+ if (resourceMappers != null) {
+ String resourceMappersStr = resourceMappers.stream().map(rm -> rm.getClass().toString()).collect(Collectors.joining("\n"));
+ LOG.info("Available Resource Mappers:\n{}", resourceMappersStr);
+ } else {
+ LOG.info("No Resource Mappers available");
+ }
+ }
+
+ public List getAvailableResourceMappers() {
+ return resourceMappers.stream().map(rm -> rm.getClass().toString()).collect(Collectors.toList());
+ }
+
+ @NotNull
+ public MappingChainResult map(@Nullable HttpServletRequest request, @NotNull String resourcePath) {
+
+ try (ResourceResolver rr = getResourceResolver()) {
+ MappingChainContextInternal mappingContext = new MappingChainContextInternal(rr);
+ SlingUri resourceUri = SlingUriBuilder.parse(resourcePath, rr).build();
+ addIntermediateMapping(mappingContext, resourceUri, KEY_INTIAL);
+ if (resourceMappers != null) {
+ for (SlingUriMapper mapper : resourceMappers) {
+ String mapperName = mapper.getClass().getName();
+ LOG.trace("map(): Using {} for {}", mapperName, resourceUri);
+ SlingUri input = resourceUri;
+ resourceUri = mapper.map(resourceUri, request, mappingContext);
+ if (input != resourceUri) {
+ addIntermediateMapping(mappingContext, resourceUri, mapperName);
+ }
+
+ if (chancelChain(mappingContext, mapperName)) {
+ break;
+ }
+ }
+ }
+
+ if (LOG.isDebugEnabled()) {
+ logResult(mappingContext, "map()");
+ }
+
+ return new MappingChainResult(resourceUri, mappingContext.getIntermediateMappings());
+ }
+ }
+
+ @NotNull
+ public MappingChainResult resolve(@Nullable HttpServletRequest request, @Nullable String path) {
+
+ if (request == null) {
+ throw new IllegalArgumentException("Parameter HttpServletRequest must not be null");
+ }
+
+ try (ResourceResolver rr = getResourceResolver()) {
+
+ MappingChainContextInternal mappingContext = new MappingChainContextInternal(rr);
+
+ SlingUri resourceUri = path != null ? SlingUriBuilder.parse(unmangleNamespaces(path, rr), rr).build()
+ : getSlingUriFromRequest(request, rr);
+ addIntermediateMapping(mappingContext, resourceUri, KEY_INTIAL);
+ if (resourceMappers != null) {
+ for (SlingUriMapper mapper : reversedList(resourceMappers)) {
+ String mapperName = mapper.getClass().getName();
+ LOG.trace("resolve(): Using {} for {}", mapperName, resourceUri);
+ SlingUri input = resourceUri;
+ resourceUri = mapper.resolve(resourceUri, request, mappingContext);
+ if (input != resourceUri) {
+ addIntermediateMapping(mappingContext, resourceUri, mapperName);
+ }
+
+ if (chancelChain(mappingContext, mapperName)) {
+ break;
+ }
+ }
+ }
+
+ if (LOG.isDebugEnabled()) {
+ logResult(mappingContext, "resolve()");
+ }
+
+ return new MappingChainResult(resourceUri, mappingContext.getIntermediateMappings());
+ }
+
+ }
+
+ private String unmangleNamespaces(String path, ResourceResolver rr) {
+ return jcrNamespaceMangler.unmangleNamespaces(rr, LOG, path);
+ }
+
+
+ private boolean chancelChain(MappingChainContextInternal mappingContext, String name) {
+ if (mappingContext.isMarkedAsSkipRemainingChain()) {
+ LOG.debug("{} cancelled remaining chain", name);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private void addIntermediateMapping(MappingChainContextInternal mappingContext, SlingUri resourceUri, String name) {
+ mappingContext.addIntermediateMapping(name, resourceUri);
+ LOG.trace("{} ajusted SlingUri: {}", name, resourceUri);
+ }
+
+ private List reversedList(List list) {
+ List reversedList = new ArrayList<>(list);
+ Collections.reverse(reversedList);
+ return reversedList;
+ }
+
+ private void logResult(MappingChainContextInternal mappingContext, String method) {
+ Map intermediateMappings = mappingContext.getIntermediateMappings();
+ if (intermediateMappings.size() == 1) {
+ LOG.debug("\n{}:\nUNCHANGED {}", method, intermediateMappings.values().iterator().next());
+ } else {
+ LOG.debug("\n{}:\n{}", method,
+ intermediateMappings.entrySet().stream()
+ .map(e -> StringUtils.leftPad(e.getKey().replaceAll("([a-z])[^.]*\\.(?=.*\\..*$)", "$1."), 50) + " -> "
+ + e.getValue())
+ .collect(Collectors.joining("\n")));
+ }
+ }
+
+ protected ResourceResolver getResourceResolver() {
+
+ try {
+ final Map authenticationInfo = new HashMap<>();
+ authenticationInfo.put(ResourceResolverFactory.SUBSERVICE, SUBSERVICE_NAME_MAPPING);
+ ResourceResolver serviceResourceResolver = resourceResolverFactory.getServiceResourceResolver(authenticationInfo);
+ return serviceResourceResolver;
+ } catch (LoginException e) {
+ throw new IllegalStateException("Cannot create ResourceResolver: " + e, e);
+ }
+ }
+
+ private SlingUri getSlingUriFromRequest(final HttpServletRequest request, ResourceResolver rr) {
+ final StringBuilder sb = new StringBuilder();
+ if (request.getServletPath() != null) {
+ sb.append(request.getServletPath());
+ }
+ if (request.getPathInfo() != null) {
+ sb.append(request.getPathInfo());
+ }
+ String path = sb.toString();
+ // Get the path used to select the authenticator, if the SlingServlet
+ // itself has been requested without any more info, this will be empty
+ // and we assume the root (SLING-722)
+ if (path.length() == 0) {
+ path = "/";
+ }
+
+ return SlingUriBuilder.create()
+ .setResourceResolver(rr)
+ .setScheme(request.getScheme())
+ .setHost(request.getServerName())
+ .setPort(request.getServerPort())
+ .setPath(unmangleNamespaces(path, rr))
+ .setQuery(request.getQueryString())
+ .build();
+ }
+}
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/EtcMappingResourceResolverTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/EtcMappingResourceResolverTest.java
index ca2d6a640..380be0a7d 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/EtcMappingResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/EtcMappingResourceResolverTest.java
@@ -16,6 +16,31 @@
*/
package org.apache.sling.resourceresolver.impl;
+import static java.util.Arrays.asList;
+import static org.apache.sling.resourceresolver.impl.MockedResourceResolverImplTest.createRPHandler;
+import static org.apache.sling.resourceresolver.impl.ResourceResolverImpl.PROP_REDIRECT_INTERNAL;
+import static org.apache.sling.resourceresolver.impl.mapping.MapEntries.PROP_REDIRECT_EXTERNAL;
+import static org.apache.sling.resourceresolver.util.MockTestUtil.buildResource;
+import static org.apache.sling.resourceresolver.util.MockTestUtil.callInaccessibleMethod;
+import static org.apache.sling.resourceresolver.util.MockTestUtil.checkInternalResource;
+import static org.apache.sling.resourceresolver.util.MockTestUtil.checkRedirectResource;
+import static org.apache.sling.resourceresolver.util.MockTestUtil.createRequestFromUrl;
+import static org.apache.sling.resourceresolver.util.MockTestUtil.createStringInterpolationProviderConfiguration;
+import static org.apache.sling.resourceresolver.util.MockTestUtil.setInaccessibleField;
+import static org.apache.sling.resourceresolver.util.MockTestUtil.setupStringInterpolationProvider;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
@@ -23,12 +48,14 @@
import org.apache.sling.api.resource.path.Path;
import org.apache.sling.resourceresolver.impl.mapping.MapConfigurationProvider;
import org.apache.sling.resourceresolver.impl.mapping.MapEntries;
-import org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProviderConfiguration;
import org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProvider;
+import org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProviderConfiguration;
import org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProviderImpl;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker;
+import org.apache.sling.resourceresolver.util.MockTestUtil;
+import org.apache.sling.resourceresolver.util.MockTestUtil.ExpectedEtcMapping;
import org.apache.sling.serviceusermapping.ServiceUserMapper;
import org.apache.sling.spi.resource.provider.ResourceProvider;
import org.junit.Before;
@@ -39,31 +66,6 @@
import org.osgi.framework.BundleContext;
import org.osgi.service.event.EventAdmin;
-import javax.servlet.http.HttpServletRequest;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import static java.util.Arrays.asList;
-import static org.apache.sling.resourceresolver.impl.MockedResourceResolverImplTest.createRPHandler;
-import static org.apache.sling.resourceresolver.impl.ResourceResolverImpl.PROP_REDIRECT_INTERNAL;
-import static org.apache.sling.resourceresolver.impl.mapping.MapEntries.PROP_REDIRECT_EXTERNAL;
-import static org.apache.sling.resourceresolver.util.MockTestUtil.ExpectedEtcMapping;
-import static org.apache.sling.resourceresolver.util.MockTestUtil.buildResource;
-import static org.apache.sling.resourceresolver.util.MockTestUtil.callInaccessibleMethod;
-import static org.apache.sling.resourceresolver.util.MockTestUtil.checkInternalResource;
-import static org.apache.sling.resourceresolver.util.MockTestUtil.checkRedirectResource;
-import static org.apache.sling.resourceresolver.util.MockTestUtil.createRequestFromUrl;
-import static org.apache.sling.resourceresolver.util.MockTestUtil.createStringInterpolationProviderConfiguration;
-import static org.apache.sling.resourceresolver.util.MockTestUtil.setInaccessibleField;
-import static org.apache.sling.resourceresolver.util.MockTestUtil.setupStringInterpolationProvider;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
/**
* These are the same tests as in the EtcMappingMapEntriesTest but in this
* class we are actually mocking the Resource Resolver Factory and its classes
@@ -130,6 +132,8 @@ public void setup() throws Exception {
setInaccessibleField("observationPaths", activator, new Path[] {new Path("/")});
ServiceUserMapper serviceUserMapper = mock(ServiceUserMapper.class);
setInaccessibleField("serviceUserMapper", activator, serviceUserMapper);
+ setInaccessibleField("pathToUriMappingService", activator, MockTestUtil.createPathToUriMappingServiceMock(resourceResolver));
+
commonFactory = spy(new CommonResourceResolverFactoryImpl(activator));
when(bundleContext.getBundle()).thenReturn(bundle);
when(bundleContext.getDataFile("vanityBloomFilter.txt")).thenReturn(vanityBloomFilterFile);
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
index b960a8210..b853473d5 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
@@ -42,6 +42,7 @@
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.apache.sling.resourceresolver.impl.mapping.MapEntries;
import org.apache.sling.resourceresolver.impl.observation.ResourceChangeListenerWhiteboard;
@@ -49,6 +50,7 @@
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker;
+import org.apache.sling.resourceresolver.util.MockTestUtil;
import org.apache.sling.serviceusermapping.ServiceUserMapper;
import org.apache.sling.spi.resource.provider.QueryLanguageProvider;
import org.apache.sling.spi.resource.provider.ResolveContext;
@@ -141,7 +143,12 @@ public MockedResourceResolverImplTest() {
@SuppressWarnings("unchecked")
@Before
public void before() throws LoginException {
- activator = new ResourceResolverFactoryActivator();
+ activator = new ResourceResolverFactoryActivator() {
+ @Override
+ public PathToUriMappingService getPathToUriMappingService() {
+ return MockTestUtil.createPathToUriMappingServiceMock(null);
+ }
+ };
// system bundle access
final Bundle systemBundle = Mockito.mock(Bundle.class);
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/ProviderHandlerTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/ProviderHandlerTest.java
index d9592c498..20b3d17a7 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/ProviderHandlerTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/ProviderHandlerTest.java
@@ -34,6 +34,7 @@
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider;
+import org.apache.sling.resourceresolver.util.MockTestUtil;
import org.apache.sling.spi.resource.provider.ResolveContext;
import org.apache.sling.spi.resource.provider.ResourceContext;
import org.apache.sling.spi.resource.provider.ResourceProvider;
@@ -67,6 +68,7 @@ public ResourceProviderStorage getResourceProviderStorage() {
return new ResourceProviderStorage(Arrays.asList(h));
}
});
+ activator.pathToUriMappingService = MockTestUtil.createPathToUriMappingServiceMock(resolver);
final Resource parent = resolver.getResource(ResourceUtil.getParent(servletpath));
assertNotNull("Parent must be available", parent);
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTestBase.java b/src/test/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTestBase.java
index 821317944..679587553 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTestBase.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTestBase.java
@@ -36,10 +36,12 @@
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider;
+import org.apache.sling.resourceresolver.util.MockTestUtil;
import org.apache.sling.spi.resource.provider.QueryLanguageProvider;
import org.apache.sling.spi.resource.provider.ResolveContext;
import org.apache.sling.spi.resource.provider.ResourceContext;
@@ -141,6 +143,11 @@ public ResourceDecoratorTracker getResourceDecoratorTracker() {
public ResourceAccessSecurityTracker getResourceAccessSecurityTracker() {
return new ResourceAccessSecurityTracker();
}
+
+ @Override
+ public PathToUriMappingService getPathToUriMappingService() {
+ return MockTestUtil.createPathToUriMappingServiceMock(null);
+ }
};
final List list = Arrays.asList(MockedResourceResolverImplTest.createRPHandler(provider, "A-provider", 0L, "/"));
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
index 3eee2cfe5..fde657b5d 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
@@ -52,6 +52,7 @@
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker;
+import org.apache.sling.resourceresolver.util.MockTestUtil;
import org.apache.sling.spi.resource.provider.ResolveContext;
import org.apache.sling.spi.resource.provider.ResourceContext;
import org.apache.sling.spi.resource.provider.ResourceProvider;
@@ -91,6 +92,7 @@ public Iterator listChildren(ResolveContext