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