09-09-2013 10:40 AM
I'm trying to invoke Nuxeo Services by local API, but I obtain NullPointerException.
I see in the documentation,
The services can be local (inside the same JVM) and most of them can be Also called remotely via RMI if your target Application Server supports EJB3 remoting.
I would like to call upon the services of Nuxeo from "local", ie with a java client within the same JVM of Nuxeo. This need arises from having to perform operations that are not supported by remote clients documented. For example, do the tagging of a document. I tried to write the following code but I obtain a NullPointerException. Probably, I'm missing some basic concept.
I wrote java code in a jsp: **<%
LocalSessionFactory lsf = new LocalSessionFactory();
CoreSession session = lsf.getSession();
TagService tsi = Framework.getService(TagService.class);
tsi.tag(session, "2b1eefa4-81ee-4d0f-8bcb-24f5e9745f96", "trytag","Administrator");
%>**
Exception stacktrace logs:
143: CoreSession csession = lsf.getSession();
144:
145: TagService tsi = Framework.getService(TagService.class);
146: tsi.tag(csession, "2b1eefa4-81ee-4d0f-8bcb-24f5e9745f96","trytag","Administrator");
147:
148:
149:
Stacktrace:
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.nuxeo.wss.servlet.BaseWSSFilter.doFilter(BaseWSSFilter.java:137)
at org.nuxeo.wss.servlet.FailSafeWSSFilter.doFilter(FailSafeWSSFilter.java:55)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.nuxeo.ecm.platform.ui.web.rest.FancyURLFilter.doFilter(FancyURLFilter.java:129)
... 24 more
Caused by: java.lang.NullPointerException
at org.nuxeo.ecm.core.api.local.LocalSession.getPrincipal(LocalSession.java:164)
at org.nuxeo.ecm.core.api.UnrestrictedSessionRunner.isUnrestricted(UnrestrictedSessionRunner.java:103)
at org.nuxeo.ecm.core.api.UnrestrictedSessionRunner.
Thank you!
09-11-2013 08:59 AM
The session you use is not associated with an authenticated login, it has no principal. You should retrieve it from the context or the request. Also give a look at CoreInstance rather than a direct call to LocalSessionFactory.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.