Search in sources :

Example 26 with Repository

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

the class JNDIBindingServlet method init.

/**
     * Binds a repository from the servlet context in the configured
     * JNDI location.
     *
     * @throws ServletException if the repository could not be bound in JNDI
     */
public void init() throws ServletException {
    try {
        Hashtable environment = new Hashtable();
        Enumeration names = getInitParameterNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            if (name.equals("location")) {
                location = getInitParameter(name);
            } else if (!name.equals(Repository.class.getName())) {
                environment.put(name, getInitParameter(name));
            }
        }
        context = new InitialContext(environment);
        context.bind(location, new ServletRepository(this));
    } catch (NamingException e) {
        throw new ServletException("Failed to bind repository to JNDI: " + location, e);
    }
}
Also used : ServletException(javax.servlet.ServletException) Repository(javax.jcr.Repository) Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 27 with Repository

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

the class ServletRepositoryFactory method getRepository.

/**
     * Looks up and returns a repository bound in the configured servlet
     * context attribute.
     *
     * @return repository from servlet context
     * @throws RepositoryException if the repository is not available
     */
public Repository getRepository() throws RepositoryException {
    String name = servlet.getInitParameter(Repository.class.getName());
    if (name == null) {
        name = Repository.class.getName();
    }
    ServletContext context = servlet.getServletContext();
    Object repository = context.getAttribute(name);
    if (repository instanceof Repository) {
        return (Repository) repository;
    } else if (repository != null) {
        throw new RepositoryException("Invalid repository: Attribute " + name + " in servlet context " + context.getServletContextName() + " is an instance of " + repository.getClass().getName());
    } else {
        throw new RepositoryException("Repository not found: Attribute " + name + " does not exist in servlet context " + context.getServletContextName());
    }
}
Also used : Repository(javax.jcr.Repository) ServletContext(javax.servlet.ServletContext) RepositoryException(javax.jcr.RepositoryException)

Example 28 with Repository

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

the class BundleTest method testJackrabbitBundle.

public void testJackrabbitBundle() throws Exception {
    ServiceReference reference = getServiceReference(Repository.class.getName());
    Assert.assertNotNull(reference);
    Assert.assertEquals("Jackrabbit", reference.getProperty(Repository.REP_NAME_DESC));
    Object service = getServiceObject(reference);
    assertTrue(service instanceof Repository);
    Repository repository = (Repository) service;
    Assert.assertEquals("Jackrabbit", repository.getDescriptor(Repository.REP_NAME_DESC));
    Session session = repository.login();
    try {
        assertEquals("/", session.getRootNode().getPath());
    } finally {
        session.logout();
    }
}
Also used : Repository(javax.jcr.Repository) ServiceReference(org.osgi.framework.ServiceReference) Session(javax.jcr.Session)

Example 29 with Repository

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

the class JackrabbitRepositoryFixture method setUpCluster.

@Override
public Repository[] setUpCluster(int n) throws Exception {
    if (n == 1) {
        String name = "Jackrabbit-" + System.currentTimeMillis();
        File directory = new File(base, name);
        Properties variables = new Properties(System.getProperties());
        variables.setProperty(REPOSITORY_HOME_VARIABLE, directory.getPath());
        variables.setProperty("bundleCacheSize", Integer.toString(bundleCacheSize));
        InputStream xml = getClass().getResourceAsStream("repository.xml");
        RepositoryConfig config = RepositoryConfig.create(new InputSource(xml), variables);
        // Prevent Derby from polluting the current directory
        System.setProperty("derby.stream.error.file", new File(directory, "derby.log").getPath());
        RepositoryImpl repository = RepositoryImpl.create(config);
        this.cluster = new RepositoryImpl[] { repository };
        return new Repository[] { repository };
    } else {
        throw new UnsupportedOperationException("TODO");
    }
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) InputSource(org.xml.sax.InputSource) Repository(javax.jcr.Repository) InputStream(java.io.InputStream) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) Properties(java.util.Properties) File(java.io.File)

Example 30 with Repository

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

the class RevisionGCTest method run.

@Override
public void run(Iterable<RepositoryFixture> fixtures) {
    for (RepositoryFixture fixture : fixtures) {
        if (fixture.isAvailable(1)) {
            System.out.format("%s: RevisionGC benchmark%n", fixture);
            try {
                final AtomicReference<Oak> whiteboardRef = new AtomicReference<Oak>();
                Repository[] cluster;
                if (fixture instanceof OakRepositoryFixture) {
                    cluster = ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {

                        @Override
                        public Jcr customize(Oak oak) {
                            whiteboardRef.set(oak);
                            return new Jcr(oak);
                        }
                    });
                } else {
                    System.err.format("%s: RevisionGC benchmark only runs on Oak%n", fixture);
                    return;
                }
                try {
                    run(cluster[0], getNodeStore(whiteboardRef.get()));
                } finally {
                    fixture.tearDownCluster();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Repository(javax.jcr.Repository) OakRepositoryFixture(org.apache.jackrabbit.oak.fixture.OakRepositoryFixture) OakRepositoryFixture(org.apache.jackrabbit.oak.fixture.OakRepositoryFixture) RepositoryFixture(org.apache.jackrabbit.oak.fixture.RepositoryFixture) Oak(org.apache.jackrabbit.oak.Oak) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) AtomicReference(java.util.concurrent.atomic.AtomicReference) JcrCreator(org.apache.jackrabbit.oak.fixture.JcrCreator) RepositoryException(javax.jcr.RepositoryException)

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