How to invoke Nuxeo services by local Java API?

I'm trying to invoke Nuxeo Services by local API, but I obtain NullPointerException.

I see in the documentation,

How to invoke services:

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(
    at org.apache.jasper.servlet.JspServletWrapper.service(
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(
    at org.apache.jasper.servlet.JspServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    at org.nuxeo.wss.servlet.BaseWSSFilter.doFilter(
    at org.nuxeo.wss.servlet.FailSafeWSSFilter.doFilter(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    ... 24 more

Caused by: java.lang.NullPointerException

    at org.nuxeo.ecm.core.api.local.LocalSession.getPrincipal(
    at org.nuxeo.ecm.core.api.UnrestrictedSessionRunner.isUnrestricted(
    at org.nuxeo.ecm.core.api.UnrestrictedSessionRunner.<init>(
    at org.nuxeo.ecm.platform.tag.TagServiceImpl$UnrestrictedAddTagging.<init>(
    at org.nuxeo.ecm.platform.tag.TagServiceImpl.tag(
    at org.apache.jsp.prova_jsp._jspService(
    at org.apache.jasper.runtime.HttpJspBase.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.jasper.servlet.JspServletWrapper.service(
    ... 34 more*

Thank you!

0 votes

1 answers



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.

1 votes