incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r629151 - in /incubator/sling/trunk: jcr/base/ jcr/base/src/main/java/org/apache/sling/jcr/base/util/ jcr/jackrabbit-server/ jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/ jcr/jackrabbit-server/src/main/resource...
Date Tue, 19 Feb 2008 16:34:29 GMT
Author: bdelacretaz
Date: Tue Feb 19 08:34:22 2008
New Revision: 629151

URL: http://svn.apache.org/viewvc?rev=629151&view=rev
Log:
SLING-254 - jackrabbit-server bundle acquires Repository via JNDI or RMI if the sling.repository.url.override
system property is set, instead of using embedded repository

Modified:
    incubator/sling/trunk/jcr/base/pom.xml
    incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
    incubator/sling/trunk/jcr/jackrabbit-server/pom.xml
    incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java
    incubator/sling/trunk/jcr/jackrabbit-server/src/main/resources/OSGI-INF/metatype/metatype.properties
    incubator/sling/trunk/launchpad/launchpad-webapp/pom.xml
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpPingTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxSessionInfoTest.java

Modified: incubator/sling/trunk/jcr/base/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/base/pom.xml?rev=629151&r1=629150&r2=629151&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/base/pom.xml (original)
+++ incubator/sling/trunk/jcr/base/pom.xml Tue Feb 19 08:34:22 2008
@@ -77,6 +77,11 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.0.0-incubator-SNAPSHOT</version>
+        </dependency>
+        <dependency>
             <groupId>javax.jcr</groupId>
             <artifactId>jcr</artifactId>
             <scope>compile</scope>

Modified: 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=629151&r1=629150&r2=629151&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
(original)
+++ incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
Tue Feb 19 08:34:22 2008
@@ -27,6 +27,7 @@
 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.api.SlingException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,7 +37,16 @@
     
     /** Prefix for RMI Repository URLs */
     public static final String RMI_PREFIX = "rmi://";
+    
+    /** Prefix for JNDI Repository URLs */
+    public static final String JNDI_PREFIX = "jndi://";
  
+    public static class RepositoryUrlException extends SlingException {
+        RepositoryUrlException(String reason) {
+            super(reason);
+        }
+    }
+    
     /** First try to access the Repository via JNDI (unless jndiContext is null), and if
      *  not successful try RMI.
      *  
@@ -48,8 +58,8 @@
         
         Repository result = null;
         
-        if(jndiContext == null) {
-            log.info("jndiContext is null, not trying JNDI");
+        if(jndiContext == null || jndiContext.size() == 0) {
+            log.info("jndiContext is null or empty, not trying JNDI");
         } else {
             log.debug("Trying to acquire Repository '" + repositoryName + "' via JNDI, context="
+ jndiContext);
             final ClassLoader old = Thread.currentThread().getContextClassLoader();
@@ -95,5 +105,44 @@
         }
         
         return result;
+    }
+    
+    /** Acquire a Repository from the given URL
+     *  @param url for RMI, an RMI URL. For JNDI, "jndi://", followed by the JNDI repository
name,
+     *  followed by a colon and a comma-separated list of JNDI context values, for example:
+     *  <pre>
+     *      jndi://jackrabbit:java.naming.factory.initial=org.SomeClass,java.naming.provider.url=http://foo.com
+     *  </pre>  
+     */
+    public Repository getRepositoryFromURL(String url) throws RepositoryUrlException {
+        if(url == null) {
+            throw new RepositoryUrlException("null URL");
+        }
+        
+        if(url.startsWith(JNDI_PREFIX)) {
+            // Parse JNDI URL to extract repository name and context
+            String name = null;
+            final Hashtable<String, Object> jndiContext = new Hashtable <String,
Object> ();
+            final String urlNoPrefix = url.substring(JNDI_PREFIX.length()); 
+            final int colonPos = urlNoPrefix.indexOf(':');
+            if(colonPos < 0) {
+                name = urlNoPrefix;
+            } else {
+                name = urlNoPrefix.substring(0, colonPos);
+                for(String entryStr : urlNoPrefix.substring(colonPos + 1).split(",")) {
+                    final String [] entry = entryStr.split("=");
+                    if(entry.length == 2) {
+                        jndiContext.put(entry[0], entry[1]);
+                    }
+                }
+            }
+            
+            return getRepository(name, jndiContext);
+            
+        } else {
+            
+            // Use URL as is
+            return getRepository(url, null);
+        }
     }
 }

