Last active
October 10, 2018 19:26
-
-
Save nastacio/03ee3dadb136ef3341b4624b22c1f5e5 to your computer and use it in GitHub Desktop.
JNDI binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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