Author: chetanm Date: Thu Aug 6 12:42:20 2015 New Revision: 1694486 URL: http://svn.apache.org/r1694486 Log: OAK-3185 - Port and refactor jackrabbit-webapp module to Oak (WIP)
Introducing repository-config.json which acts as a substitute for repository.xml to configure the whole repository -- Changed the default folder to 'oak' under which repository would be created -- Repository initialization logic would use OSGiRepositoryFactory to initialize repository. Still cannot use ServiceLoader approach as oak-jcr has a dummy factory -- Disabled auto JNDI registration for now as we do not have MemoryInitialContextFactory. User can configure it as per requirement of respective app server Added: jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/repository-config.json Modified: jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/Installer.java jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/bootstrap.properties jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/web.xml jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/bootstrap/missing.jsp Modified: jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/Installer.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/Installer.java?rev=1694486&r1=1694485&r2=1694486&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/Installer.java (original) +++ jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/Installer.java Thu Aug 6 12:42:20 2015 @@ -95,7 +95,7 @@ public class Installer { * todo: to be configured */ private final String configTemplate = - "/org/apache/jackrabbit/core/repository.xml"; + "/WEB-INF/templates/repository-config.json"; /** * the place for the bootstrap properties template @@ -125,62 +125,43 @@ public class Installer { public int installRepository(HttpServletRequest req) throws ServletException, IOException { String repHome = req.getParameter("repository_home"); - String repType = req.getParameter("repository_type"); - String repXml = req.getParameter("repository_xml"); String mode = req.getParameter("mode"); if (repHome == null || mode == null) { return C_INVALID_INPUT; } File home = new File(repHome); - - File config; - if ("oak".equals(repType)) { - config = null; - repXml = null; - } else if (repXml == null || repXml.length() == 0) { - config = new File(home, "repository.xml"); - repXml = config.getPath(); - } else { - config = new File(repXml); - } + File config = new File(home, "repository-config.json"); if ("new".equals(mode)) { // Test internal folder repository existence and not home because home is already created // by org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet - if (new File(home, "repository").exists()) { - log.error("Trying to install new repository home '{}' but it already contain a repository", repHome); - return C_HOME_EXISTS; - } - if (config != null && config.exists()) { - log.error("Trying to install new repository config '{}' but already exists", repXml); + if (config.exists()) { + log.error("Trying to install new repository config '{}' but already exists", config); return C_CONFIG_EXISTS; } log.info("Creating new repository home '{}'", repHome); home.mkdirs(); - if (config != null) { - // install repository xml for Jackrabbit Classic - try { - installRepositoryConfig(config); - } catch (IOException e) { - log.error("Error while installing new repository config '{}': {}", repXml, e.toString()); - return C_BOOTSTRAP_EXISTS; - } + try { + installRepositoryConfig(config); + } catch (IOException e) { + log.error("Error while installing new repository config '{}': {}", config, e.toString()); + return C_BOOTSTRAP_EXISTS; } } else { if (!home.exists()) { log.error("Trying to use existing repository home '{}' but does not exists", repHome); return C_HOME_MISSING; } - if (config != null && !config.exists()) { - log.error("Trying to use existing repository config '{}' but does not exists", repXml); + if (!config.exists()) { + log.error("Trying to use existing repository config '{}' but does not exists", config); return C_CONFIG_MISSING; } } // install bootstrap.properties try { - installBootstrap(bootstrapConfigFile, repHome, repXml); + installBootstrap(bootstrapConfigFile, repHome); } catch (IOException e) { log.error("Error while installing '{}': {}", bootstrapConfigFile.getPath(), e.toString()); return C_INSTALL_ERROR; @@ -213,19 +194,15 @@ public class Installer { * Installs the bootstrap config file from the template * @param dest the destination location * @param repHome the repository home location - * @param repXml the repository xml location * @throws IOException if an I/O error occurs */ - private void installBootstrap(File dest, String repHome, String repXml) + private void installBootstrap(File dest, String repHome) throws IOException { log.info("Creating new bootstrap properties: {}", dest.getPath()); InputStream in = context.getResourceAsStream(bootstrapTemplate); Properties props = new Properties(); props.load(in); props.setProperty("repository.home", repHome); - if (repXml != null) { - props.setProperty("repository.config", repXml); - } in.close(); if (!dest.getParentFile().exists()) { dest.getParentFile().mkdirs(); Modified: jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java?rev=1694486&r1=1694485&r2=1694486&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java (original) +++ jackrabbit/oak/trunk/oak-examples/webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryStartupServlet.java Thu Aug 6 12:42:20 2015 @@ -16,26 +16,24 @@ */ package org.apache.jackrabbit.j2ee; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.jackrabbit.api.JackrabbitRepository; +import org.apache.jackrabbit.commons.JcrUtils; import org.apache.jackrabbit.commons.repository.RepositoryFactory; -import org.apache.jackrabbit.core.RepositoryImpl; -import org.apache.jackrabbit.core.config.RepositoryConfig; -import org.apache.jackrabbit.oak.jcr.Jcr; -import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore; -import org.apache.jackrabbit.oak.plugins.segment.SegmentStore; -import org.apache.jackrabbit.oak.plugins.segment.file.FileStore; +import org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory; import org.apache.jackrabbit.rmi.server.RemoteAdapterFactory; import org.apache.jackrabbit.rmi.server.ServerAdapterFactory; import org.apache.jackrabbit.servlet.AbstractRepositoryServlet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.xml.sax.InputSource; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.net.InetAddress; import java.net.ServerSocket; import java.net.UnknownHostException; @@ -48,6 +46,8 @@ import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.RMIServerSocketFactory; import java.rmi.server.UnicastRemoteObject; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; import javax.jcr.Repository; @@ -172,11 +172,6 @@ public class RepositoryStartupServlet ex static String bootstrapOverride = null; /** - * the TarMK segment store - */ - private SegmentStore store; - - /** * the registered repository */ private Repository repository; @@ -410,35 +405,31 @@ public class RepositoryStartupServlet ex "Repository configuration failure: " + config.getRepositoryHome(), e); } String repConfig = config.getRepositoryConfig(); - if (repConfig != null) { // Jackrabbit Classic - InputStream in = getServletContext().getResourceAsStream(repConfig); - if (in == null) { + if (repConfig != null) { + File configJson = new File(repHome, repConfig); + if (!configJson.exists()){ + InputStream in = getServletContext().getResourceAsStream(repConfig); + if (in == null){ + throw new ServletException("No config file found in classpath " + repConfig); + } + OutputStream os = null; try { - in = new FileInputStream(new File(repConfig)); - } catch (FileNotFoundException e) { - // fallback to old config - try { - in = new FileInputStream(new File(repHome, repConfig)); - } catch (FileNotFoundException e1) { - throw new ServletExceptionWithCause( - "Repository configuration not found: " + repConfig, e); - } + os = FileUtils.openOutputStream(configJson); + IOUtils.copy(in, os); + } catch (IOException e1) { + throw new ServletExceptionWithCause( + "Error copying the repository config json", e1); + } finally { + IOUtils.closeQuietly(os); + IOUtils.closeQuietly(in); } } try { - repository = createRepository(new InputSource(in), repHome); + repository = createRepository(configJson, repHome); } catch (RepositoryException e) { throw new ServletExceptionWithCause("Error while creating repository", e); } - } else { // Jackrabbit Oak - try { - String model = System.getProperty("sun.arch.data.model", "32"); - store = new FileStore(repHome, 256, "64".equals(model)); - repository = new Jcr(new SegmentNodeStore(store)).createRepository(); - } catch (IOException e) { - throw new ServletExceptionWithCause("Error while creating repository", e); - } } } @@ -449,10 +440,7 @@ public class RepositoryStartupServlet ex * <code>nulled</code>. */ private void shutdownRepository() { - if (store != null) { - store.close(); - store = null; - } else if (repository instanceof JackrabbitRepository) { + if (repository instanceof JackrabbitRepository) { ((JackrabbitRepository) repository).shutdown(); } repository = null; @@ -468,10 +456,15 @@ public class RepositoryStartupServlet ex * @return a new jcr repository. * @throws RepositoryException if an error during creation occurs. */ - protected Repository createRepository(InputSource is, File homedir) + protected Repository createRepository(File configJson, File homedir) throws RepositoryException { - RepositoryConfig config = RepositoryConfig.create(is, homedir.getAbsolutePath()); - return RepositoryImpl.create(config); + Map<String,String> config = new HashMap<String, String>(); + config.put("org.apache.jackrabbit.repository.home", homedir.getAbsolutePath()); + config.put("org.apache.jackrabbit.oak.repository.configFile", configJson.getAbsolutePath()); + //TODO oak-jcr also provides a dummy RepositoryFactory. Hence this + //cannot be used + //return JcrUtils.getRepository(config); + return new OakOSGiRepositoryFactory().getRepository(config); } /** Modified: jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/bootstrap.properties URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/bootstrap.properties?rev=1694486&r1=1694485&r2=1694486&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/bootstrap.properties (original) +++ jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/bootstrap.properties Thu Aug 6 12:42:20 2015 @@ -18,8 +18,8 @@ # in the "bootstrap-config" init parameter. # Repository configuration settings (will be adjusted by installer) -repository.config=jackrabbit/repository/repository.xml -repository.home=jackrabbit/repository +repository.config=repository-config.json +repository.home=oak repository.name=jackrabbit.repository # RMI Settings @@ -32,7 +32,9 @@ rmi.host=localhost # JNDI Settings # all properties starting with 'java.naming.' will go into the # environment of the initial context -jndi.enabled=true +# TODO Disabling JMDI support by default as DummyInitialContextFactory does +# not exist by default +jndi.enabled=false # if the name is not specified, it's initialized with the repository.name #jndi.name=${repository.name} java.naming.provider.url=http://www.apache.org/jackrabbit Added: jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/repository-config.json URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/repository-config.json?rev=1694486&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/repository-config.json (added) +++ jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/templates/repository-config.json Thu Aug 6 12:42:20 2015 @@ -0,0 +1,24 @@ +{ + "org.apache.felix.jaas.Configuration.factory-GuestLoginModule": { + "jaas.controlFlag": "optional", + "jaas.classname": "org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule", + "jaas.ranking": 300 + }, + "org.apache.felix.jaas.Configuration.factory-LoginModuleImpl": { + "jaas.controlFlag": "required", + "jaas.classname": "org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl", + "jaas.ranking": 100 + }, + "org.apache.felix.jaas.Configuration.factory-TokenLoginModule": { + "jaas.controlFlag": "sufficient", + "jaas.classname": "org.apache.jackrabbit.oak.security.authentication.token.TokenLoginModule", + "jaas.ranking": 200 + }, + "org.apache.felix.jaas.ConfigurationSpi": { + "jaas.defaultRealmName": "jackrabbit.oak", + "jaas.globalConfigPolicy": "proxy", + "jaas.configProviderName": "FelixJaasProvider" + }, + "org.apache.jackrabbit.oak.jcr.osgi.RepositoryManager": {}, + "org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService" : {} +} \ No newline at end of file Modified: jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/web.xml?rev=1694486&r1=1694485&r2=1694486&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/web.xml (original) +++ jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/WEB-INF/web.xml Thu Aug 6 12:42:20 2015 @@ -34,7 +34,7 @@ <init-param> <param-name>bootstrap-config</param-name> - <param-value>jackrabbit/bootstrap.properties</param-value> + <param-value>oak/bootstrap.properties</param-value> <description> Property file that hold the same initialization properties than the init-params below. If a parameter is specified in both @@ -125,7 +125,7 @@ <init-param> <param-name>bootstrap-config</param-name> - <param-value>jackrabbit/bootstrap.properties</param-value> + <param-value>oak/bootstrap.properties</param-value> <description> Property file that hold the same initialization properties than the init-params below. If a parameter is specified in both Modified: jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/bootstrap/missing.jsp URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/bootstrap/missing.jsp?rev=1694486&r1=1694485&r2=1694486&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/bootstrap/missing.jsp (original) +++ jackrabbit/oak/trunk/oak-examples/webapp/src/main/webapp/bootstrap/missing.jsp Thu Aug 6 12:42:20 2015 @@ -37,16 +37,7 @@ request.setAttribute("title", "Content R <p> <label> Repository home directory: - <input size="40" type="text" name="repository_home" value="jackrabbit"> - </label> - </p> - <p> - Repository type: - <label> - <input type="radio" name="repository_type" value="classic" checked> Classic - </label> - <label> - <input type="radio" name="repository_type" value="oak"> Oak + <input size="40" type="text" name="repository_home" value="oak"> </label> </p> <p><input type="submit" value="Create Content Repository"></p> @@ -58,7 +49,7 @@ request.setAttribute("title", "Content R <p> Use this form to access an existing content repository in the given directory. The repository configuration file should be available as - <code>repository.xml</code> within the given directory. + <code>repository-config.json</code> within the given directory. </p> <p> Note that the repository can not be concurrently accessed by multiple @@ -70,7 +61,7 @@ request.setAttribute("title", "Content R <p> <label> Repository home directory: - <input size="40" type="text" name="repository_home" value="jackrabbit"> + <input size="40" type="text" name="repository_home" value="oak"> </label> </p> <p><input type="submit" value="Access Content Repository"></p>