Search in sources :

Example 31 with Context

use of javax.naming.Context in project jetty.project by eclipse.

the class Transaction method unbindENC.

/**
     * Unbind this Transaction from a java:comp
     */
public void unbindENC() {
    try {
        InitialContext ic = new InitialContext();
        Context env = (Context) ic.lookup("java:comp");
        __log.debug("Unbinding java:comp/" + getJndiName());
        env.unbind(getJndiName());
    } catch (NamingException e) {
        __log.warn(e);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 32 with Context

use of javax.naming.Context 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 33 with Context

use of javax.naming.Context in project jetty.project by eclipse.

the class NamingEntry method unbindENC.

/**
     * Unbind this NamingEntry from a java:comp/env
     */
public void unbindENC() {
    try {
        InitialContext ic = new InitialContext();
        Context env = (Context) ic.lookup("java:comp/env");
        __log.debug("Unbinding java:comp/env/" + getJndiName());
        env.unbind(getJndiName());
    } catch (NamingException e) {
        __log.warn(e);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 34 with Context

use of javax.naming.Context in project jetty.project by eclipse.

the class NamingEntryUtil method getContextForScope.

public static Context getContextForScope(Object scope) throws NamingException {
    InitialContext ic = new InitialContext();
    NameParser parser = ic.getNameParser("");
    Name name = parser.parse("");
    if (scope != null) {
        name.add(canonicalizeScope(scope));
    }
    return (Context) ic.lookup(name);
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 35 with Context

use of javax.naming.Context 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)

Aggregations

Context (javax.naming.Context)507 InitialContext (javax.naming.InitialContext)250 Test (org.junit.Test)173 NamingException (javax.naming.NamingException)156 DataSource (javax.sql.DataSource)72 Properties (java.util.Properties)67 Connection (java.sql.Connection)62 NameNotFoundException (javax.naming.NameNotFoundException)52 UserTransaction (javax.transaction.UserTransaction)48 SQLException (java.sql.SQLException)46 IOException (java.io.IOException)44 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)44 Statement (java.sql.Statement)42 Name (javax.naming.Name)38 Hashtable (java.util.Hashtable)35 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)27 BeanContext (org.apache.openejb.BeanContext)27 Binding (javax.naming.Binding)25 Reference (javax.naming.Reference)25 NotContextException (javax.naming.NotContextException)23