Search in sources :

Example 6 with NameNotFoundException

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());
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 7 with NameNotFoundException

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();
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) InitialContext(javax.naming.InitialContext)

Example 8 with NameNotFoundException

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);
    }
}
Also used : InitialContext(javax.naming.InitialContext) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) NamingContext(org.eclipse.jetty.jndi.NamingContext) Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) WebAppClassLoader(org.eclipse.jetty.webapp.WebAppClassLoader) ArrayList(java.util.ArrayList) List(java.util.List) InitialContext(javax.naming.InitialContext)

Example 9 with NameNotFoundException

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();
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) ArrayList(java.util.ArrayList)

Example 10 with NameNotFoundException

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");
        }
    }
}
Also used : Binding(javax.naming.Binding) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NamingContext(org.eclipse.jetty.jndi.NamingContext) NotContextException(javax.naming.NotContextException) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NotContextException(javax.naming.NotContextException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) CompoundName(javax.naming.CompoundName) Name(javax.naming.Name)

Aggregations

NameNotFoundException (javax.naming.NameNotFoundException)112 InitialContext (javax.naming.InitialContext)56 Context (javax.naming.Context)51 NamingException (javax.naming.NamingException)51 Test (org.junit.Test)36 Name (javax.naming.Name)33 Reference (javax.naming.Reference)27 NotContextException (javax.naming.NotContextException)24 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)23 CompositeName (javax.naming.CompositeName)22 Binding (javax.naming.Binding)21 OperationNotSupportedException (javax.naming.OperationNotSupportedException)21 CompoundName (javax.naming.CompoundName)16 NamingContext (org.eclipse.jetty.jndi.NamingContext)12 IOException (java.io.IOException)11 InvalidNameException (javax.naming.InvalidNameException)7 ContainerSystem (org.apache.openejb.spi.ContainerSystem)7 ArrayList (java.util.ArrayList)6 LinkRef (javax.naming.LinkRef)6 Properties (java.util.Properties)5