Search in sources :

Example 61 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat by apache.

the class SharedPoolDataSource method getReference.

/**
 * Creates a new {@link Reference} to a {@link SharedPoolDataSource}.
 */
@Override
public Reference getReference() throws NamingException {
    final Reference ref = new Reference(getClass().getName(), SharedPoolDataSourceFactory.class.getName(), null);
    ref.add(new StringRefAddr("instanceKey", getInstanceKey()));
    return ref;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Example 62 with StringRefAddr

use of javax.naming.StringRefAddr in project druid by alibaba.

the class DruidDataSource method getReference.

public Reference getReference() throws NamingException {
    final String className = getClass().getName();
    // XXX: not robust
    final String factoryName = className + "Factory";
    Reference ref = new Reference(className, factoryName, null);
    ref.add(new StringRefAddr("instanceKey", instanceKey));
    ref.add(new StringRefAddr("url", this.getUrl()));
    ref.add(new StringRefAddr("username", this.getUsername()));
    ref.add(new StringRefAddr("password", this.getPassword()));
    // TODO ADD OTHER PROPERTIES
    return ref;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Example 63 with StringRefAddr

use of javax.naming.StringRefAddr in project druid by alibaba.

the class DruidDataSourceFactoryTest method test_factory.

public void test_factory() throws Exception {
    DruidDataSourceFactory factory = new DruidDataSourceFactory();
    Reference ref = new Reference(DataSource.class.getName());
    ref.add(new StringRefAddr(DruidDataSourceFactory.PROP_REMOVEABANDONED, "true"));
    ref.add(new StringRefAddr(DruidDataSourceFactory.PROP_MAXACTIVE, "20"));
    Hashtable<String, String> env = new Hashtable<String, String>();
    dataSource = (DruidDataSource) factory.getObjectInstance(ref, null, null, env);
    Assert.assertTrue(dataSource.isRemoveAbandoned());
    Assert.assertEquals(20, dataSource.getMaxActive());
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) Hashtable(java.util.Hashtable) DruidDataSourceFactory(com.alibaba.druid.pool.DruidDataSourceFactory) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) DataSource(javax.sql.DataSource)

Example 64 with StringRefAddr

use of javax.naming.StringRefAddr in project jackrabbit by apache.

the class RegistryHelper method registerRepository.

/**
 * Binds a configured repository to the given JNDI context.
 * This method creates a {@link BindableRepository BindableRepository}
 * instance using the given configuration information, and binds
 * it to the given JNDI context.
 *
 * @param ctx            context where the repository should be registered (i.e. bound)
 * @param name           the name to register the repository with
 * @param configFilePath path to the configuration file of the repository
 * @param repHomeDir     repository home directory
 * @param overwrite      if <code>true</code>, any existing binding with the given
 *                       name will be overwritten; otherwise a <code>NamingException</code> will
 *                       be thrown if the name is already bound
 * @throws RepositoryException if the repository cannot be created
 * @throws NamingException if the repository cannot be registered in JNDI
 */
public static void registerRepository(Context ctx, String name, String configFilePath, String repHomeDir, boolean overwrite) throws NamingException, RepositoryException {
    Reference reference = new Reference(Repository.class.getName(), BindableRepositoryFactory.class.getName(), // no classpath defined
    null);
    reference.add(new StringRefAddr(BindableRepository.CONFIGFILEPATH_ADDRTYPE, configFilePath));
    reference.add(new StringRefAddr(BindableRepository.REPHOMEDIR_ADDRTYPE, repHomeDir));
    // always create instance by using BindableRepositoryFactory
    // which maintains an instance cache;
    // see http://issues.apache.org/jira/browse/JCR-411 for details
    Object obj = new BindableRepositoryFactory().getObjectInstance(reference, null, null, null);
    if (overwrite) {
        ctx.rebind(name, obj);
    } else {
        ctx.bind(name, obj);
    }
}
Also used : Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Example 65 with StringRefAddr

use of javax.naming.StringRefAddr in project wildfly by wildfly.

the class NamingContextTestCase method testLookupReference.

@Test
public void testLookupReference() throws Exception {
    final Name name = new CompositeName("test");
    final Reference reference = new Reference(String.class.getName(), new StringRefAddr("blah", "test"), TestObjectFactory.class.getName(), null);
    namingStore.bind(name, reference);
    Object result = namingContext.lookup(name);
    assertEquals("test", result);
    // the same with security permissions
    result = testActionPermission(JndiPermission.ACTION_LOOKUP, namingContext, "test");
    assertEquals("test", result);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) Test(org.junit.Test)

Aggregations

StringRefAddr (javax.naming.StringRefAddr)68 Reference (javax.naming.Reference)51 NamingException (javax.naming.NamingException)18 RefAddr (javax.naming.RefAddr)9 Test (org.junit.Test)8 Name (javax.naming.Name)7 Properties (java.util.Properties)6 CompositeName (javax.naming.CompositeName)5 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)5 ObjectFactory (javax.naming.spi.ObjectFactory)5 MalformedURLException (java.net.MalformedURLException)4 Enumeration (java.util.Enumeration)4 Hashtable (java.util.Hashtable)4 Iterator (java.util.Iterator)4 Context (javax.naming.Context)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 NameNotFoundException (javax.naming.NameNotFoundException)3 Context (org.apache.catalina.Context)3 NamingContext (org.apache.naming.NamingContext)3