use of org.apache.jackrabbit.spi.RepositoryService in project jackrabbit by apache.
the class ConnectionTest method testObtainInvalidURIWithConnectionTimeout.
public void testObtainInvalidURIWithConnectionTimeout() throws URISyntaxException, RepositoryException {
// make sure it takes long enough before a timeout is happening
Map<String, String> parameters = new HashMap<>();
ConnectionOptions.Builder builder = ConnectionOptions.builder();
int connectionTimeoutMs = 1000;
builder.connectionTimeoutMs(connectionTimeoutMs);
parameters.putAll(builder.build().toServiceFactoryParameters());
// overwrite URI (use non-routable IP to run into connection timeout)
parameters.put(Spi2davexRepositoryServiceFactory.PARAM_REPOSITORY_URI, "http://10.0.0.0");
RepositoryService repositoryService = createRepositoryService(true, parameters);
long beforeTimeMs = System.currentTimeMillis();
try {
repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
fail("Should have run into a connect exception");
} catch (RepositoryException e) {
if (!(e.getCause() instanceof ConnectTimeoutException)) {
fail("Expected a connect timeout but received " + e);
}
}
long afterTimeMs = System.currentTimeMillis();
assertTrue("Have not waited long enough!", afterTimeMs - beforeTimeMs >= connectionTimeoutMs);
}
use of org.apache.jackrabbit.spi.RepositoryService in project jackrabbit by apache.
the class ConnectionTest method testObtainWithTLSSelfSignedCertAllowed.
public void testObtainWithTLSSelfSignedCertAllowed() throws RepositoryException, URISyntaxException {
Map<String, String> parameters = new HashMap<>();
ConnectionOptions.Builder builder = ConnectionOptions.builder();
builder.allowSelfSignedCertificates(true);
parameters.putAll(builder.build().toServiceFactoryParameters());
RepositoryService repositoryService = createRepositoryService(true, parameters);
try {
repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
} catch (RepositoryException e) {
Throwable cause = ExceptionUtils.getRootCause(e);
if (!(cause instanceof SSLPeerUnverifiedException)) {
fail("should have failed with SSLPeerUnverifiedException but got " + e.getCause());
}
}
}
use of org.apache.jackrabbit.spi.RepositoryService in project jackrabbit by apache.
the class ConnectionTest method testObtainViaProxy.
public void testObtainViaProxy() throws URISyntaxException, RepositoryException {
HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(// use arbitrary port
0).start();
try {
Map<String, String> parameters = new HashMap<>();
ConnectionOptions.Builder builder = ConnectionOptions.builder();
builder.proxyHost("127.0.0.1");
builder.proxyPort(proxyServer.getListenAddress().getPort());
parameters.putAll(builder.build().toServiceFactoryParameters());
RepositoryService repositoryService = createRepositoryService(false, parameters);
repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
} finally {
proxyServer.stop();
}
}
use of org.apache.jackrabbit.spi.RepositoryService in project jackrabbit by apache.
the class ConnectionTest method testObtainViaProxyWithInvalidCredentials.
public void testObtainViaProxyWithInvalidCredentials() throws URISyntaxException, RepositoryException {
ProxyAuthenticator authenticator = new ProxyAuthenticator() {
@Override
public String getRealm() {
return null;
}
@Override
public boolean authenticate(String userName, String password) {
return false;
}
};
HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(// use arbitrary port
0).withProxyAuthenticator(authenticator).start();
try {
Map<String, String> parameters = new HashMap<>();
ConnectionOptions.Builder builder = ConnectionOptions.builder();
builder.proxyHost("127.0.0.1");
builder.proxyPort(proxyServer.getListenAddress().getPort());
builder.proxyUsername("test");
builder.proxyPassword("invalid");
parameters.putAll(builder.build().toServiceFactoryParameters());
RepositoryService repositoryService = createRepositoryService(false, parameters);
try {
repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
fail("should have failed with proxy authentication failure!");
} catch (RepositoryException expected) {
}
} finally {
proxyServer.stop();
}
}
use of org.apache.jackrabbit.spi.RepositoryService 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;
}
Aggregations