Search in sources :

Example 56 with CompositeName

use of javax.naming.CompositeName in project rabbitmq-jms-client by rabbitmq.

the class RMQConnectionFactoryTest method testConnectionFactoryReferenceUpdated.

@Test
public void testConnectionFactoryReferenceUpdated() throws Exception {
    RMQConnectionFactory connFactory = new RMQConnectionFactory();
    connFactory.setQueueBrowserReadMax(52);
    Reference ref = connFactory.getReference();
    addStringRefProperty(ref, "host", "sillyHost");
    addStringRefProperty(ref, "password", "my-password");
    addStringRefProperty(ref, "port", "42");
    // duplicates don't overwrite
    addStringRefProperty(ref, "queueBrowserReadMax", "52");
    addStringRefProperty(ref, "onMessageTimeoutMs", "62");
    addStringRefProperty(ref, "ssl", "true");
    addStringRefProperty(ref, "terminationTimeout", "1234567890123456789");
    addStringRefProperty(ref, "username", "fred");
    addStringRefProperty(ref, "virtualHost", "bill");
    RMQConnectionFactory newFactory = (RMQConnectionFactory) new RMQObjectFactory().createConnectionFactory(ref, new Hashtable<Object, Object>(), new CompositeName("newOne"));
    assertEquals("sillyHost", newFactory.getHost(), "Not the correct host");
    assertEquals("my-password", newFactory.getPassword(), "Not the correct password");
    assertEquals(42, newFactory.getPort(), "Not the correct port");
    assertEquals(52, newFactory.getQueueBrowserReadMax(), "Not the correct queueBrowserReadMax");
    assertEquals(62, newFactory.getOnMessageTimeoutMs(), "Not the correct onMessageTimeoutMs");
    assertEquals(true, newFactory.isSsl(), "Not the correct ssl");
    assertEquals(1234567890123456789L, newFactory.getTerminationTimeout(), "Not the correct terminationTimeout");
    assertEquals("fred", newFactory.getUsername(), "Not the correct username");
    assertEquals("bill", newFactory.getVirtualHost(), "Not the correct virtualHost");
    assertEquals("amqps://fred:my-password@sillyHost:42/bill", newFactory.getUri());
}
Also used : Reference(javax.naming.Reference) Hashtable(java.util.Hashtable) CompositeName(javax.naming.CompositeName) Test(org.junit.jupiter.api.Test)

Example 57 with CompositeName

use of javax.naming.CompositeName in project rabbitmq-jms-client by rabbitmq.

the class RMQObjectFactoryTest method getObjectInstanceShouldThrowNamingExceptionWhenMissingRequiredPropertyViaEnvironment.

@Test
public void getObjectInstanceShouldThrowNamingExceptionWhenMissingRequiredPropertyViaEnvironment() throws Exception {
    Hashtable<?, ?> environment = new Hashtable<Object, Object>() {

        {
            put("className", "javax.jms.Queue");
            put("destinationName", "TEST_QUEUE");
            put("amqp", "true");
        }
    };
    try {
        rmqObjectFactory.getObjectInstance("anything but a javax.naming.Reference", new CompositeName("java:global/jms/TestConnectionFactory"), null, environment);
        fail("Should have thrown a NamingException");
    } catch (NamingException ne) {
        assertEquals("Property [amqpExchangeName] may not be null.", ne.getMessage());
    }
}
Also used : Hashtable(java.util.Hashtable) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) Test(org.junit.jupiter.api.Test)

Example 58 with CompositeName

use of javax.naming.CompositeName in project rabbitmq-jms-client by rabbitmq.

the class RMQObjectFactoryTest method getObjectInstanceShouldThrowNamingExceptionWhenObjectArgIsNotAReferenceAndEnvironmentClassNameIsMissing.

@Test
public void getObjectInstanceShouldThrowNamingExceptionWhenObjectArgIsNotAReferenceAndEnvironmentClassNameIsMissing() throws Exception {
    try {
        Hashtable<Object, Object> environment = new Hashtable<Object, Object>() {

            {
                put("anything but className", "some value");
            }
        };
        rmqObjectFactory.getObjectInstance("anything but a javax.naming.Reference", new CompositeName("java:global/jms/TestConnectionFactory"), null, environment);
        fail("Should have thrown a NamingException");
    } catch (NamingException ne) {
        assertEquals("Unable to instantiate object: type has not been specified", ne.getMessage());
    }
}
Also used : Hashtable(java.util.Hashtable) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) Test(org.junit.jupiter.api.Test)

Example 59 with CompositeName

use of javax.naming.CompositeName in project mule by mulesoft.

the class DefaultSpringJndiContext method composeName.

public String composeName(String name, String prefix) throws NamingException {
    CompositeName result = new CompositeName(prefix);
    result.addAll(new CompositeName(name));
    return result.toString();
}
Also used : CompositeName(javax.naming.CompositeName)

Example 60 with CompositeName

use of javax.naming.CompositeName in project mule by mulesoft.

the class DefaultSpringJndiContext method lookup.

public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object obj = bindings.get(first);
                if (obj == null) {
                    throw new NameNotFoundException(name);
                } else if (obj instanceof Context && path.size() > 1) {
                    Context subContext = (Context) obj;
                    obj = subContext.lookup(path.getSuffix(1));
                }
                return obj;
            }
        }
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof DefaultSpringJndiContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new DefaultSpringJndiContext((DefaultSpringJndiContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) LinkRef(javax.naming.LinkRef)

Aggregations

CompositeName (javax.naming.CompositeName)124 Test (org.junit.Test)69 Name (javax.naming.Name)43 NameNotFoundException (javax.naming.NameNotFoundException)27 NamingException (javax.naming.NamingException)25 Reference (javax.naming.Reference)19 Context (javax.naming.Context)18 InvalidNameException (javax.naming.InvalidNameException)13 NotContextException (javax.naming.NotContextException)12 ServiceName (org.jboss.msc.service.ServiceName)11 Test (org.junit.jupiter.api.Test)10 JndiPermission (org.wildfly.naming.java.permission.JndiPermission)10 Hashtable (java.util.Hashtable)9 Binding (javax.naming.Binding)8 LinkRef (javax.naming.LinkRef)8 OperationNotSupportedException (javax.naming.OperationNotSupportedException)8 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IEntityGroup (org.apereo.portal.groups.IEntityGroup)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 StringRefAddr (javax.naming.StringRefAddr)5