Search in sources :

Example 51 with Binding

use of javax.naming.Binding in project activemq-artemis by apache.

the class JNDITestSupport method tearDown.

/**
 * Stops all existing ActiveMQConnectionFactory in Context.
 *
 * @throws javax.naming.NamingException
 */
@Override
protected void tearDown() throws NamingException, JMSException {
    NamingEnumeration<Binding> iter = context.listBindings("");
    while (iter.hasMore()) {
        Binding binding = iter.next();
        Object connFactory = binding.getObject();
        if (connFactory instanceof ActiveMQConnectionFactory) {
        // ((ActiveMQConnectionFactory) connFactory).stop();
        }
    }
}
Also used : Binding(javax.naming.Binding) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory)

Example 52 with Binding

use of javax.naming.Binding in project activemq-artemis by apache.

the class InVMContext method listBindings.

@Override
public NamingEnumeration<Binding> listBindings(String contextName) throws NamingException {
    contextName = trimSlashes(contextName);
    if (!"".equals(contextName) && !".".equals(contextName)) {
        try {
            return ((InVMContext) lookup(contextName)).listBindings("");
        } catch (Throwable t) {
            throw new NamingException(t.getMessage());
        }
    }
    List<Binding> l = new ArrayList<>();
    for (Object element : map.keySet()) {
        String name = (String) element;
        Object object = map.get(name);
        l.add(new Binding(name, object));
    }
    return new NamingEnumerationImpl<>(l.iterator());
}
Also used : Binding(javax.naming.Binding) ArrayList(java.util.ArrayList) NamingException(javax.naming.NamingException)

Example 53 with Binding

use of javax.naming.Binding in project activemq-artemis by apache.

the class InVMNamingContext method listBindings.

@Override
public NamingEnumeration<Binding> listBindings(String contextName) throws NamingException {
    contextName = trimSlashes(contextName);
    if (!"".equals(contextName) && !".".equals(contextName)) {
        try {
            return ((InVMNamingContext) lookup(contextName)).listBindings("");
        } catch (Throwable t) {
            throw new NamingException(t.getMessage());
        }
    }
    List<Binding> l = new ArrayList<>();
    for (Object element : map.keySet()) {
        String name = (String) element;
        Object object = map.get(name);
        l.add(new Binding(name, object));
    }
    return new NamingEnumerationImpl<>(l.iterator());
}
Also used : Binding(javax.naming.Binding) ArrayList(java.util.ArrayList) NamingException(javax.naming.NamingException)

Example 54 with Binding

use of javax.naming.Binding in project activemq-artemis by apache.

the class InVMContext method listBindings.

@Override
public NamingEnumeration<Binding> listBindings(String contextName) throws NamingException {
    contextName = trimSlashes(contextName);
    if (!"".equals(contextName) && !".".equals(contextName)) {
        try {
            return ((InVMContext) lookup(contextName)).listBindings("");
        } catch (Throwable t) {
            throw new NamingException(t.getMessage());
        }
    }
    List<Binding> l = new ArrayList<>();
    for (String name : map.keySet()) {
        Object object = map.get(name);
        l.add(new Binding(name, object));
    }
    return new NamingEnumerationImpl(l.iterator());
}
Also used : Binding(javax.naming.Binding) ArrayList(java.util.ArrayList) NamingException(javax.naming.NamingException)

Example 55 with Binding

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

the class RemoteNamingEjbTestCase method testDeploymentBinding.

@Test
public void testDeploymentBinding() throws Exception {
    final InitialContext ctx = getRemoteContext();
    BinderRemote binder = null;
    try {
        try {
            ctx.lookup("some/entry");
            fail("expected exception");
        } catch (NameNotFoundException e) {
        // expected
        }
        // test binding
        binder = (BinderRemote) ctx.lookup(ARCHIVE_NAME + "/" + Singleton.class.getSimpleName() + "!" + BinderRemote.class.getName());
        assertNotNull(binder);
        binder.bind();
        assertEquals("Test", ctx.lookup("some/entry"));
        NamingEnumeration<Binding> bindings = ctx.listBindings("some");
        assertTrue(bindings.hasMore());
        assertEquals("Test", bindings.next().getObject());
        assertFalse(bindings.hasMore());
        // test rebinding
        binder.rebind();
        assertEquals("Test2", ctx.lookup("some/entry"));
        bindings = ctx.listBindings("some");
        assertTrue(bindings.hasMore());
        assertEquals("Test2", bindings.next().getObject());
        assertFalse(bindings.hasMore());
        // test unbinding
        binder.unbind();
        try {
            ctx.lookup("some/entry");
            fail("expected exception");
        } catch (NameNotFoundException e) {
        // expected
        }
        // test rebinding when it doesn't already exist
        binder.rebind();
        assertEquals("Test2", ctx.lookup("some/entry"));
        bindings = ctx.listBindings("some");
        assertTrue(bindings.hasMore());
        assertEquals("Test2", bindings.next().getObject());
        assertFalse(bindings.hasMore());
    } finally {
        // clean up in case any JNDI bindings were left around
        try {
            if (binder != null)
                binder.unbind();
        } catch (Exception e) {
        // expected
        }
        ctx.close();
    }
}
Also used : Binding(javax.naming.Binding) NameNotFoundException(javax.naming.NameNotFoundException) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) Test(org.junit.Test)

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