Search in sources :

Example 36 with StringRefAddr

use of javax.naming.StringRefAddr in project jetty.project by eclipse.

the class TestNamingEntries method testResourceReference.

@Test
public void testResourceReference() throws Exception {
    RefAddr refAddr = new StringRefAddr("val", "10");
    Reference ref = new Reference(SomeObject.class.getName(), refAddr, SomeObjectFactory.class.getName(), null);
    InitialContext icontext = new InitialContext();
    Resource resource = new Resource(null, "resourceByRef", ref);
    NamingEntry ne = NamingEntryUtil.lookupNamingEntry(null, "resourceByRef");
    assertNotNull(ne);
    assertTrue(ne instanceof Resource);
    Object o = icontext.lookup("resourceByRef");
    assertNotNull(o);
    assertTrue(o instanceof SomeObject);
    assertEquals(((SomeObject) o).getValue(), 10);
}
Also used : RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 37 with StringRefAddr

use of javax.naming.StringRefAddr in project hibernate-orm by hibernate.

the class JndiRegionFactoryTest method bind.

/**
	 * Helper method that binds the a non serializable object to the JNDI tree.
	 *
	 * @param jndiName Name under which the object must be bound
	 * @param who Object to bind in JNDI
	 * @param classType Class type under which should appear the bound object
	 * @param ctx Naming context under which we bind the object
	 * @throws Exception Thrown if a naming exception occurs during binding
	 */
private void bind(String jndiName, Object who, Class<?> classType, Context ctx) throws Exception {
    // Ah ! This service isn't serializable, so we use a helper class
    NonSerializableFactory.bind(jndiName, who);
    Name n = ctx.getNameParser("").parse(jndiName);
    while (n.size() > 1) {
        String ctxName = n.get(0);
        try {
            ctx = (Context) ctx.lookup(ctxName);
        } catch (NameNotFoundException e) {
            log.debug("creating Subcontext " + ctxName);
            ctx = ctx.createSubcontext(ctxName);
        }
        n = n.getSuffix(1);
    }
    // The helper class NonSerializableFactory uses address type nns, we go on to
    // use the helper class to bind the service object in JNDI
    StringRefAddr addr = new StringRefAddr("nns", jndiName);
    Reference ref = new Reference(classType.getName(), addr, NonSerializableFactory.class.getName(), null);
    ctx.rebind(n.get(0), ref);
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NonSerializableFactory(org.jboss.util.naming.NonSerializableFactory) Name(javax.naming.Name)

Example 38 with StringRefAddr

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

the class NamingContextTestCase method testLookupWitResolveResult.

@Test
public void testLookupWitResolveResult() throws Exception {
    namingStore.bind(new CompositeName("test/nested"), "test");
    final Reference reference = new Reference(String.class.getName(), new StringRefAddr("blahh", "test"), TestObjectFactoryWithNameResolution.class.getName(), null);
    namingStore.bind(new CompositeName("comp"), reference);
    Object result = namingContext.lookup(new CompositeName("comp/nested"));
    assertEquals("test", result);
    //the same with security permissions
    result = testActionPermission(JndiPermission.ACTION_LOOKUP, Arrays.asList(new JndiPermission("test/nested", "lookup")), namingContext, "comp/nested");
    assertEquals("test", result);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) Test(org.junit.Test)

Example 39 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)

Example 40 with StringRefAddr

use of javax.naming.StringRefAddr in project voltdb by VoltDB.

the class JDBCDataSource method getReference.

// javadoc to be copied from javax.naming.Referenceable.getReference()
public Reference getReference() throws NamingException {
    String cname = "org.hsqldb_voltpatches.jdbc.JDBCDataSourceFactory";
    Reference ref = new Reference(getClass().getName(), cname, null);
    ref.add(new StringRefAddr("database", getDatabase()));
    ref.add(new StringRefAddr("user", getUser()));
    ref.add(new StringRefAddr("password", password));
    return ref;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Aggregations

StringRefAddr (javax.naming.StringRefAddr)67 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 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 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 Map (java.util.Map)4 Context (javax.naming.Context)4 NameNotFoundException (javax.naming.NameNotFoundException)3 Context (org.apache.catalina.Context)3 NamingContext (org.apache.naming.NamingContext)3