Search in sources :

Example 1 with RepositoryStubException

use of org.apache.jackrabbit.test.RepositoryStubException in project jackrabbit by apache.

the class JackrabbitRepositoryStub method getRepository.

/**
 * Returns the configured repository instance.
 *
 * @return the configured repository instance.
 * @throws RepositoryStubException if an error occurs while
 *                                 obtaining the repository instance.
 */
public synchronized Repository getRepository() throws RepositoryStubException {
    try {
        String dir = settings.getProperty(PROP_REPOSITORY_HOME);
        if (dir == null) {
            dir = new File("target", "repository").getAbsolutePath();
        } else {
            dir = new File(dir).getAbsolutePath();
        }
        String xml = settings.getProperty(PROP_REPOSITORY_CONFIG);
        if (xml == null) {
            xml = new File(dir, "repository.xml").getPath();
        }
        return getOrCreateRepository(dir, xml);
    } catch (Exception e) {
        throw new RepositoryStubException("Failed to start repository", e);
    }
}
Also used : RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) File(java.io.File) IOException(java.io.IOException) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) RepositoryException(javax.jcr.RepositoryException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Example 2 with RepositoryStubException

use of org.apache.jackrabbit.test.RepositoryStubException in project jackrabbit by apache.

the class RepositoryStubImpl method getRepository.

@Override
public synchronized Repository getRepository() throws RepositoryStubException {
    if (repository == null) {
        try {
            Repository repo = super.getRepository();
            principal = findKnownPrincipal(repo);
            RemoteAdapterFactory raf = new ServerAdapterFactory();
            remote = raf.getRemoteRepository(repo);
            // Make sure that the remote reference survives serialization
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(buffer);
            oos.writeObject(RemoteObject.toStub(remote));
            oos.close();
            ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
            LocalAdapterFactory laf = new ClientAdapterFactory();
            repository = laf.getRepository((RemoteRepository) ois.readObject());
        } catch (Exception e) {
            throw new RepositoryStubException(e);
        }
    }
    return repository;
}
Also used : Repository(javax.jcr.Repository) RemoteRepository(org.apache.jackrabbit.rmi.remote.RemoteRepository) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteRepository(org.apache.jackrabbit.rmi.remote.RemoteRepository) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) RemoteAdapterFactory(org.apache.jackrabbit.rmi.server.RemoteAdapterFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClientAdapterFactory(org.apache.jackrabbit.rmi.client.ClientAdapterFactory) ObjectOutputStream(java.io.ObjectOutputStream) LocalAdapterFactory(org.apache.jackrabbit.rmi.client.LocalAdapterFactory) ServerAdapterFactory(org.apache.jackrabbit.rmi.server.ServerAdapterFactory) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) RepositoryException(javax.jcr.RepositoryException) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with RepositoryStubException

use of org.apache.jackrabbit.test.RepositoryStubException in project jackrabbit by apache.

the class RepositoryStubImpl method getRepository.

@Override
public Repository getRepository() throws RepositoryStubException {
    if (repository == null) {
        repository = super.getRepository();
    }
    if (server == null) {
        server = new Server();
        ServletHolder holder = new ServletHolder(new JcrRemotingServlet() {

            protected Repository getRepository() {
                return repository;
            }
        });
        String pathPrefix = WEBDAV_SERVLET_PATH_PREFIX;
        if (pathPrefix.endsWith("/")) {
            pathPrefix = pathPrefix.substring(0, pathPrefix.length() - 1);
        }
        holder.setInitParameter(JCRWebdavServerServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, pathPrefix);
        holder.setInitParameter(JCRWebdavServerServlet.INIT_PARAM_MISSING_AUTH_MAPPING, "");
        holder.setInitParameter(JcrRemotingServlet.INIT_PARAM_PROTECTED_HANDLERS_CONFIG, protectedRemoveImplClass);
        ServletContextHandler schandler = new ServletContextHandler(server, WEBDAV_SERVLET_CONTEXT_PATH);
        schandler.addServlet(holder, WEBDAV_SERVLET_PATH_MAPPING);
    }
    if (connector == null) {
        connector = new ServerConnector(server);
        connector.setHost("localhost");
        String pvalue = System.getProperty("org.apache.jackrabbit.jcr2dav.RepositoryStubImpl.port", "0");
        int port = pvalue.equals("") ? 0 : Integer.parseInt(pvalue);
        connector.setPort(port);
        server.addConnector(connector);
        try {
            server.start();
        } catch (Exception e) {
            throw new RepositoryStubException(e);
        }
    }
    if (client == null) {
        try {
            Map<String, String> parameters = new HashMap<String, String>();
            String uri = "http://localhost:" + connector.getLocalPort() + WEBDAV_SERVLET_CONTEXT_PATH + WEBDAV_SERVLET_PATH_PREFIX;
            String parmName = System.getProperty(this.getClass().getName() + ".REPURIPARM", JcrUtils.REPOSITORY_URI);
            parameters.put(parmName, uri);
            parameters.put(PROP_ACCESSCONTROL_PROVIDER_CLASS, acProviderImplClass);
            client = JcrUtils.getRepository(parameters);
        } catch (Exception e) {
            throw new RepositoryStubException(e);
        }
    }
    return client;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Repository(javax.jcr.Repository) Server(org.eclipse.jetty.server.Server) HashMap(java.util.HashMap) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) JcrRemotingServlet(org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) RepositoryException(javax.jcr.RepositoryException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Example 4 with RepositoryStubException

use of org.apache.jackrabbit.test.RepositoryStubException in project jackrabbit by apache.

the class RepositoryStubImpl method getRepository.

/**
 * @return the repository instance to test.
 * @throws RepositoryStubException if an error occurs while starting up the
 *                                 repository.
 */
public Repository getRepository() throws RepositoryStubException {
    if (repo == null) {
        try {
            final RepositoryService service = getRepositoryService();
            repo = RepositoryImpl.create(new AbstractRepositoryConfig() {

                public RepositoryService getRepositoryService() {
                    return service;
                }
            });
        } catch (RepositoryException e) {
            throw new RepositoryStubException(e);
        }
    }
    return repo;
}
Also used : RepositoryException(javax.jcr.RepositoryException) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) AbstractRepositoryConfig(org.apache.jackrabbit.jcr2spi.AbstractRepositoryConfig) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 5 with RepositoryStubException

