Created
June 17, 2013 10:54
-
-
Save dagvadorj/5796120 to your computer and use it in GitHub Desktop.
Update JNDI
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
public String update() { | |
Context ctx = null; | |
try { | |
ctx = new InitialContext(); | |
Object previousValue = ctx.lookup(pair.getName()); | |
if (previousValue != null) | |
ctx.rebind(pair.getName(), pair.getValue()); | |
} catch (NamingException e) { | |
String[] subs = pair.getName().split("/"); | |
Context c = ctx; | |
for (int i = 0; i < subs.length - 1; i++) { | |
Object o; | |
try { | |
o = c.lookup(subs[i]); | |
if (o instanceof Context) | |
c = (Context)o; | |
} catch (NamingException e2) { | |
try { | |
c = c.createSubcontext(subs[i]); | |
} catch (NamingException e3) { | |
e3.printStackTrace(); | |
FacesUtils.addErrorMessage("ManagementBundle", "management.settings.login.error", null); | |
return null; | |
} | |
} | |
} | |
try { | |
ctx.bind(pair.getName(), pair.getValue()); | |
} catch (CannotProceedException e2) { | |
e2.printStackTrace(); | |
FacesUtils.addErrorMessage("ManagementBundle", "management.settings.login.error", null); | |
return null; | |
} catch (NamingException e2) { | |
e2.printStackTrace(); | |
FacesUtils.addErrorMessage("ManagementBundle", "management.settings.login.error", null); | |
return null; | |
} | |
} | |
try { | |
System.out.println("> " + ctx.lookup(pair.getName())); | |
pair = new Pair(); | |
} catch (NamingException e) { | |
FacesUtils.addErrorMessage("ManagementBundle", "management.settings.login.error", null); | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment