Search in sources :

Example 76 with Repository

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

the class RepositoryStubImpl method getRepositoryService.

/**
     *
     * @return
     * @throws RepositoryStubException
     */
public RepositoryService getRepositoryService() throws RepositoryStubException {
    Repository jackrabbitRepo = super.getRepository();
    // TODO: make configurable
    BatchReadConfig brconfig = new BatchReadConfig();
    brconfig.setDepth(NameConstants.NT_UNSTRUCTURED, BatchReadConfig.DEPTH_INFINITE);
    return new RepositoryServiceImpl(jackrabbitRepo, brconfig);
}
Also used : Repository(javax.jcr.Repository)

Example 77 with Repository

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

the class ServiceStubImpl method getRepositoryService.

public RepositoryService getRepositoryService() throws RepositoryException {
    if (service == null) {
        Repository repository;
        try {
            repository = RepositoryStub.getInstance(Collections.EMPTY_MAP).getRepository();
        } catch (RepositoryStubException e) {
            throw new RepositoryException(e);
        }
        service = new RepositoryServiceImpl(repository, new BatchReadConfig());
    }
    return service;
}
Also used : Repository(javax.jcr.Repository) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) RepositoryException(javax.jcr.RepositoryException)

Example 78 with Repository

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

the class Main method run.

public void run() throws Exception {
    String defaultFile = "jackrabbit-standalone.jar";
    URL location = Main.class.getProtectionDomain().getCodeSource().getLocation();
    if (location != null && "file".equals(location.getProtocol())) {
        File file = new File(location.getPath());
        if (file.isFile()) {
            defaultFile = location.getPath();
        }
    }
    File file = new File(command.getOptionValue("file", defaultFile));
    if (command.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar " + file.getName(), options, true);
    } else if (command.hasOption("notice")) {
        copyToOutput("/META-INF/NOTICE.txt");
    } else if (command.hasOption("license")) {
        copyToOutput("/META-INF/LICENSE.txt");
    } else if (command.hasOption("cli")) {
        System.setProperty("logback.configurationFile", "logback-cli.xml");
        String uri = command.getOptionValue("cli");
        Repository repository = JcrUtils.getRepository(uri);
        Context context = new ContextBase();
        CommandHelper.setRepository(context, repository, uri);
        try {
            Session session = repository.login();
            CommandHelper.setSession(context, session);
            CommandHelper.setCurrentNode(context, session.getRootNode());
        } catch (RepositoryException ignore) {
        // anonymous login not possible
        }
        new JcrClient(context).runInteractive();
        try {
            CommandHelper.getSession(context).logout();
        } catch (CommandException ignore) {
        // already logged out
        }
    } else {
        message("Welcome to Apache Jackrabbit!");
        message("-------------------------------");
        File repository = new File(command.getOptionValue("repo", "jackrabbit"));
        message("Using repository directory " + repository);
        repository.mkdirs();
        File tmp = new File(repository, "tmp");
        tmp.mkdir();
        File log = new File(repository, "log");
        log.mkdir();
        message("Writing log messages to " + log);
        prepareServerLog(log);
        if (command.hasOption("backup")) {
            backup(repository);
        } else {
            message("Starting the server...");
            prepareWebapp(file, repository, tmp);
            accessLog.setHandler(webapp);
            prepareAccessLog(log);
            server.setHandler(accessLog);
            prepareConnector();
            server.addConnector(connector);
            prepareShutdown();
            try {
                server.start();
                String host = connector.getHost();
                if (host == null) {
                    host = "localhost";
                }
                message("Apache Jackrabbit is now running at " + "http://" + host + ":" + connector.getPort() + "/");
            } catch (Throwable t) {
                System.err.println("Unable to start the server: " + t.getMessage());
                System.exit(1);
            }
        }
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) Context(org.apache.commons.chain.Context) Repository(javax.jcr.Repository) RepositoryException(javax.jcr.RepositoryException) CommandException(org.apache.jackrabbit.standalone.cli.CommandException) File(java.io.File) URL(java.net.URL) JcrClient(org.apache.jackrabbit.standalone.cli.JcrClient) ContextBase(org.apache.commons.chain.impl.ContextBase) Session(javax.jcr.Session)

Example 79 with Repository

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

the class ConnectToJNDIServer method execute.

/**
	 * {@inheritDoc}
	 */
public boolean execute(Context ctx) throws Exception {
    String url = (String) ctx.get(this.urlKey);
    if (log.isDebugEnabled()) {
        log.debug("connecting to jndi server at " + url);
    }
    InitialContext iCtx = new InitialContext();
    ClientAdapterFactory adapter = new ClientAdapterFactory();
    RemoteRepository remote = (RemoteRepository) iCtx.lookup(url);
    Repository repo = adapter.getRepository(remote);
    CommandHelper.setRepository(ctx, repo, "jndi " + url);
    return false;
}
Also used : Repository(javax.jcr.Repository) RemoteRepository(org.apache.jackrabbit.rmi.remote.RemoteRepository) RemoteRepository(org.apache.jackrabbit.rmi.remote.RemoteRepository) ClientAdapterFactory(org.apache.jackrabbit.rmi.client.ClientAdapterFactory) InitialContext(javax.naming.InitialContext)

Example 80 with Repository

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

the class ConnectToRmiServer method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String url = (String) ctx.get(this.urlKey);
    if (log.isDebugEnabled()) {
        log.debug("connecting to jcr-rmi server at " + url);
    }
    ClientRepositoryFactory factory = new ClientRepositoryFactory();
    Repository repository = factory.getRepository(url);
    CommandHelper.setRepository(ctx, repository, "jcr-rmi " + url);
    return false;
}
Also used : Repository(javax.jcr.Repository) ClientRepositoryFactory(org.apache.jackrabbit.rmi.client.ClientRepositoryFactory)

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