use of javax.naming.InitialContext in project ignite by apache.
the class CacheJndiTmFactorySelfTest method beforeTestsStarted.
/** {@inheritDoc} */
@Override
protected void beforeTestsStarted() throws Exception {
super.beforeTestsStarted();
initCtxFactoryBackup = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
urlPkgPrefixesBackup = System.getProperty(Context.URL_PKG_PREFIXES);
// Create initial context
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
InitialContext ic = new InitialContext();
ic.createSubcontext("java:");
ic.createSubcontext("java:/comp");
ic.createSubcontext("java:/comp/env");
ic.createSubcontext("java:/comp/env/tm");
ic.bind(TM_JNDI_NAME, new TestTransactionManager());
ic.bind(TM_JNDI_NAME2, new TestTransactionManager2());
ic.bind(NOT_TM_JNDI_NAME, 1);
}
use of javax.naming.InitialContext in project jackrabbit by apache.
the class JNDIDatabaseJournal method getConnection.
//-----------------------------------------------------< DatabaseJournal >
/**
* Returns a JDBC connection from a {@link DataSource} acquired from JNDI
* with the configured data source location.
*
* @return new database connection
* @throws SQLException if a database access error occurs
* @see DataSource#getConnection()
*/
protected Connection getConnection() throws SQLException {
try {
InitialContext ic = new InitialContext();
DataSource dataSource = (DataSource) ic.lookup(dataSourceLocation);
return dataSource.getConnection();
} catch (NamingException e) {
SQLException exception = new SQLException("DataSource not found: " + dataSourceLocation);
exception.initCause(e);
throw exception;
}
}
use of javax.naming.InitialContext in project jackrabbit by apache.
the class JNDIDatabasePersistenceManager method getConnection.
//-------------------------------------------< DatabasePersistenceManager >
/**
* Returns a JDBC connection from a {@link DataSource} acquired from JNDI
* with the configured data source location.
*
* @return new database connection
* @throws NamingException if the given data source location does not exist
* @throws SQLException if a database access error occurs
* @see DatabasePersistenceManager#getConnection()
*/
protected Connection getConnection() throws NamingException, SQLException {
InitialContext ic = new InitialContext();
DataSource dataSource = (DataSource) ic.lookup(dataSourceLocation);
return dataSource.getConnection();
}
use of javax.naming.InitialContext in project jackrabbit by apache.
the class RepositoryStartupServlet method registerJNDI.
/**
* Binds the repository to the JNDI context
* @throws ServletException if an error occurs.
*/
private void registerJNDI() throws ServletException {
JNDIConfig jc = config.getJndiConfig();
if (jc.isValid() && jc.enabled()) {
try {
jndiContext = new InitialContext(jc.getJndiEnv());
jndiContext.bind(jc.getJndiName(), repository);
log.info("Repository bound to JNDI with name: " + jc.getJndiName());
} catch (NamingException e) {
throw new ServletExceptionWithCause("Unable to bind repository using JNDI: " + jc.getJndiName(), e);
}
}
}
use of javax.naming.InitialContext in project jackrabbit by apache.
the class JNDIRemoteRepositoryServlet method getRepository.
/**
* Returns the remote repository in the configured JNDI location.
*
* @return repository
* @throws RepositoryException if the repository could not be accessed
*/
@Override
protected Repository getRepository() throws RepositoryException {
String location = "//localhost/" + RemoteRepository.class.getName().replace('.', '/');
try {
Hashtable environment = new Hashtable();
Enumeration names = getInitParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (name.equals("location")) {
location = getInitParameter(name);
} else if (!name.equals(Repository.class.getName()) && !name.equals(LocalAdapterFactory.class.getName())) {
environment.put(name, getInitParameter(name));
}
}
return new JNDIRemoteRepositoryFactory(getLocalAdapterFactory(), new InitialContext(environment), location).getRepository();
} catch (NamingException e) {
throw new RepositoryException("Repository not found: Invalid JNDI context", e);
}
}
Aggregations