Search in sources :

Example 81 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class RepositoryAccessServlet method getRepositoryByRMI.

/**
     * Checks if the repository is available via RMI and returns it.
     * @return the repository or <code>null</code>
     * @throws ServletException if this servlet is not properly configured.
     */
private Repository getRepositoryByRMI() throws ServletException {
    BootstrapConfig config = getConfig();
    if (!config.getRmiConfig().isValid() || !config.getRmiConfig().enabled()) {
        return null;
    }
    // acquire via RMI
    String rmiURI = config.getRmiConfig().getRmiUri();
    if (rmiURI == null) {
        return null;
    }
    log.info("  trying to retrieve repository using rmi. uri={}", rmiURI);
    ClientFactoryDelegater cfd;
    try {
        Class clazz = Class.forName(getServerFactoryDelegaterClass());
        cfd = (ClientFactoryDelegater) clazz.newInstance();
    } catch (Throwable e) {
        log.error("Unable to locate RMI ClientRepositoryFactory. Is jcr-rmi.jar missing?", e);
        return null;
    }
    try {
        Repository r = cfd.getRepository(rmiURI);
        log.info("Acquired repository via RMI.");
        return r;
    } catch (Exception e) {
        log.error("Error while retrieving repository using RMI: {}", rmiURI, e);
        return null;
    }
}
Also used : Repository(javax.jcr.Repository) MalformedURLException(java.net.MalformedURLException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) NotBoundException(java.rmi.NotBoundException)

Example 82 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class RepositoryAccessServlet method getRepositoryByJNDI.

/**
     * Checks if the repository is available via JNDI and returns it.
     * @return the repository or <code>null</code>
     * @throws ServletException if this servlet is not properly configured.
     */
private Repository getRepositoryByJNDI() throws ServletException {
    BootstrapConfig config = getConfig();
    if (!config.getJndiConfig().isValid() || !config.getJndiConfig().enabled()) {
        return null;
    }
    // acquire via JNDI
    String repositoryName = config.getRepositoryName();
    InitialContext ctx = getInitialContext();
    if (ctx == null) {
        return null;
    }
    try {
        Repository r = (Repository) ctx.lookup(repositoryName);
        log.info("Acquired repository via JNDI.");
        return r;
    } catch (NamingException e) {
        log.error("Error while retrieving repository using JNDI (name={})", repositoryName, e);
        return null;
    }
}
Also used : Repository(javax.jcr.Repository) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 83 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class RepositoryStartupServlet method createRepository.

/**
     * Creates the repository instance for the given config and homedir.
     * Subclasses may override this method of providing own implementations of
     * a {@link Repository}.
     *
     * @param configJson input source of the repository config
     * @param homedir the repository home directory
     * @return a new jcr repository.
     * @throws RepositoryException if an error during creation occurs.
     */
protected Repository createRepository(File configJson, File homedir) throws RepositoryException {
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(OakOSGiRepositoryFactory.REPOSITORY_HOME, homedir.getAbsolutePath());
    config.put(OakOSGiRepositoryFactory.REPOSITORY_CONFIG_FILE, configJson.getAbsolutePath());
    config.put(OakOSGiRepositoryFactory.REPOSITORY_BUNDLE_FILTER, getBootstrapConfig().getBundleFilter());
    config.put(OakOSGiRepositoryFactory.REPOSITORY_SHUTDOWN_ON_TIMEOUT, getBootstrapConfig().isShutdownOnTimeout());
    config.put(OakOSGiRepositoryFactory.REPOSITORY_TIMEOUT_IN_SECS, getBootstrapConfig().getStartupTimeout());
    configureActivator(config);
    //TODO oak-jcr also provides a dummy RepositoryFactory. Hence this
    //cannot be used
    //return JcrUtils.getRepository(config);
    Repository repository = new OakOSGiRepositoryFactory().getRepository(config);
    configWebConsoleSecurityProvider(repository);
    return repository;
}
Also used : Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) HashMap(java.util.HashMap) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) OakOSGiRepositoryFactory(org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory)

Example 84 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class RepositoryAccessServlet method getRepositoryByRMI.

/**
     * Checks if the repository is available via RMI and returns it.
     * @return the repository or <code>null</code>
     * @throws ServletException if this servlet is not properly configured.
     */
private Repository getRepositoryByRMI() throws ServletException {
    BootstrapConfig config = getConfig();
    if (!config.getRmiConfig().isValid() || !config.getRmiConfig().enabled()) {
        return null;
    }
    // acquire via RMI
    String rmiURI = config.getRmiConfig().getRmiUri();
    if (rmiURI == null) {
        return null;
    }
    log.info("  trying to retrieve repository using rmi. uri={}", rmiURI);
    ClientFactoryDelegater cfd;
    try {
        Class clazz = Class.forName(getServerFactoryDelegaterClass());
        cfd = (ClientFactoryDelegater) clazz.newInstance();
    } catch (Throwable e) {
        log.error("Unable to locate RMI ClientRepositoryFactory. Is jcr-rmi.jar missing?", e);
        return null;
    }
    try {
        Repository r = cfd.getRepository(rmiURI);
        log.info("Acquired repository via RMI.");
        return r;
    } catch (Exception e) {
        log.error("Error while retrieving repository using RMI: {}", rmiURI, e);
        return null;
    }
}
Also used : Repository(javax.jcr.Repository) MalformedURLException(java.net.MalformedURLException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) NotBoundException(java.rmi.NotBoundException)

Example 85 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class RemotingInitializer method remotingServlet.

@Bean
public ServletRegistrationBean remotingServlet() {
    ServletRegistrationBean bean = new ServletRegistrationBean(new JcrRemotingServlet() {

        @Override
        public Repository getRepository() {
            return repository;
        }

        @Override
        public ServletContext getServletContext() {
            return RemotingInitializer.this.getServletContext();
        }
    }, "/server/*");
    bean.addInitParameter(JcrRemotingServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "/server");
    bean.addInitParameter(JcrRemotingServlet.INIT_PARAM_BATCHREAD_CONFIG, "/remoting/batchread.properties");
    bean.addInitParameter(JcrRemotingServlet.INIT_PARAM_PROTECTED_HANDLERS_CONFIG, "/remoting/protectedHandlersConfig.xml");
    bean.addInitParameter(JcrRemotingServlet.INIT_PARAM_HOME, davHome);
    return bean;
}
Also used : Repository(javax.jcr.Repository) ServletRegistrationBean(org.springframework.boot.context.embedded.ServletRegistrationBean) ServletContext(javax.servlet.ServletContext) JcrRemotingServlet(org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet) ServletRegistrationBean(org.springframework.boot.context.embedded.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Repository (javax.jcr.Repository)107 Session (javax.jcr.Session)31 RepositoryException (javax.jcr.RepositoryException)26 SimpleCredentials (javax.jcr.SimpleCredentials)15 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 Node (javax.jcr.Node)12 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)10 SlingRepository (org.apache.sling.jcr.api.SlingRepository)10 JackrabbitRepository (org.apache.jackrabbit.api.JackrabbitRepository)9 Oak (org.apache.jackrabbit.oak.Oak)7 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)7 IOException (java.io.IOException)6 Map (java.util.Map)6 InitialContext (javax.naming.InitialContext)6 NamingException (javax.naming.NamingException)6 ServletContext (javax.servlet.ServletContext)5 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 File (java.io.File)4 OutputStreamWriter (java.io.OutputStreamWriter)4