Search in sources :

Example 26 with Binding

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

the class ServiceBasedNamingStoreTestCase method testListBindings.

@Test
public void testListBindings() throws Exception {
    final Object value = new Object();
    bindObject(ServiceName.JBOSS.append("TestBean"), value);
    bindObject(ServiceName.JBOSS.append("foo", "TestBean"), value);
    bindObject(ServiceName.JBOSS.append("foo", "bar", "TestBean"), value);
    bindObject(ServiceName.JBOSS.append("foo", "bar", "baz", "TestBean"), value);
    store.add(ServiceName.JBOSS.append("foos", "bar"));
    store.add(ServiceName.JBOSS.append("fo", "bar"));
    store.add(ServiceName.JBOSS.append("foo", "ba", "baz"));
    store.add(ServiceName.JBOSS.append("foo", "bart", "baz"));
    store.add(ServiceName.JBOSS.append("foo", "bar", "ba"));
    store.add(ServiceName.JBOSS.append("foo", "bar", "bazt"));
    store.add(ServiceName.JBOSS.append("foo", "bar", "art"));
    store.add(ServiceName.JBOSS.append("other", "one"));
    List<Binding> list = store.listBindings(new CompositeName(""));
    assertEquals(5, list.size());
    assertContains(list, "TestBean", Object.class);
    assertContains(list, "foo", NamingContext.class);
    assertContains(list, "fo", NamingContext.class);
    assertContains(list, "foos", NamingContext.class);
    assertContains(list, "other", NamingContext.class);
    list = store.listBindings(new CompositeName("foo"));
    assertEquals(4, list.size());
    assertContains(list, "TestBean", Object.class);
    assertContains(list, "ba", NamingContext.class);
    assertContains(list, "bart", NamingContext.class);
    assertContains(list, "bar", NamingContext.class);
    for (Binding binding : list) {
        if (binding.getName().equals("bar")) {
            final Object bean = Context.class.cast(binding.getObject()).lookup("TestBean");
            assertNotNull(bean);
            assertEquals(value, bean);
        }
    }
}
Also used : Binding(javax.naming.Binding) StopContext(org.jboss.msc.service.StopContext) Context(javax.naming.Context) StartContext(org.jboss.msc.service.StartContext) CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 27 with Binding

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

the class InMemoryNamingStoreTestCase method testListBindings.

@Test
public void testListBindings() throws Exception {
    final Name name = new CompositeName("test");
    final Object object = new Object();
    nameStore.bind(name, object);
    final Name nameTwo = new CompositeName("testTwo");
    final Object objectTwo = new Object();
    nameStore.bind(nameTwo, objectTwo);
    final Name nameThree = new CompositeName("testThree");
    final Object objectThree = new Object();
    nameStore.bind(nameThree, objectThree);
    nameStore.bind(new CompositeName("testContext/test"), "test");
    final List<Binding> results = nameStore.listBindings(new CompositeName());
    assertEquals(4, results.size());
    final Set<String> expected = new HashSet<String>(Arrays.asList("test", "testTwo", "testThree", "testContext"));
    for (Binding result : results) {
        final String resultName = result.getName();
        if ("test".equals(resultName)) {
            assertEquals(Object.class.getName(), result.getClassName());
            assertEquals(object, result.getObject());
        } else if ("testTwo".equals(resultName)) {
            assertEquals(Object.class.getName(), result.getClassName());
            assertEquals(objectTwo, result.getObject());
        } else if ("testThree".equals(resultName)) {
            assertEquals(Object.class.getName(), result.getClassName());
            assertEquals(objectThree, result.getObject());
        } else if ("testContext".equals(resultName)) {
            assertEquals(Context.class.getName(), result.getClassName());
        } else {
            fail("Unknown result name: " + resultName);
        }
        expected.remove(resultName);
    }
    assertTrue("Not all expected results were returned", expected.isEmpty());
}
Also used : Binding(javax.naming.Binding) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with Binding

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

the class NamingContextTestCase method testListBindingsWithContinuation.

@Test
@SuppressWarnings("unchecked")
public void testListBindingsWithContinuation() throws Exception {
    bindListWithContinuations();
    NamingEnumeration<Binding> results = namingContext.listBindings(new CompositeName("comp"));
    checkListWithContinuationsResults(results);
    // the same with security permissions
    results = (NamingEnumeration<Binding>) testActionPermission(JndiPermission.ACTION_LIST_BINDINGS, Arrays.asList(new JndiPermission("test", "listBindings")), namingContext, "comp");
    checkListWithContinuationsResults(results);
}
Also used : Binding(javax.naming.Binding) CompositeName(javax.naming.CompositeName) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) Test(org.junit.Test)

