Search in sources :

Example 66 with Binding

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);
}
Also used : Binding(javax.naming.Binding) CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 67 with Binding

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

Example 68 with Binding

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

Example 69 with Binding

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

Example 70 with Binding

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);
    }
}
Also used : Binding(javax.naming.Binding) InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) OperationNotSupportedException(javax.naming.OperationNotSupportedException) UserDatabase(org.apache.catalina.UserDatabase) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException)

Aggregations

Binding (javax.naming.Binding)70 NamingException (javax.naming.NamingException)37 Context (javax.naming.Context)31 InitialContext (javax.naming.InitialContext)29 NameNotFoundException (javax.naming.NameNotFoundException)22 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)20 Name (javax.naming.Name)19 NotContextException (javax.naming.NotContextException)18 OperationNotSupportedException (javax.naming.OperationNotSupportedException)18 Reference (javax.naming.Reference)17 CompoundName (javax.naming.CompoundName)16 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 NamingContext (org.eclipse.jetty.jndi.NamingContext)9 CompositeName (javax.naming.CompositeName)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 NamingEnumeration (javax.naming.NamingEnumeration)5 ServletContext (javax.servlet.ServletContext)5 MalformedURLException (java.net.MalformedURLException)4