use of javax.naming.Binding in project wildfly by wildfly.
the class NamingContextTestCase method testListBindings.
@Test
@SuppressWarnings("unchecked")
public void testListBindings() throws Exception {
bindList();
NamingEnumeration<Binding> results = namingContext.listBindings(new CompositeName());
checkListResults(results);
// the same with security permissions
results = (NamingEnumeration<Binding>) testActionPermission(JndiPermission.ACTION_LIST_BINDINGS, namingContext, null);
checkListResults(results);
}
use of javax.naming.Binding in project aries by apache.
the class ServiceRegistryContextTest method listRepositoryBindings.
/**
* This test checks that we can list the contents of the repository using the
* list method
*
* @throws NamingException
*/
public void listRepositoryBindings() throws NamingException {
InitialContext ctx = new InitialContext();
NamingEnumeration<Binding> serviceList = ctx.listBindings("osgi:service/java.lang.Runnable/(rubbish=smelly)");
Object returnedService = checkThreadRetrievedViaListBindingsMethod(serviceList);
assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
assertTrue("The returned service was not the service we expected", returnedService == service);
// Now add a second service
Thread secondService = new Thread();
registerService(secondService);
serviceList = ctx.listBindings("osgi:service/java.lang.Runnable/(rubbish=smelly)");
Object returnedService1 = checkThreadRetrievedViaListBindingsMethod(serviceList);
Object returnedService2 = checkThreadRetrievedViaListBindingsMethod(serviceList);
assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
assertTrue("The services were not the ones we expected!", (returnedService1 == service || returnedService2 == service) && (returnedService1 == secondService || returnedService2 == secondService) && (returnedService1 != returnedService2));
}
use of javax.naming.Binding in project aries by apache.
the class XaPooledConnectionFactory method configFromJndiConf.
private void configFromJndiConf(Object rootContextName) {
if (rootContextName instanceof String) {
String name = (String) rootContextName;
name = name.substring(0, name.lastIndexOf('/')) + "/conf" + name.substring(name.lastIndexOf('/'));
try {
InitialContext ctx = new InitialContext();
NamingEnumeration<Binding> bindings = ctx.listBindings(name);
while (bindings.hasMore()) {
Binding bd = bindings.next();
IntrospectionSupport.setProperty(this, bd.getName(), bd.getObject());
}
} catch (Exception ignored) {
if (LOG.isTraceEnabled()) {
LOG.trace("exception on config from jndi: " + name, ignored);
}
}
}
}
use of javax.naming.Binding in project tomcat by apache.
the class NamingContextBindingsEnumeration method nextElementInternal.
private Binding nextElementInternal() throws NamingException {
NamingEntry entry = iterator.next();
Object value;
// If the entry is a reference, resolve it
if (entry.type == NamingEntry.REFERENCE || entry.type == NamingEntry.LINK_REF) {
try {
value = ctx.lookup(new CompositeName(entry.name));
} catch (NamingException e) {
throw e;
} catch (Exception e) {
NamingException ne = new NamingException(e.getMessage());
ne.initCause(e);
throw ne;
}
} else {
value = entry.value;
}
return new Binding(entry.name, value.getClass().getName(), value, true);
}
use of javax.naming.Binding in project tomcat by apache.
the class GlobalResourcesLifecycleListener method createMBeans.
/**
* Create the MBeans for the interesting global JNDI resources in
* the specified naming context.
*
* @param prefix Prefix for complete object name paths
* @param context Context to be scanned
*
* @exception NamingException if a JNDI exception occurs
*/
protected void createMBeans(String prefix, Context context) throws NamingException {
if (log.isDebugEnabled()) {
log.debug("Creating MBeans for Global JNDI Resources in Context '" + prefix + "'");
}
try {
NamingEnumeration<Binding> bindings = context.listBindings("");
while (bindings.hasMore()) {
Binding binding = bindings.next();
String name = prefix + binding.getName();
Object value = context.lookup(binding.getName());
if (log.isDebugEnabled()) {
log.debug("Checking resource " + name);
}
if (value instanceof Context) {
createMBeans(name + "/", (Context) value);
} else if (value instanceof UserDatabase) {
try {
createMBeans(name, (UserDatabase) value);
} catch (Exception e) {
log.error(sm.getString("globalResources.userDatabaseCreateError", name), e);
}
}
}
} catch (RuntimeException ex) {
log.error(sm.getString("globalResources.createError.runtime"), ex);
} catch (OperationNotSupportedException ex) {
log.error(sm.getString("globalResources.createError.operation"), ex);
}
}
Aggregations