2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package org.collectionspace.services.nuxeo;
8 import java.util.Collection;
9 import org.nuxeo.ecm.core.client.NuxeoApp;
10 import org.nuxeo.ecm.core.client.NuxeoClient;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
15 * NuxeoConnector is a facade to Nuxeo remoting client
18 public class NuxeoConnector {
19 //FIXME: get port and host from configuration
20 public static int NUXEO_PORT = 62474;
21 public static String NUXEO_HOST = "localhost";
22 private Logger logger = LoggerFactory.getLogger(NuxeoConnector.class);
23 private static final NuxeoConnector self = new NuxeoConnector();
25 private NuxeoClient client;
26 volatile boolean initialized = false; //use volatile for lazy initialization in singleton
28 private NuxeoConnector() {
31 public final static NuxeoConnector getInstance() {
35 public void initialize() throws Exception {
38 if(initialized == false){
42 if(logger.isDebugEnabled()) {
43 logger.debug("initialize() NuxeoApp started");
46 client = NuxeoClient.getInstance();
50 if(logger.isDebugEnabled()){
56 private void loadBundles() throws Exception {
57 String bundles = "nuxeo-client/lib/nuxeo-runtime-*:nuxeo-client/lib/nuxeo-*";
58 Collection<File> files = null;
60 files = NuxeoApp.getBundleFiles(new File("."), bundles, ":");
62 if(logger.isDebugEnabled()){
63 logger.debug("loadBundles(): deploying bundles: " + files);
66 app.deployBundles(files);
70 private void setProperties() {
71 System.setProperty("org.nuxeo.runtime.server.enabled", Boolean.FALSE.toString());
72 System.setProperty("org.nuxeo.runtime.server.port", "" + NUXEO_PORT);
73 System.setProperty("org.nuxeo.runtime.server.host", "127.0.0.1");
74 //System.setProperty("org.nuxeo.runtime.1.3.3.streaming.port", "3233");
75 System.setProperty("org.nuxeo.runtime.streaming.serverLocator", "socket://127.0.0.1:3233");
76 System.setProperty("org.nuxeo.runtime.streaming.isServer", Boolean.FALSE.toString());
77 System.setProperty("org.nuxeo.client.remote", Boolean.TRUE.toString());
80 public NuxeoClient getClient() throws Exception {
81 if(initialized == true){
82 // if(client.isConnected()){
85 //authentication failure error comes when reusing the client
86 //fore connect for now
87 client.forceConnect(NUXEO_HOST, NUXEO_PORT);
88 if(logger.isDebugEnabled()){
89 logger.debug("getClient(): connection successful port=" + NUXEO_PORT);
94 String msg = "NuxeoConnector is not initialized!";
96 throw new IllegalStateException(msg);