Search in sources :

Example 1 with RepositoryAddress

use of org.apache.jackrabbit.vault.fs.api.RepositoryAddress in project sling by apache.

the class VltSerializationManager method main.

public static void main(String[] args) throws RepositoryException, URISyntaxException, IOException {
    RepositoryAddress address = new RepositoryAddress("http://localhost:8080/server/root");
    Repository repo = new RepositoryProvider().getRepository(address);
    Session session = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
    VaultFileSystem fs = Mounter.mount(null, null, address, "/", session);
    String[] attempts = new String[] { "/rep:policy", "/var" };
    for (String attempt : attempts) {
        VaultFile vaultFile = fs.getFile(attempt);
        System.out.println(attempt + " -> " + vaultFile);
    }
    for (String attempt : attempts) {
        attempt = PlatformNameFormat.getPlatformPath(attempt) + EXTENSION_XML;
        VaultFile vaultFile = fs.getFile(attempt);
        System.out.println(attempt + " -> " + vaultFile);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) RepositoryAddress(org.apache.jackrabbit.vault.fs.api.RepositoryAddress) Repository(javax.jcr.Repository) VaultFileSystem(org.apache.jackrabbit.vault.fs.api.VaultFileSystem) VaultFile(org.apache.jackrabbit.vault.fs.api.VaultFile) RepositoryProvider(org.apache.jackrabbit.vault.util.RepositoryProvider) Session(javax.jcr.Session)

Example 2 with RepositoryAddress

use of org.apache.jackrabbit.vault.fs.api.RepositoryAddress in project sling by apache.

the class RepositoryUtilsTest method testWebDavUrlLocationForSling.

@Test
public void testWebDavUrlLocationForSling() throws URISyntaxException {
    // make sure AEM url contains workspace name
    String url = "http://localhost:4502/" + RepositoryUtils.WEBDAV_URL_LOCATIONS[0];
    RepositoryAddress address = new RepositoryAddress(url);
    // make sure the workspace name is correctly extracted
    Assert.assertEquals("default", address.getWorkspace());
}
Also used : RepositoryAddress(org.apache.jackrabbit.vault.fs.api.RepositoryAddress) Test(org.junit.Test)

Example 3 with RepositoryAddress

use of org.apache.jackrabbit.vault.fs.api.RepositoryAddress in project sling by apache.

the class RepositoryUtilsTest method testWebDavUrlLocationForAEM.

@Test
public void testWebDavUrlLocationForAEM() throws URISyntaxException {
    // make sure AEM url contains workspace name
    String url = "http://localhost:4502/" + RepositoryUtils.WEBDAV_URL_LOCATIONS[1];
    RepositoryAddress address = new RepositoryAddress(url);
    // make sure the workspace name is correctly extracted
    Assert.assertEquals("crx.default", address.getWorkspace());
}
Also used : RepositoryAddress(org.apache.jackrabbit.vault.fs.api.RepositoryAddress) Test(org.junit.Test)

Example 4 with RepositoryAddress

use of org.apache.jackrabbit.vault.fs.api.RepositoryAddress in project sling by apache.

the class RepositoryUtils method getRepositoryAddress.

public static RepositoryAddress getRepositoryAddress(RepositoryInfo repositoryInfo) {
    StringBuilder errors = new StringBuilder();
    for (String webDavUrlLocation : WEBDAV_URL_LOCATIONS) {
        Session session = null;
        String url = repositoryInfo.appendPath(webDavUrlLocation);
        try {
            RepositoryAddress address = new RepositoryAddress(url);
            Repository repository;
            synchronized (SYNC) {
                repository = REGISTERED_REPOSITORIES.get(address);
                if (repository == null) {
                    Set<String> supportedSchemes = FACTORY.getSupportedSchemes();
                    if (!supportedSchemes.contains(address.getURI().getScheme())) {
                        throw new IllegalArgumentException("Unable to create a a repository for " + address.getURI() + ", since the scheme is unsupported. Only schemes '" + supportedSchemes + "' are supported");
                    }
                    // SLING-3739: ensure that a well-known ClassLoader is used
                    ClassLoader old = Thread.currentThread().getContextClassLoader();
                    Thread.currentThread().setContextClassLoader(Repository.class.getClassLoader());
                    try {
                        repository = FACTORY.createRepository(address);
                    } finally {
                        Thread.currentThread().setContextClassLoader(old);
                    }
                    REGISTERED_REPOSITORIES.put(address, repository);
                }
            }
            session = repository.login(new SimpleCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword().toCharArray()));
            return address;
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        } catch (RepositoryException e) {
            Activator.getDefault().getPluginLogger().trace("Failed connecting to repository at " + url, e);
            errors.append(url).append(" : ").append(e.getMessage()).append('\n');
            continue;
        } finally {
            if (session != null) {
                session.logout();
            }
        }
    }
    errors.deleteCharAt(errors.length() - 1);
    throw new IllegalArgumentException("No repository found at " + repositoryInfo.getUrl() + "\n" + errors.toString());
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) RepositoryAddress(org.apache.jackrabbit.vault.fs.api.RepositoryAddress) Repository(javax.jcr.Repository) RepositoryException(javax.jcr.RepositoryException) URISyntaxException(java.net.URISyntaxException) Session(javax.jcr.Session)