Example 29 with Binding

use of javax.naming.Binding in project tomee by apache.

the class Debug method contextToMap.

public static void contextToMap(final Context context, final String baseName, final Map<String, Object> results) throws NamingException {
    final NamingEnumeration<Binding> namingEnumeration = context.listBindings("");
    while (namingEnumeration.hasMoreElements()) {
        final Binding binding = namingEnumeration.nextElement();
        final String name = binding.getName();
        final String fullName = baseName + name;
        final Object object = binding.getObject();
        results.put(fullName, object);
        if (object instanceof Context) {
            contextToMap((Context) object, fullName + "/", results);
        }
    }
}
Also used : Binding(javax.naming.Binding) Context(javax.naming.Context)

Example 30 with Binding

use of javax.naming.Binding in project tomee by apache.

the class Assembler method destroyResourceTree.

private Collection<DestroyingResource> destroyResourceTree(final String base, final NamingEnumeration<Binding> namingEnumeration) {
    final List<DestroyingResource> resources = new LinkedList<>();
    while (namingEnumeration != null && namingEnumeration.hasMoreElements()) {
        final Binding binding = namingEnumeration.nextElement();
        final Object object = binding.getObject();
        if (Context.class.isInstance(object)) {
            try {
                resources.addAll(destroyResourceTree(IvmContext.class.isInstance(object) ? IvmContext.class.cast(object).mynode.getAtomicName() : "", Context.class.cast(object).listBindings("")));
            } catch (final Exception ignored) {
            // no-op
            }
        } else {
            resources.add(new DestroyingResource((base == null || base.isEmpty() ? "" : (base + '/')) + binding.getName(), binding.getClassName(), object));
        }
    }
    resources.sort(new // end by destroying RA after having closed CF pool (for jms for instance)
    Comparator<DestroyingResource>() {

        @Override
        public int compare(final DestroyingResource o1, final DestroyingResource o2) {
            final boolean ra1 = isRa(o1.instance);
            final boolean ra2 = isRa(o2.instance);
            if (ra2 && !ra1) {
                return -1;
            }
            if (ra1 && !ra2) {
                return 1;
            }
            // TODO: handle dependencies there too
            return o1.name.compareTo(o2.name);
        }

        private boolean isRa(final Object instance) {
            return ResourceAdapter.class.isInstance(instance) || ResourceAdapterReference.class.isInstance(instance);
        }
    });
    for (final DestroyingResource resource : resources) {
        try {
            destroyResource(resource.name, resource.clazz, resource.instance);
        } catch (final Throwable th) {
            logger.debug(th.getMessage(), th);
        }
    }
    return resources;
}
Also used : Binding(javax.naming.Binding) WebContext(org.apache.openejb.core.WebContext) SimpleBootstrapContext(org.apache.openejb.core.transaction.SimpleBootstrapContext) Context(javax.naming.Context) ServletContext(javax.servlet.ServletContext) MethodContext(org.apache.openejb.MethodContext) IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) AppContext(org.apache.openejb.AppContext) InitialContext(javax.naming.InitialContext) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanContext(org.apache.openejb.BeanContext) CreationalContext(javax.enterprise.context.spi.CreationalContext) DeploymentContext(org.apache.openejb.DeploymentContext) GeronimoBootstrapContext(org.apache.geronimo.connector.GeronimoBootstrapContext) BootstrapContext(javax.resource.spi.BootstrapContext) IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) LinkedList(java.util.LinkedList) InvalidObjectException(java.io.InvalidObjectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ObjectStreamException(java.io.ObjectStreamException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) UndeployException(org.apache.openejb.UndeployException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) ConstructionException(org.apache.xbean.recipe.ConstructionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(javax.validation.ValidationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) DeploymentException(javax.enterprise.inject.spi.DeploymentException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Aggregations

Binding (javax.naming.Binding)69 NamingException (javax.naming.NamingException)36 Context (javax.naming.Context)31 InitialContext (javax.naming.InitialContext)29 NameNotFoundException (javax.naming.NameNotFoundException)22 Name (javax.naming.Name)19 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)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)11 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