Modified: incubator/sling/trunk/jcr/jackrabbit-server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-server/pom.xml?rev=629151&r1=629150&r2=629151&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-server/pom.xml (original)
+++ incubator/sling/trunk/jcr/jackrabbit-server/pom.xml Tue Feb 19 08:34:22 2008
@@ -140,6 +140,7 @@
                         </Private-Package>
                         <Import-Package>
                             org.apache.sling.jcr.api,
+                            org.apache.sling.jcr.base.util,
 
                             javax.jcr.*,
 
@@ -172,6 +173,11 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.jcr.api</artifactId>
+            <version>2.0.0-incubator-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.jcr.base</artifactId>
             <version>2.0.0-incubator-SNAPSHOT</version>
         </dependency>
         <dependency>

Modified: incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java?rev=629151&r1=629150&r2=629151&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java
(original)
+++ incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/SlingServerRepository.java
Tue Feb 19 08:34:22 2008
@@ -33,6 +33,7 @@
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 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.framework.Bundle;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.log.LogService;
@@ -97,18 +98,23 @@
     public static final String REPOSITORY_REGISTRATION_NAME = "name";
 
     /**
+     * @scr.property value="sling.repository.url.override"
+     */
+    public static final String REPOSITORY_URL_OVERRIDE_NAME = "repository.url.override.property";

+
+    /**
      * @scr.reference
      */
     private LogService log;
 
