use of org.eclipse.jetty.jndi.NamingContext in project jetty.project by eclipse.
the class EnvConfiguration method configure.
@Override
public void configure(WebAppContext context) throws Exception {
if (LOG.isDebugEnabled())
LOG.debug("Created java:comp/env for webapp " + context.getContextPath());
//look in WEB-INF/jetty-env.xml
if (jettyEnvXmlUrl == null) {
//look for a file called WEB-INF/jetty-env.xml
//and process it if it exists
org.eclipse.jetty.util.resource.Resource web_inf = context.getWebInf();
if (web_inf != null && web_inf.isDirectory()) {
org.eclipse.jetty.util.resource.Resource jettyEnv = web_inf.addPath("jetty-env.xml");
if (jettyEnv.exists()) {
jettyEnvXmlUrl = jettyEnv.getURL();
}
}
}
if (jettyEnvXmlUrl != null) {
synchronized (localContextRoot.getRoot()) {
// create list and listener to remember the bindings we make.
final List<Bound> bindings = new ArrayList<Bound>();
NamingContext.Listener listener = new NamingContext.Listener() {
public void unbind(NamingContext ctx, Binding binding) {
}
public Binding bind(NamingContext ctx, Binding binding) {
bindings.add(new Bound(ctx, binding.getName()));
return binding;
}
};
try {
localContextRoot.getRoot().addListener(listener);
XmlConfiguration configuration = new XmlConfiguration(jettyEnvXmlUrl);
WebAppClassLoader.runWithServerClassAccess(() -> {
configuration.configure(context);
return null;
});
} finally {
localContextRoot.getRoot().removeListener(listener);
context.setAttribute(JETTY_ENV_BINDINGS, bindings);
}
}
}
//add java:comp/env entries for any EnvEntries that have been defined so far
bindEnvEntries(context);
}
use of org.eclipse.jetty.jndi.NamingContext in project jetty.project by eclipse.
the class EnvConfiguration method destroy.
/**
* Remove all jndi setup
* @throws Exception if unable to destroy
*/
@Override
public void destroy(WebAppContext context) throws Exception {
try {
//unbind any NamingEntries that were configured in this webapp's name space
NamingContext scopeContext = (NamingContext) NamingEntryUtil.getContextForScope(context);
scopeContext.getParent().destroySubcontext(scopeContext.getName());
} catch (NameNotFoundException e) {
LOG.ignore(e);
LOG.debug("No jndi entries scoped to webapp {}", context);
} catch (NamingException e) {
LOG.debug("Error unbinding jndi entries scoped to webapp " + context, e);
}
}
Aggregations