Skip to content

Instantly share code, notes, and snippets.

@luszczynski
Last active August 29, 2015 14:09
Show Gist options
  • Save luszczynski/575657b9ffe0f82c232f to your computer and use it in GitHub Desktop.
Save luszczynski/575657b9ffe0f82c232f to your computer and use it in GitHub Desktop.
EJB JNDI View with parameters
private Object getEJB(final Class<?> ejbClass) throws Exception {
try {
InitialContext ctx = new InitialContext();
NamingEnumeration<NameClassPair> globals;
NamingEnumeration<NameClassPair> modules;
NamingEnumeration<NameClassPair> apps;
NameClassPair global;
NameClassPair module;
NameClassPair app;
String beanInterface;
globals = ctx.list("java:global");
while (globals.hasMore()) {
global = globals.next();
modules = ctx.list("java:global/" + global.getName());
while(modules.hasMore()) {
module = modules.next();
apps = ctx.list("java:global/" + global.getName() + "/" + module.getName());
while(apps.hasMore()) {
app = apps.next();
beanInterface = app.getClassName();
if (beanInterface != null && beanInterface.equals(ejbClass.getCanonicalName())) {
return ctx.lookup("java:global/" + global.getName() + "/" + module.getName() + "/" + app.getName() + "!" + app.getClassName());
}
}
}
}
} catch (Exception e) {
throw new Exception(e);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment