Cette conversation a été verrouillée en raison de son inactivité. Veuillez créer une nouvelle publication.
Niveau 1
Niveau 2
Se connecter à la communauté
Connectez-vous pour voir tous les badges
Cette conversation a été verrouillée en raison de son inactivité. Veuillez créer une nouvelle publication.
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/... 😞
@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!
Résolu ! Accéder à la solution.
Vues
Réponses
Nombre de J’aime
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.
Vues
Réponses
Nombre de J’aime
You need to use a System user and Sling Mapping as you do when you get a Session object.
Vues
Réponses
Nombre de J’aime
smacdonald2008 I have a service user and the 'Apache Sling Service User Mapper Service' has the default user set to this user. Am I missing something?
Vues
Réponses
Nombre de J’aime
You are missing the code required to create a ResourceResolver. I did not see it in that link.
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;
try {
//Create a valid ResourceResolver
resolver = resolverFactory.getServiceResourceResolver(param);
.
See this article -- Scott's Digital Community: Querying Adobe Experience Manager 6 data using the Sling getServiceResour...
Vues
Réponses
Nombre de J’aime
Hey,
Scott is right. In order to create ResourceResolver, you have to use mentioned code:
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;
try {
//Create a valid ResourceResolver
resolver = resolverFactory.getServiceResourceResolver(param);
~Ratna
Vues
Réponses
Nombre de J’aime
I added the following line in the 'Apache Sling Service User Mapper Service':
aem-company-platform-core-bundle:datawrite=platform-company-service (NOTE: aem-company-platform-core-bundle is the symbolic bundle name)
And I have the following code:
//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;
@Override
public Resource getResource(ResolveContext<DoesNotNeedAContext> resolveContext, String s, ResourceContext resourceContext, Resource resource) {
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;
//Create a valid ResourceResolver
try {
resolver = resolverFactory.getServiceResourceResolver(param);
Resource thisResouceIsNull = resolver.getResource("/content/we-retail");
} catch (LoginException e) {
e.printStackTrace();
}
return null;
}
I still get null If I try to get a resource using that resolver:
Is something still missing?
Vues
Réponses
Nombre de J’aime
Post screen shot of the Sling Mapping Service. Make sure you are specifying the correct Symbolic Bundle name in that service.
Vues
Réponses
Nombre de J’aime
Mapper service: Apache Sling Service User Mapper Service - Album on Imgur
Bundle that contains the class: Bundle - Album on Imgur
System User: System User - Album on Imgur
Vues
Réponses
Nombre de J’aime
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.
Vues
Réponses
Nombre de J’aime
I was missing the correct permission, thank you very much both of you! ![]()
Vues
Réponses
Nombre de J’aime
Can you please send me an email at scottm@adobe.com -- thxs!
Vues
Réponses
Nombre de J’aime
Get the resource Resolver in Sling Model without using SlingHttpServletRequest.
Vues
Réponses
Nombre de J’aime
Vues
Likes
Réponses