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