Expand my Community achievements bar.

SOLVED

help with javax.jcr.NamespaceException (Unknown namespace URI). Thanks!

Avatar

Level 9

Line 67 of the error message (see below) is the adaptTo line

import com.adobe.granite.security.user.UserProperties;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;

ResourceResolver resolver = request.getResourceResolver();
UserProperties userProperties = resolver.adaptTo(UserProperties.class);

 

error message

21.03.2022 15:30:09.630 *ERROR* [10.46.0.17 [1647837009626] GET /services/portal/myservice.json HTTP/1.1] com.adobe.granite.security.user.internal.UserPropertiesServiceImpl Could not adapt org.apache.sling.resourceresolver.impl.ResourceResolverImpl@488d2e95 to com.adobe.granite.security.user.UserPropertiesManager
javax.jcr.NamespaceException: Unknown namespace URI: http://sling.apache.org/jcr/sling/1.0
        at org.apache.jackrabbit.oak.jcr.session.SessionNamespaces.getNamespacePrefix(SessionNamespaces.java:154) [org.apache.jackrabbit.oak-jcr:1.22.4]
        at org.apache.jackrabbit.oak.jcr.session.SessionImpl.getNamespacePrefix(SessionImpl.java:757) [org.apache.jackrabbit.oak-jcr:1.22.4]
        at com.adobe.granite.repository.impl.CRX3SessionImpl.getNamespacePrefix(CRX3SessionImpl.java:288) [com.adobe.granite.repository:1.6.28.CQ650-B0001]
        at com.adobe.granite.security.user.internal.UserPropertiesManagerImpl.<init>(UserPropertiesManagerImpl.java:111) [com.adobe.granite.security.user:0.4.62]
        at com.adobe.granite.security.user.internal.UserPropertiesServiceImpl.createUserPropertiesManager(UserPropertiesServiceImpl.java:130) [com.adobe.granite.security.user:0.4.62]
        at com.adobe.granite.security.user.internal.UserPropertiesServiceImpl.getAdapter(UserPropertiesServiceImpl.java:334) [com.adobe.granite.security.user:0.4.62]
        at org.apache.sling.adapter.internal.AdapterManagerImpl.getAdapter(AdapterManagerImpl.java:143) [org.apache.sling.adapter:2.1.10]
        at org.apache.sling.api.adapter.SlingAdaptable.adaptTo(SlingAdaptable.java:104) [org.apache.sling.api:2.20.0]
        at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.adaptTo(ResourceResolverImpl.java:635) [org.apache.sling.resourceresolver:1.6.8]
        at com.day.cq.personalization.impl.DefaultProfileProvider.getUserProperties(DefaultProfileProvider.java:110) [com.day.cq.cq-personalization:5.12.40]
        at com.day.cq.personalization.impl.ProfileAdapterFactory.getUserProperties(ProfileAdapterFactory.java:123) [com.day.cq.cq-personalization:5.12.40]
        at com.day.cq.personalization.impl.ProfileAdapterFactory.getAdapter(ProfileAdapterFactory.java:77) [com.day.cq.cq-personalization:5.12.40]
        at com.day.cq.personalization.impl.ProfileAdapterFactory.getAdapter(ProfileAdapterFactory.java:66) [com.day.cq.cq-personalization:5.12.40]
        at org.apache.sling.adapter.internal.AdapterManagerImpl.getAdapter(AdapterManagerImpl.java:143) [org.apache.sling.adapter:2.1.10]
        at org.apache.sling.api.adapter.SlingAdaptable.adaptTo(SlingAdaptable.java:104) [org.apache.sling.api:2.20.0]
        at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.adaptTo(ResourceResolverImpl.java:635) [org.apache.sling.resourceresolver:1.6.8]
        at com.myapp.core.servlets.MyServlet2.doGet(MyServlet2.java:67)

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

try with User class, if it helps

 

import org.apache.jackrabbit.api.security.user.User;

 

User currentUser = request.getResourceResolver().adaptTo(User.class);



Arun Patidar

View solution in original post

4 Replies

Avatar

Employee Advisor

This is very simple servlet and just to test I was trying to understand issue with adaptTo here -

 

package com.aem.demo.core.servlets;

import java.io.IOException;

import javax.jcr.RepositoryException;
import javax.servlet.Servlet;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;

import com.adobe.granite.security.user.UserProperties;

@component(service = Servlet.class, property = { "sling.servlet.paths=" + "/bin/username",
"sling.servlet.methods=" + HttpConstants.METHOD_GET })
public class UserPropertiesServlet extends SlingAllMethodsServlet {




/**
*
*/
private static final long serialVersionUID = -3561858749807565841L;

protected void doGet(SlingHttpServletRequest slingHttpServletRequest, SlingHttpServletResponse slingHttpServletResponse) {

ResourceResolver resourceResolver = slingHttpServletRequest.getResourceResolver();

UserProperties userProperties = resourceResolver.adaptTo(UserProperties.class);
try {
slingHttpServletResponse.getWriter().write(userProperties.getDisplayName());
} catch (IOException | RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

 

But I didn't face such problem and here is the servlet response -

DEBAL_DAS_0-1648008160506.png

Could you please tell me what are you trying to achieve via the servlet or code overview.

Avatar

Level 9

the error does NOT happen all the time.

 

I'm trying to read user properties.

Avatar

Employee Advisor

Are you facing this intermittent issue on publish instance? how are you accessing it?

Avatar

Correct answer by
Community Advisor

try with User class, if it helps

 

import org.apache.jackrabbit.api.security.user.User;

 

User currentUser = request.getResourceResolver().adaptTo(User.class);



Arun Patidar