Skip to content

Nuxeo quick reference

Jeremie Guillemotte edited this page Jun 25, 2013 · 28 revisions

Nuxeo quick reference

Code & configuration

Nuxeo Document Model

Nuxeo JSF (Document) Layout

Nuxeo WebEngine Freemarker templates quick reference :

Available context variables are : (as seen in AbstractWebContext and at http://doc.nuxeo.com/pages/viewpage.action?pageId=11044493 )

  • Context : the View extending AbstractWebContext, which provides : i18n (module's messages) & locale, logging, cookies, principal (user), properties (context variables shared among scripts), user session, running scripts, loginPath, headers, request, form and everything below (path /url...)
  • Root : the controller. So you can put there (or in the ModuleRoot class it extends) code available here that requires the request.
  • Module : NOT your own module Class. Provides class loading, adapters & resources, validators.
  • Runtime : Framework.getRuntime()
  • Engine : WebEngine
  • basePath : /nuxeo/site
  • skinPath : /nuxeo/site/skin/easysoa
  • contextPath : /nuxeo
  • This : the Web Object if any
  • Document : its (adapted) DocumentModel if any
  • Adapter : the adapter of the first WebEngine resource having one, starting from the controller
  • Session : CoreSession
  • & what's put by controller

FAQ

See also Developing on the service registry.

General FAQ

How can I reset all Nuxeo data?

Simply remove the nxserver/data folder from Nuxeo (in the EasySOA package, Nuxeo is filed under the serviceregistry folder).

Enabling remote debugging

Open bin/nuxeo.conf and uncomment the "DEBUGGING" options line:

        # Sample JPDA settings for remote socket debugging
        JAVA_OPTS=$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

You can switch suspend=n to suspend=y if you want to monitor Nuxeo right from the start (Java will wait for you to connect with Eclipse before to start Nuxeo).

Connecting to Nuxeo CMIS

You can use a special software like (CMIS Workbench)[http://chemistry.apache.org/java/developing/tools/dev-tools-workbench.html]. The address where the Nuxeo CMIS is published is : [http://localhost:8080/nuxeo/atom/cmis]

Junit test FAQ

Guice provision errors (CoreSession)

Error :

      com.google.inject.ProvisionException: Guice provision errors: 

      1) null returned by binding at org.nuxeo.runtime.test.runner.RuntimeFeature.bind0(RuntimeFeature.java:196)
       but org.nuxeo.snapshot.AbstractTestSnapshot.session is not @Nullable
        at org.nuxeo.runtime.test.runner.RuntimeFeature.bind0(RuntimeFeature.java:196)
        while locating org.nuxeo.ecm.core.api.CoreSession 

Solution :

In your test annotations, change cleanup to Granularity.CLASS in

    @RepositoryConfig(type = BackendType.H2, init = PublishRepositoryInit.class, user = "Administrator", cleanup = Granularity.METHOD)

JSF FAQ

String concatenation in EL (Expression Language)

It is not done by "+" but by either by putting them along each other in an EL expression, [using <c:set var="s" value="${s1} ${s2}"/> beforehand] (http://stackoverflow.com/questions/296398/concatenate-strings-in-jsp-el), or defining a [custom concat() function] (http://stackoverflow.com/questions/2192759/concatenate-strings-in-jsf-jsp-el-and-javascript).

Overriding

What nxd:xxx JSF functions are available ?

See nxweb document tld or javadoc.

JAX RS

REST HOWTO

@GET
@Path("/getExchangeRecordStorelist")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public StoreCollection getExchangeRecordStorelist() { ...

@Produces to tell that the returned type can be a json string. The returned java object, here StoreCollection must have some annotations :

@XmlRootElement
public class StoreCollection {

    private Collection<ExchangeRecordStore> stores;
    ...
    @XmlElement(name="ExchangeRecordStore")
    @XmlElementWrapper(name="stores")
    public Collection<ExchangeRecordStore> getStores() {
        return stores;
    }
}

How to build a mock server with Nuxeo Web Engine ?

Simply create a class that extends ModuleRoot class. Then add JAX-RS annotations to publish the service and at least one method to generate the response. You have to create a contrib file in OSGI-INF folder to start the mock in Nuxeo.

For a complete example see the MockServer class and the contrib file.

Source code for the mock class

@Path("/mock")
@Produces("text/xml;charset=UTF-8")
@WebObject(type = "MockServer")
public class MockServer extends ModuleRoot {

    @GET
    @Path("wsdl/{wsdlResource}")
    public Object doGet(@PathParam("wsdlResource") String wsdlResource) throws Exception {
        ...
        // Get the wsdl file list
        ....
        for(File file : fileList){
            // If the requested file is in the list return it
            if(file.getName().toLowerCase().contains(wsdlResource.toLowerCase())){
                return FileUtils.readFileToString(file);
            }
        }
        throw new Exception("Resource '" + wsdlResource + "' not found");
     }
    
}

Source code for the contrib file

<?xml version="1.0" encoding="UTF-8"?>
<component name="org.easysoa.registry.doctypes.core.mock.wsdlMockServer" version="1.0">
    <implementation class="org.easysoa.registry.mock.MockServer" />
</component>
Clone this wiki locally