use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class TestNamingEntryUtil method testGetContextForScope.
@Test
public void testGetContextForScope() throws Exception {
ScopeA scope = new ScopeA();
try {
Context c = NamingEntryUtil.getContextForScope(scope);
fail("context should not exist");
} catch (NameNotFoundException e) {
//expected
}
InitialContext ic = new InitialContext();
Context scopeContext = ic.createSubcontext(NamingEntryUtil.getNameForScope(scope));
assertNotNull(scopeContext);
try {
Context c = NamingEntryUtil.getContextForScope(scope);
assertNotNull(c);
} catch (NameNotFoundException e) {
fail(e.getMessage());
}
}
use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class DataSourceLoginService method initDb.
/* ------------------------------------------------------------ */
/**
* Lookup the datasource for the jndiName and formulate the
* necessary sql query strings based on the configured table
* and column names.
*
* @throws NamingException if unable to init jndi
* @throws SQLException if unable to init database
*/
public void initDb() throws NamingException, SQLException {
if (_datasource != null)
return;
@SuppressWarnings("unused") InitialContext ic = new InitialContext();
assert ic != null;
// try finding the datasource in the Server scope
if (_server != null) {
try {
_datasource = (DataSource) NamingEntryUtil.lookup(_server, _jndiName);
} catch (NameNotFoundException e) {
//next try the jvm scope
}
}
//try finding the datasource in the jvm scope
if (_datasource == null) {
_datasource = (DataSource) NamingEntryUtil.lookup(null, _jndiName);
}
// set up the select statements based on the table and column names configured
_userSql = "select " + _userTableKey + "," + _userTablePasswordField + " from " + _userTableName + " where " + _userTableUserField + " = ?";
_roleSql = "select r." + _roleTableRoleField + " from " + _roleTableName + " r, " + _userRoleTableName + " u where u." + _userRoleTableUserKey + " = ?" + " and r." + _roleTableKey + " = u." + _userRoleTableRoleKey;
prepareTables();
}
use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class EnvConfiguration method deconfigure.
/**
* Remove jndi setup from start
* @throws Exception if unable to deconfigure
*/
@Override
public void deconfigure(WebAppContext context) throws Exception {
//get rid of any bindings for comp/env for webapp
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
ContextFactory.associateClassLoader(context.getClassLoader());
try {
Context ic = new InitialContext();
Context compCtx = (Context) ic.lookup("java:comp");
compCtx.destroySubcontext("env");
//unbind any NamingEntries that were configured in this webapp's name space
@SuppressWarnings("unchecked") List<Bound> bindings = (List<Bound>) context.getAttribute(JETTY_ENV_BINDINGS);
context.setAttribute(JETTY_ENV_BINDINGS, null);
if (bindings != null) {
Collections.reverse(bindings);
for (Bound b : bindings) b._context.destroySubcontext(b._name);
}
} catch (NameNotFoundException e) {
LOG.warn(e);
} finally {
ContextFactory.disassociateClassLoader();
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class NamingEntryUtil method lookupNamingEntries.
/**
* Get all NameEntries of a certain type in the given naming
* environment scope (server-wide names or context-specific names)
*
* @param scope the object scope
* @param clazz the type of the entry
* @return all NameEntries of a certain type in the given naming environment scope (server-wide names or context-specific names)
* @throws NamingException if unable to lookup the naming entries
*/
public static List<Object> lookupNamingEntries(Object scope, Class<?> clazz) throws NamingException {
try {
Context scopeContext = getContextForScope(scope);
Context namingEntriesContext = (Context) scopeContext.lookup(NamingEntry.__contextName);
ArrayList<Object> list = new ArrayList<Object>();
lookupNamingEntries(list, namingEntriesContext, clazz);
return list;
} catch (NameNotFoundException e) {
return Collections.emptyList();
}
}
use of javax.naming.NameNotFoundException in project jetty.project by eclipse.
the class localContextRoot method unbind.
/**
*
*
* @see javax.naming.Context#unbind(javax.naming.Name)
*/
public void unbind(Name name) throws NamingException {
synchronized (__root) {
if (name.size() == 0)
return;
if (__root.isLocked())
throw new NamingException("This context is immutable");
Name cname = __root.toCanonicalName(name);
if (cname == null)
throw new NamingException("Name is null");
if (cname.size() == 0)
throw new NamingException("Name is empty");
//if no subcontexts, just unbind it
if (cname.size() == 1) {
__root.removeBinding(cname);
} else {
//walk down the subcontext hierarchy
if (__log.isDebugEnabled())
__log.debug("Checking for existing binding for name=" + cname + " for first element of name=" + cname.get(0));
String firstComponent = cname.get(0);
Object ctx = null;
if (firstComponent.equals(""))
ctx = this;
else {
Binding binding = __root.getBinding(name.get(0));
if (binding == null)
throw new NameNotFoundException(name.get(0) + " is not bound");
ctx = binding.getObject();
if (ctx instanceof Reference) {
//deference the object
try {
ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), __root, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
__log.warn("", e);
throw new NamingException(e.getMessage());
}
}
}
if (ctx instanceof Context) {
((Context) ctx).unbind(cname.getSuffix(1));
} else
throw new NotContextException("Object bound at " + firstComponent + " is not a Context");
}
}
}
Aggregations