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());
}
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());
}
}
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());
}
}
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();
}
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;
}
Aggregations