From: Sanjay Dalal Date: Tue, 6 Oct 2009 22:14:58 +0000 (+0000) Subject: CSPACE-492 removed forced connection on the nuxeo client while obtaining every sessio... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5c072c41e96af155da66062ae50fc9afece34674;p=tmp%2Fjakarta-migration.git CSPACE-492 removed forced connection on the nuxeo client while obtaining every session. reuses client and reauthenticates on every use. tests: mvn test passes at the top level, still to test on linux platform. --- diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnector.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnector.java index de56a8a57..604d64768 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnector.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnector.java @@ -31,6 +31,7 @@ import org.collectionspace.services.common.RepositoryClientConfigType; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; +import org.nuxeo.ecm.core.client.DefaultLoginHandler; import org.nuxeo.ecm.core.client.NuxeoApp; import org.nuxeo.ecm.core.client.NuxeoClient; import org.slf4j.Logger; @@ -80,6 +81,15 @@ public class NuxeoConnector { } loadBundles(); client = NuxeoClient.getInstance(); + DefaultLoginHandler loginHandler = new DefaultLoginHandler( + repositoryClientConfig.getUser(), repositoryClientConfig.getPassword()); + client.setLoginHandler(loginHandler); + client.connect(repositoryClientConfig.getHost(), + repositoryClientConfig.getPort()); + if(logger.isDebugEnabled()){ + logger.debug("initialize(): connection successful port=" + + repositoryClientConfig.getPort()); + } initialized = true; }catch(Exception e){ if(logger.isDebugEnabled()){ @@ -151,18 +161,17 @@ public class NuxeoConnector { */ public NuxeoClient getClient() throws Exception { if(initialized == true){ -// if(client.isConnected()){ -// return client; -// }else{ - //authentication failure error comes when reusing the client - //force connect for now - client.forceConnect(repositoryClientConfig.getHost(), repositoryClientConfig.getPort()); - if(logger.isDebugEnabled()){ - logger.debug("getClient(): connection successful port=" + - repositoryClientConfig.getPort()); + if(client.isConnected()){ + client.login(); + return client; + }else{ + client.forceConnect(repositoryClientConfig.getHost(), repositoryClientConfig.getPort()); + if(logger.isDebugEnabled()){ + logger.debug("getClient(): connection successful port=" + + repositoryClientConfig.getPort()); + } + return client; } - return client; -// } } String msg = "NuxeoConnector is not initialized!"; logger.error(msg); @@ -214,10 +223,10 @@ public class NuxeoConnector { while(diter.hasNext()){ DocumentModel domain = diter.next(); String domainPath = "/" + tenantDomain; - if(!domain.getPathAsString().equalsIgnoreCase(domainPath)) { + if(!domain.getPathAsString().equalsIgnoreCase(domainPath)){ continue; } - if(logger.isDebugEnabled()) { + if(logger.isDebugEnabled()){ logger.debug("domain=" + domain.toString()); } DocumentModelList domainChildrenList = repoSession.getChildren(domain.getRef());