AEM 6.3 ResourceProvider resourceResolve.getResource always returns null | Community
Skip to main content
Level 4
Aug 21, 2017 1:35 PM UTC
Solved

AEM 6.3 ResourceProvider resourceResolve.getResource always returns null

I am having trouble solving the following issue: I have a ResourceProvider with a root mapped at '/synthetic/config'. In the getResource() method I retrieve the resourceResolver and try to fetch the resource (this resource does exists!) but this never succeeds, I always get a 'null'.

Here is my code (I based mine on https://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservic…  ):

@Component

@Service(value=ResourceProvider.class)

@Properties({

        @Property(name = ResourceProvider.PROPERTY_NAME, value = "Planets"),

        @Property(name = ResourceProvider.PROPERTY_ROOT, value= ConfigResourceProvider.SYNTHETIC_CONFIG_ROOT)

})

public class ConfigResourceProvider extends ResourceProvider<ConfigResourceProvider.DoesNotNeedAContext> {

    public static final String SYNTHETIC_CONFIG_ROOT = "/synthetic/config";

    @Override

    public Resource getResource(ResolveContext<DoesNotNeedAContext> resolveContext, String s, ResourceContext resourceContext, Resource resource) {

        Resource resource1 = resolveContext.getResourceResolver().getResource("/content/we-retail");

        return null;

    }

    @Override

    public Iterator<Resource> listChildren(ResolveContext<DoesNotNeedAContext> resolveContext, Resource resource) {

        return null;

    }

    /** If this provider required a context this would be more elaborate,

     *  but for this simple example we don't need one.

     */

    public static class DoesNotNeedAContext {

    };

}

How can I fix this? Thanks in advance!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Aug 21, 2017 7:12 PM UTC

IS that the value that appears when you open the Manifest file in the bundle? You need to make sure they match exactly. Also make sure the system user has the correct permissions. These are 2 things that can explain the null.

11 replies

smacdonald2008
Level 10
Aug 21, 2017 1:47 PM UTC

You need to use a System user and Sling Mapping as you do when you get a Session object.

Translate