use of javax.naming.NameClassPair in project wildfly by wildfly.
the class NamingContextTestCase method checkListResults.
private void checkListResults(NamingEnumeration<? extends NameClassPair> results) throws NamingException {
final Set<String> expected = new HashSet<String>(Arrays.asList("test", "testTwo", "testThree", "testContext"));
while (results.hasMore()) {
NameClassPair result = results.next();
final String resultName = result.getName();
if ("test".equals(resultName) || "testTwo".equals(resultName) || "testThree".equals(resultName)) {
assertEquals(Object.class.getName(), result.getClassName());
} 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());
}
use of javax.naming.NameClassPair in project wildfly by wildfly.
the class NamingContextTestCase method testListWithContinuation.
@Test
@SuppressWarnings("unchecked")
public void testListWithContinuation() throws Exception {
bindListWithContinuations();
NamingEnumeration<NameClassPair> results = namingContext.list(new CompositeName("comp"));
checkListWithContinuationsResults(results);
// the same with security permissions
results = (NamingEnumeration<NameClassPair>) testActionPermission(JndiPermission.ACTION_LIST, Arrays.asList(new JndiPermission("test", "list")), namingContext, "comp");
checkListWithContinuationsResults(results);
}
use of javax.naming.NameClassPair in project wildfly by wildfly.
the class ServiceBasedNamingStore method list.
public List<NameClassPair> list(final Name name) throws NamingException {
final ServiceName lookupName = buildServiceName(name);
final ServiceName floor = boundServices.floor(lookupName);
boolean isContextBinding = false;
if (floor != null && floor.isParentOf(lookupName)) {
// Parent might be a reference or a link
Object obj = lookup(name.toString(), floor, true);
if (obj instanceof NamingContext) {
isContextBinding = true;
} else if (obj != null) {
throw new RequireResolveException(convert(floor));
}
}
final List<ServiceName> children = listChildren(lookupName, isContextBinding);
final String[] lookupParts = lookupName.toArray();
final Set<String> childContexts = new HashSet<String>();
final List<NameClassPair> results = new ArrayList<NameClassPair>();
for (ServiceName child : children) {
final String[] childParts = child.toArray();
if (childParts.length > lookupParts.length + 1) {
childContexts.add(childParts[lookupParts.length]);
} else {
final Object binding = lookup(name.toString(), child, false);
if (binding != null) {
final String bindingType;
if (binding instanceof ContextListManagedReferenceFactory) {
bindingType = ContextListManagedReferenceFactory.class.cast(binding).getInstanceClassName();
} else {
if (binding instanceof ManagedReferenceFactory) {
bindingType = ContextListManagedReferenceFactory.DEFAULT_INSTANCE_CLASS_NAME;
} else {
bindingType = binding.getClass().getName();
}
}
results.add(new NameClassPair(childParts[childParts.length - 1], bindingType));
}
}
}
for (String contextName : childContexts) {
results.add(new NameClassPair(contextName, Context.class.getName()));
}
return results;
}
use of javax.naming.NameClassPair in project wildfly by wildfly.
the class RemoteNamingEjbTestCase method testIt.
@Test
public void testIt() throws Exception {
final InitialContext ctx = getRemoteContext();
final ClassLoader current = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(Remote.class.getClassLoader());
Remote remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + Bean.class.getSimpleName() + "!" + Remote.class.getName());
assertNotNull(remote);
assertEquals("Echo: test", remote.echo("test"));
remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + Singleton.class.getSimpleName() + "!" + BinderRemote.class.getName());
assertNotNull(remote);
assertEquals("Echo: test", remote.echo("test"));
remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + StatefulBean.class.getSimpleName() + "!" + Remote.class.getName());
assertNotNull(remote);
assertEquals("Echo: test", remote.echo("test"));
final Set<String> expected = new HashSet<String>();
expected.add(Bean.class.getSimpleName() + "!" + Remote.class.getName());
expected.add(Singleton.class.getSimpleName() + "!" + BinderRemote.class.getName());
expected.add(StatefulBean.class.getSimpleName() + "!" + Remote.class.getName());
NamingEnumeration<NameClassPair> e = ctx.list("test");
while (e.hasMore()) {
NameClassPair binding = e.next();
if (!expected.remove(binding.getName())) {
Assert.fail("unknown binding " + binding.getName());
}
}
if (!expected.isEmpty()) {
Assert.fail("bindings not found " + expected);
}
} finally {
ctx.close();
Thread.currentThread().setContextClassLoader(current);
}
}
use of javax.naming.NameClassPair in project tomee by apache.
the class JndiServlet method addBindings.
private void addBindings(String path, Map<String, Object> bindings, Context context) {
try {
for (NameClassPair pair : Collections.list(context.list(""))) {
String name = pair.getName();
String className = pair.getClassName();
if ("org.apache.naming.resources.FileDirContext$FileResource".equals(className)) {
bindings.put(path + name, "<file>");
} else {
try {
Object value = context.lookup(name);
if (value instanceof Context) {
Context nextedContext = (Context) value;
bindings.put(path + name, "");
addBindings(path + name + "/", bindings, nextedContext);
} else {
bindings.put(path + name, value);
}
} catch (NamingException e) {
// lookup failed
bindings.put(path + name, "ERROR: " + e.getMessage());
}
}
}
} catch (NamingException e) {
bindings.put(path, "ERROR: list bindings threw an exception: " + e.getMessage());
}
}
Aggregations