Skip to content

Instantly share code, notes, and snippets.

@nastacio
Last active October 10, 2018 19:26
Show Gist options
  • Save nastacio/03ee3dadb136ef3341b4624b22c1f5e5 to your computer and use it in GitHub Desktop.
Save nastacio/03ee3dadb136ef3341b4624b22c1f5e5 to your computer and use it in GitHub Desktop.
JNDI binding
try {
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:/Users/nastacio/tmp/jndi");
InitialContext ctx = new InitialDirContext(env);
for (Entry<String, DB2SimpleDataSource> ds : dss.entrySet()) {
String name = ds.getKey();
CompositeName cn = new CompositeName(name);
Context subCtx = ctx;
for (int i = 0; i < cn.size() - 1; i++) {
String namePrefix = cn.get(i);
Name pp = cn.getPrefix(i);
System.out.println(pp);
try {
subCtx = (Context) subCtx.lookup(namePrefix);
} catch (NameNotFoundException e) {
subCtx = subCtx.createSubcontext(namePrefix);
}
}
ctx.bind(cn, ds.getValue());
}
} catch (NamingException ne) {
ne.printStackTrace();
Assertions.fail("e");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment