[Q&A Friday] Embedding Nuxeo?


Fri 17 February 2012 By Laurent Doguin


Embedding Nuxeo? Embedding Nuxeo?

Here is an excellent question from mainzelM. He asks how to embed Nuxeo in his application.

He references the documentation in his answer, which does explain one way your application can interact with Nuxeo. But this is just one of the possible options Nuxeo puts at your fingertips. Let's talk about the others :)

Full Integration with Nuxeo


 

So as you can see from the picture, you have multiple choices.


Integration Examples Integration Examples

 

Embed your application inside Nuxeo Server


Imagine you have a simple webapp with one servlet. All you have to do is put your jar in the lib directory, and declare the servlet in the web.xml. Since Nuxeo has a modular development model, you need to create a new module using the IDE, then add some xml code in the deployment-fragment.
Deployment-fragments are used to generate the usual config files: web.xml, faces-config.xml, and the like.

Here is an example for JavaMelody:

[xml]
<?xml version="1.0"?>
<fragment version="1">

<extension target="web#FILTER">
<filter>
<filter-name>monitoring</filter-name>
<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>monitoring</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</extension>

<extension target="web#LISTENER">
<listener>
<listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>
</extension>

</fragment>
[/xml]

Now put the jar containing this fragment in the plugins folder of your server, and then the JavaMelody jar in the lib folder. And that's it. You're done :)

Use Nuxeo's service from your Java application


You can also embed Nuxeo Client in your java application, which is readily available from our maven repository. The code is quite simple:

[java]
public static void main(String[] args) throws Exception {
HttpAutomationClient client = new HttpAutomationClient(
"http://localhost:8080/nuxeo/site/automation&quot;);

Session session = client.getSession(&quot;Administrator&quot;, &quot;Administrator&quot;);
Documents docs = (Documents) session.newRequest(&quot;Document.Query&quot;).set(
       &quot;query&quot;, &quot;SELECT * FROM Document&quot;).execute();
System.out.println(docs);

client.shutdown();

}
[/java]

And if you need other operations than the default one, it's simple to create your own with Nuxeo IDE.

There is also a nice PHP client on github.

Use Nuxeo's service via WebService


Most Nuxeo services are exposed as Web services. You can choose from a variety:
-ContentAutomation
-WebServices (JAX-RS, JAX-WS...)
-CMIS

Of course, this is the easiest way to interact with Nuxeo if your application is not written in Java.

Embed Nuxeo's services inside your application


And now we come back to the original subject of the question. Be sure to take a look at Martin’s question and the associated documentation for more information on this last option.


Category: Product & Development
Tagged: CMIS, Java, Q&A