Example 5 with RepositoryAddress

use of org.apache.jackrabbit.vault.fs.api.RepositoryAddress in project sling by apache.

the class VltSerializationDataBuilder method init.

public void init(org.apache.sling.ide.transport.Repository repository, File contentSyncRoot) throws SerializationException {
    this.repo = repository;
    try {
        this.skm = new SerializationKindManager();
        this.skm.init(repository);
        if (!contentSyncRoot.exists()) {
            throw new IllegalArgumentException("contentSyncRoot does not exist: " + contentSyncRoot);
        }
        Repository jcrRepo = RepositoryUtils.getRepository(repo.getRepositoryInfo());
        Credentials credentials = RepositoryUtils.getCredentials(repo.getRepositoryInfo());
        session = jcrRepo.login(credentials);
        RepositoryAddress address = RepositoryUtils.getRepositoryAddress(repo.getRepositoryInfo());
        fs = fsLocator.getFileSystem(address, contentSyncRoot, session);
    } catch (org.apache.sling.ide.transport.RepositoryException e) {
        throw new SerializationException(e);
    } catch (RepositoryException e) {
        throw new SerializationException(e);
    } catch (IOException e) {
        throw new SerializationException(e);
    } catch (ConfigurationException e) {
        throw new SerializationException(e);
    }
}
Also used : RepositoryAddress(org.apache.jackrabbit.vault.fs.api.RepositoryAddress) SerializationException(org.apache.sling.ide.serialization.SerializationException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) SerializationKindManager(org.apache.sling.ide.serialization.SerializationKindManager) Repository(javax.jcr.Repository) ConfigurationException(org.apache.jackrabbit.vault.fs.config.ConfigurationException) Credentials(javax.jcr.Credentials)

Aggregations

RepositoryAddress (org.apache.jackrabbit.vault.fs.api.RepositoryAddress)5 Repository (javax.jcr.Repository)3 RepositoryException (javax.jcr.RepositoryException)2 Session (javax.jcr.Session)2 SimpleCredentials (javax.jcr.SimpleCredentials)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Credentials (javax.jcr.Credentials)1 VaultFile (org.apache.jackrabbit.vault.fs.api.VaultFile)1 VaultFileSystem (org.apache.jackrabbit.vault.fs.api.VaultFileSystem)1 ConfigurationException (org.apache.jackrabbit.vault.fs.config.ConfigurationException)1 RepositoryProvider (org.apache.jackrabbit.vault.util.RepositoryProvider)1 SerializationException (org.apache.sling.ide.serialization.SerializationException)1 SerializationKindManager (org.apache.sling.ide.serialization.SerializationKindManager)1