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);
}
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations