Search in sources :

Example 91 with InitialContext

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);
}
Also used : InitialContext(javax.naming.InitialContext)

Example 92 with InitialContext

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;
    }
}
Also used : SQLException(java.sql.SQLException) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource)

Example 93 with InitialContext

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();
}
Also used : InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource)

Example 94 with InitialContext

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);
        }
    }
}
Also used : NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 95 with InitialContext

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);
    }
}
Also used : Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) NamingException(javax.naming.NamingException) RepositoryException(javax.jcr.RepositoryException) JNDIRemoteRepositoryFactory(org.apache.jackrabbit.rmi.repository.JNDIRemoteRepositoryFactory) InitialContext(javax.naming.InitialContext)

Aggregations

InitialContext (javax.naming.InitialContext)1068 Test (org.junit.Test)325 EJBException (javax.ejb.EJBException)228 Properties (java.util.Properties)213 Context (javax.naming.Context)194 RemoteException (java.rmi.RemoteException)173 TestFailureException (org.apache.openejb.test.TestFailureException)172 NamingException (javax.naming.NamingException)168 AssertionFailedError (junit.framework.AssertionFailedError)168 JMSException (javax.jms.JMSException)167 RemoveException (javax.ejb.RemoveException)66 CreateException (javax.ejb.CreateException)57 DataSource (javax.sql.DataSource)55 Hashtable (java.util.Hashtable)54 Assembler (org.apache.openejb.assembler.classic.Assembler)47 EjbJar (org.apache.openejb.jee.EjbJar)41 NameNotFoundException (javax.naming.NameNotFoundException)40 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)38 Connection (java.sql.Connection)37 StatelessBean (org.apache.openejb.jee.StatelessBean)30