-    private RepositoryImpl delegatee;
+    private Repository delegatee;
 
     //---------- AbstractSlingRepository methods ------------------------------
 
     protected Repository getDelegatee() throws RepositoryException {
         if (this.delegatee == null) {
             try {
-                this.delegatee = (RepositoryImpl) this.getRepository();
+                this.delegatee = (Repository) this.getRepository();
             } catch (IOException ioe) {
                 throw new RepositoryException(ioe.getMessage(), ioe);
             }
@@ -140,7 +146,11 @@
     protected void deactivate(ComponentContext componentContext) {
         if (this.delegatee != null) {
             try {
-                this.delegatee.shutdown();
+                if(this.delegatee instanceof RepositoryImpl) {
+                    ((RepositoryImpl)this.delegatee).shutdown();
+                } else {
+                    log.log(LogService.LOG_WARNING, "Repository is not a RepositoryImpl,
cannot shut it down");
+                }
             } catch (Throwable t) {
                 this.log(LogService.LOG_ERROR, "Unexpected problem shutting down repository",
t);
             }
@@ -152,9 +162,38 @@
 
     //---------- Repository Publication ---------------------------------------
 
-    private Repository getRepository() throws RepositoryException, IOException {
+    private Repository getRepository() throws RepositoryException, IOException, RepositoryAccessor.RepositoryUrlException
{
         @SuppressWarnings("unchecked")
         Dictionary<String, Object> environment = this.getComponentContext().getProperties();
+        
+        final String urlOverrideProperty = (String) environment.get(REPOSITORY_URL_OVERRIDE_NAME);
+        String repositoryUrl = null;
+        if(urlOverrideProperty!=null && urlOverrideProperty.length() > 0) {
+            repositoryUrl = System.getProperty(urlOverrideProperty);
+        }
+        
+        if(repositoryUrl != null) {
+            log.log(LogService.LOG_INFO, 
+                    "Will not use embedded repository due to system property " + urlOverrideProperty

+                    + "=" + repositoryUrl
+                    + ", acquiring repository using that URL"
+                    );
+            return getRepositoryFromUrl(repositoryUrl);
+            
+        } else {
+            log.log(LogService.LOG_INFO, 
+                    "Repository URL override system property (" + urlOverrideProperty 
+                    + ") not set, using embedded repository"); 
+            return getEmbeddedRepository(environment);
+        }
+    }
+    
+    private Repository getRepositoryFromUrl(String repositoryUrl) throws RepositoryAccessor.RepositoryUrlException
{
+        return new RepositoryAccessor().getRepositoryFromURL(repositoryUrl);
+    }
+    
+    private Repository getEmbeddedRepository(Dictionary<String, Object> environment)

+    throws RepositoryException, IOException {
 
         String configURLObj = (String) environment.get(REPOSITORY_CONFIG_URL);
         String home = (String) environment.get(REPOSITORY_HOME_DIR);

Modified: incubator/sling/trunk/jcr/jackrabbit-server/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-server/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=629151&r1=629150&r2=629151&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-server/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ incubator/sling/trunk/jcr/jackrabbit-server/src/main/resources/OSGI-INF/metatype/metatype.properties
Tue Feb 19 08:34:22 2008
@@ -119,3 +119,10 @@
  registered JNDI and RMI registries. The respective registry services listen \
  for embedded CRX repositories to be launched and register each under the name \
  configured. If no name is configured, the repository will not be registered.
+ 
+ repository.url.override.property.name = Repository URL override property
+ repository.url.override.property.description = Name of a System Property that \
+ provides a repository connection URL to replace the embedded JCR Repository. \
+ If the corresponding System Property value is not empty, it is used to acquire \
+ a Repository via JNDI or RMI, instead of using the embedded one. \
+ Leave this value empty to force the use of the embedded Repository. 

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/pom.xml?rev=629151&r1=629150&r2=629151&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/pom.xml (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/pom.xml Tue Feb 19 08:34:22 2008
@@ -49,6 +49,12 @@
       Jetty default port (override with -D)
     -->
     <http.port>8888</http.port>
+    
+    <!-- path suffix for WebDAV access to the repository -->
+    <webdav.workspace.path>dav/default</webdav.workspace.path>
+    
+    <!-- hostname for integration tests -->
+    <test.host>localhost</test.host>
 
     <!--
       Disable Jetty webapp rescan (override with -D) 
@@ -92,9 +98,8 @@
 
           <connectors>
             <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
-              <port>8888</port>
-              <maxIdleTime>60000</maxIdleTime>
               <port>${http.port}</port>
+              <maxIdleTime>60000</maxIdleTime>
             </connector>
           </connectors>
 
@@ -193,11 +198,11 @@
             -->
             <property>
               <name>launchpad.http.server.url</name>
-              <value>http://localhost:8888</value>
+              <value>http://${test.host}:${http.port}</value>
             </property>
             <property>
               <name>launchpad.webdav.server.url</name>
-              <value>http://localhost:8888/dav/default</value>
+              <value>http://${test.host}:${http.port}/${webdav.workspace.path}</value>
             </property>
           </systemProperties>
         </configuration>
@@ -246,11 +251,11 @@
                     -->
                     <property>
                       <name>launchpad.http.server.url</name>
-                      <value>http://localhost:8888/${project.build.finalName}</value>
+                      <value>http://${test.host}:${http.port}/${project.build.finalName}</value>
                     </property>
                     <property>
                       <name>launchpad.webdav.server.url</name>
-                      <value>http://localhost:8888/${project.build.finalName}/dav/default</value>
+                      <value>http://${test.host}:${http.port}/${project.build.finalName}/${webdav.workspace.path}</value>
                     </property>
                   </systemProperties>
                 </configuration>
@@ -288,7 +293,7 @@
               </container>
               <configuration>
               <properties>
-                <cargo.servlet.port>8888</cargo.servlet.port>
+                <cargo.servlet.port>${http.port}</cargo.servlet.port>
                 <!-- 
                 <cargo.jvmargs>-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=30333,server=y,suspend=y</cargo.jvmargs>
                  -->
@@ -440,6 +445,11 @@
     <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.jcr.api</artifactId>
+      <version>2.0.0-incubator-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.jcr.base</artifactId>
       <version>2.0.0-incubator-SNAPSHOT</version>
     </dependency>
     <dependency>

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpPingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpPingTest.java?rev=629151&r1=629150&r2=629151&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpPingTest.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpPingTest.java
Tue Feb 19 08:34:22 2008
@@ -21,9 +21,12 @@
  *  setup is ok.
  */
 public class HttpPingTest extends HttpTestBase {
-    public void testWebServerRoot() throws Exception
+    
+    public void TODO_FAILS_testWebServerRoot() throws Exception
     {
-        // The root URL returns a 404, Sling doesn't resolve the root node??
+        // disabled for now: an empty repository returns 404,
+        // but if there's someting under /content it is returned
+        // due to the default mappings
         assertHttpStatus(HTTP_BASE_URL + "/", 404);
     }
     

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxSessionInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxSessionInfoTest.java?rev=629151&r1=629150&r2=629151&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxSessionInfoTest.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxSessionInfoTest.java
Tue Feb 19 08:34:22 2008
@@ -28,7 +28,11 @@
     
     public void testSessionInfo() throws IOException {
         final String content = getContent(HTTP_BASE_URL + "/ujax:sessionInfo.json", CONTENT_TYPE_JSON);
-        assertJavascript("admin.default", content, "out.println(data.userID + '.' + data.workspace)");
+        
+        // assume workspace name contains "default", might not
+        // always be the case as the default workspace is selected
+        // by the JCR implementation due to SLING-256
+        assertJavascript("admin.true", content, "out.println(data.userID + '.' + (data.workspace.indexOf('default')
>= 0) )");
     }
     
     public void testNonexistentUjaxUrl() throws IOException {



Mime
View raw message