use of org.apache.jackrabbit.test.RepositoryStubException in project jackrabbit by apache.

the class WebDAVTestBase method setUp.

protected void setUp() throws Exception {
    super.setUp();
    File home = new File("target/jackrabbit-repository");
    if (!home.exists()) {
        home.mkdirs();
    }
    File config = new File(home, "repository.xml");
    if (!config.exists()) {
        createDefaultConfiguration(config);
    }
    File keystore = new File(home, KEYSTORE);
    if (!keystore.exists()) {
        createKeystore(keystore);
    }
    if (repoContext == null) {
        repoContext = RepositoryContext.create(RepositoryConfig.create(config.toURI(), home.getPath()));
    }
    if (server == null) {
        server = new Server();
        ServletHolder simple = new ServletHolder(new SimpleWebdavServlet() {

            private static final long serialVersionUID = 8638589328461138178L;

            public Repository getRepository() {
                return repoContext.getRepository();
            }
        });
        simple.setInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_CONFIG, "/config.xml");
        ServletHolder remoting = new ServletHolder(new JcrRemotingServlet() {

            private static final long serialVersionUID = -2969534124090379387L;

            public Repository getRepository() {
                return repoContext.getRepository();
            }
        });
        remoting.setInitParameter(JcrRemotingServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "/remoting");
        ServletContextHandler schandler = new ServletContextHandler(server, "/");
        schandler.addServlet(simple, SIMPLE_WEBDAV_SERVLET_PATH_MAPPING);
        schandler.addServlet(remoting, REMOTING_WEBDAV_SERVLET_PATH_MAPPING);
        schandler.setBaseResource(Resource.newClassPathResource("/"));
        server.setHandler(schandler);
    }
    if (httpConnector == null) {
        httpConnector = new ServerConnector(server);
        httpConnector.setHost("localhost");
        httpConnector.setPort(0);
        server.addConnector(httpConnector);
    }
    if (httpsConnector == null) {
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(keystore.getPath());
        sslContextFactory.setKeyStorePassword(KEYSTOREPW);
        sslContextFactory.setKeyManagerPassword(KEYSTOREPW);
        sslContextFactory.setTrustStorePath(keystore.getPath());
        sslContextFactory.setTrustStorePassword(KEYSTOREPW);
        SslConnectionFactory cfac = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString());
        httpsConnector = new ServerConnector(server, cfac, new HttpConnectionFactory(new HttpConfiguration()));
        httpsConnector.setHost("localhost");
        httpsConnector.setPort(0);
        server.addConnector(httpsConnector);
    }
    if (!server.isStarted()) {
        try {
            server.start();
        } catch (Exception e) {
            throw new RepositoryStubException(e);
        }
    }
    this.uri = new URI("http", null, "localhost", httpConnector.getLocalPort(), "/default/", null, null);
    this.remotingUri = new URI("http", null, "localhost", httpConnector.getLocalPort(), REMOTING_PREFIX + "/", null, null);
    this.httpsUri = new URI("https", null, "localhost", httpsConnector.getLocalPort(), "/default/", null, null);
    this.root = this.uri.toASCIIString();
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    // cm.setMaxTotal(100);
    HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort());
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("admin", "admin"));
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local auth cache
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(targetHost, basicAuth);
    // Add AuthCache to the execution context
    this.context = HttpClientContext.create();
    this.context.setCredentialsProvider(credsProvider);
    this.context.setAuthCache(authCache);
    this.client = HttpClients.custom().setConnectionManager(cm).build();
    super.setUp();
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) URI(java.net.URI) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SimpleWebdavServlet(org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet) HttpHost(org.apache.http.HttpHost) BasicScheme(org.apache.http.impl.auth.BasicScheme) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) JcrRemotingServlet(org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Repository(javax.jcr.Repository) AuthScope(org.apache.http.auth.AuthScope) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File)

Aggregations

RepositoryStubException (org.apache.jackrabbit.test.RepositoryStubException)7 RepositoryException (javax.jcr.RepositoryException)6 Repository (javax.jcr.Repository)4 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)3 File (java.io.File)2 IOException (java.io.IOException)2 AbstractRepositoryConfig (org.apache.jackrabbit.jcr2spi.AbstractRepositoryConfig)2 JcrRemotingServlet (org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet)2 RepositoryService (org.apache.jackrabbit.spi.RepositoryService)2 Server (org.eclipse.jetty.server.Server)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 ServletException (javax.servlet.ServletException)1