Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 34131 invoked from network); 18 Feb 2008 14:55:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Feb 2008 14:55:48 -0000 Received: (qmail 96298 invoked by uid 500); 18 Feb 2008 14:55:43 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 96263 invoked by uid 500); 18 Feb 2008 14:55:43 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 96254 invoked by uid 99); 18 Feb 2008 14:55:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Feb 2008 06:55:43 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Feb 2008 14:55:04 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id ACB241A983A; Mon, 18 Feb 2008 06:55:23 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r628768 - in /incubator/sling/trunk/jcr: base/ base/src/ base/src/main/ base/src/main/java/ base/src/main/java/org/ base/src/main/java/org/apache/ base/src/main/java/org/apache/sling/ base/src/main/java/org/apache/sling/jcr/ base/src/main/j... Date: Mon, 18 Feb 2008 14:55:21 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080218145523.ACB241A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Mon Feb 18 06:55:19 2008 New Revision: 628768 URL: http://svn.apache.org/viewvc?rev=628768&view=rev Log: SLING-254 - JNDI/RMI Repository access code moved to RepositoryAccessor class in new jcr/base module Added: incubator/sling/trunk/jcr/base/ incubator/sling/trunk/jcr/base/pom.xml (with props) incubator/sling/trunk/jcr/base/src/ incubator/sling/trunk/jcr/base/src/main/ incubator/sling/trunk/jcr/base/src/main/java/ incubator/sling/trunk/jcr/base/src/main/java/org/ incubator/sling/trunk/jcr/base/src/main/java/org/apache/ incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/ incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/ incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/ incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/ incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java (with props) Modified: incubator/sling/trunk/jcr/jackrabbit-client/pom.xml incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties Added: incubator/sling/trunk/jcr/base/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/base/pom.xml?rev=628768&view=auto ============================================================================== --- incubator/sling/trunk/jcr/base/pom.xml (added) +++ incubator/sling/trunk/jcr/base/pom.xml Mon Feb 18 06:55:19 2008 @@ -0,0 +1,95 @@ + + + + 4.0.0 + + org.apache.sling + sling + 1-incubator-SNAPSHOT + ../../parent/pom.xml + + + org.apache.sling.jcr.base + bundle + 2.0.0-incubator-SNAPSHOT + + Sling - JCR Base Bundle + + The JCR base bundle provides JCR utility classes + + + + + scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/base + + + scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/base + + + http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/base + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + + sling,jcr,jackrabbit + + + org.apache.sling.jcr.base.util;version=${pom.version}, + + + org.apache.jackrabbit.rmi.* + + + org.apache.xml.*; resolution:=optional, * + + + + + + + + + + javax.jcr + jcr + compile + + + org.apache.jackrabbit + jackrabbit-jcr-rmi + compile + + + org.slf4j + slf4j-simple + + + + Propchange: incubator/sling/trunk/jcr/base/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java?rev=628768&view=auto ============================================================================== --- incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java (added) +++ incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java Mon Feb 18 06:55:19 2008 @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.jcr.base.util; + +import java.util.Hashtable; + +import javax.jcr.Repository; +import javax.naming.InitialContext; + +import org.apache.jackrabbit.rmi.client.ClientAdapterFactory; +import org.apache.jackrabbit.rmi.client.ClientRepositoryFactory; +import org.apache.jackrabbit.rmi.client.LocalAdapterFactory; +import org.apache.jackrabbit.rmi.remote.RemoteRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Access a Repository via JNDI or RMI. */ + public class RepositoryAccessor { + private final Logger log = LoggerFactory.getLogger(getClass()); + + /** Prefix for RMI Repository URLs */ + public static final String RMI_PREFIX = "rmi://"; + + /** First try to access the Repository via JNDI (unless jndiContext is null), and if + * not successful try RMI. + * + * @param repositoryName JNDI name or RMI URL (must start with "rmi://") of the Repository + * @param jndiContext if null, JNDI is not tried + * @return a Repository, or null if not found + */ + public Repository getRepository(String repositoryName, Hashtable jndiContext) { + + Repository result = null; + + if(jndiContext == null) { + log.info("jndiContext is null, not trying JNDI"); + } else { + log.debug("Trying to acquire Repository '" + repositoryName + "' via JNDI, context=" + jndiContext); + final ClassLoader old = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + InitialContext initialContext = new InitialContext(jndiContext); + Object repoObject = initialContext.lookup(repositoryName); + if (repoObject instanceof Repository) { + result = (Repository) repoObject; + log.info("Acquired Repository '" + repositoryName + "' via JNDI"); + + } else if (repoObject instanceof RemoteRepository) { + RemoteRepository remoteRepo = (RemoteRepository) repoObject; + LocalAdapterFactory laf = new ClientAdapterFactory(); + result = laf.getRepository(remoteRepo); + log.info("Acquired RemoteRepository '" + repositoryName + "' via JNDI"); + } + + } catch (Throwable t) { + log.debug("Unable to acquire Repository '" + repositoryName + "' via JNDI, context=" + jndiContext, t); + } finally { + Thread.currentThread().setContextClassLoader(old); + } + } + + if(result == null) { + if(repositoryName==null || !repositoryName.startsWith(RMI_PREFIX)) { + log.info("Repository name does not start with '" + RMI_PREFIX + "', not trying RMI"); + } else { + try { + log.debug("Trying to acquire Repository '" + repositoryName + "' via RMI"); + ClientRepositoryFactory crf = new ClientRepositoryFactory(); + result = crf.getRepository(repositoryName); + log.info("Acquired Repository '" + repositoryName + "' via RMI"); + } catch (Throwable t) { + log.debug("Unable to acquire Repository '" + repositoryName + "' via RMI", t); + } + } + } + + if(result == null) { + log.info("Unable to acquire Repository '" + repositoryName + "'"); + } + + return result; + } +} Propchange: incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: incubator/sling/trunk/jcr/jackrabbit-client/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-client/pom.xml?rev=628768&r1=628767&r2=628768&view=diff ============================================================================== --- incubator/sling/trunk/jcr/jackrabbit-client/pom.xml (original) +++ incubator/sling/trunk/jcr/jackrabbit-client/pom.xml Mon Feb 18 06:55:19 2008 @@ -92,6 +92,12 @@ org.apache.sling + org.apache.sling.jcr.base + 2.0.0-incubator-SNAPSHOT + + + + org.apache.sling org.apache.sling.jcr.api 2.0.0-incubator-SNAPSHOT Modified: incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java?rev=628768&r1=628767&r2=628768&view=diff ============================================================================== --- incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java (original) +++ incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java Mon Feb 18 06:55:19 2008 @@ -24,14 +24,10 @@ import javax.jcr.Repository; import javax.jcr.RepositoryException; -import javax.naming.InitialContext; -import org.apache.jackrabbit.rmi.client.ClientAdapterFactory; -import org.apache.jackrabbit.rmi.client.ClientRepositoryFactory; -import org.apache.jackrabbit.rmi.client.LocalAdapterFactory; -import org.apache.jackrabbit.rmi.remote.RemoteRepository; import org.apache.sling.jcr.api.AbstractSlingRepository; import org.apache.sling.jcr.api.SlingRepository; +import org.apache.sling.jcr.base.util.RepositoryAccessor; import org.osgi.service.log.LogService; /** @@ -111,36 +107,12 @@ throw new RepositoryException("Missing property 'name'"); } - // try JNDI - Hashtable jndiContext = this.fromDictionary(environment); - ClassLoader old = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); - InitialContext initialContext = new InitialContext(jndiContext); - Object repoObject = initialContext.lookup(repoName); - if (repoObject instanceof Repository) { - return (Repository) repoObject; - - } else if (repoObject instanceof RemoteRepository) { - RemoteRepository remoteRepo = (RemoteRepository) repoObject; - LocalAdapterFactory laf = new ClientAdapterFactory(); - return laf.getRepository(remoteRepo); - } - } catch (Throwable t) { - this.getLog().log(LogService.LOG_INFO, "Problem checking JNDI for " + repoName, t); - } finally { - Thread.currentThread().setContextClassLoader(old); + final Hashtable jndiContext = this.fromDictionary(environment); + final Repository repo = new RepositoryAccessor().getRepository(repoName, jndiContext); + if(repo == null) { + throw new RepositoryException("Cannot acquire repository '" + repoName + "'"); } - - try { - ClientRepositoryFactory crf = new ClientRepositoryFactory(); - return crf.getRepository(repoName); - } catch (Throwable t) { - this.getLog().log(LogService.LOG_INFO, "Problem checking RMI for " + repoName, t); - } - - // finally there is no way to find a repository - throw new RepositoryException("Cannot find repository " + repoName); + return repo; } Modified: incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=628768&r1=628767&r2=628768&view=diff ============================================================================== --- incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties (original) +++ incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties Mon Feb 18 06:55:19 2008 @@ -80,5 +80,5 @@ name.name = Repository Name name.description = The name under which the repository will be looked up in \ - the JNDI or RMI. In the case of RMI, this must be a standard RMI URL of the \ - form "//host[:port]/name". \ No newline at end of file + the JNDI or RMI. For RMI, this must be a standard RMI URL of the \ + form "rmi://host[:port]/name". \ No newline at end of file