Search in sources :

Example 21 with InitialContext

use of javax.naming.InitialContext 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 22 with InitialContext

use of javax.naming.InitialContext 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 23 with InitialContext

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

the class Transaction method bindToComp.

/**
     * Insist on the java:comp/UserTransaction binding
     * @throws NamingException
     */
private void bindToComp() throws NamingException {
    //ignore the name, it is always bound to java:comp
    InitialContext ic = new InitialContext();
    Context env = (Context) ic.lookup("java:comp");
    __log.debug("Binding java:comp/" + getJndiName() + " to " + _objectNameString);
    NamingUtil.bind(env, getJndiName(), new LinkRef(_objectNameString));
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) LinkRef(javax.naming.LinkRef)

Example 24 with InitialContext

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

the class DatabaseAdaptor method initialize.

public void initialize() throws Exception {
    if (_datasource != null)
        //already set up
        return;
    if (_jndiName != null) {
        InitialContext ic = new InitialContext();
        _datasource = (DataSource) ic.lookup(_jndiName);
    } else if (_driver != null && _connectionUrl != null) {
        DriverManager.registerDriver(_driver);
    } else if (_driverClassName != null && _connectionUrl != null) {
        Class.forName(_driverClassName);
    } else {
        try {
            InitialContext ic = new InitialContext();
            //last ditch effort
            _datasource = (DataSource) ic.lookup("jdbc/sessions");
        } catch (NamingException e) {
            throw new IllegalStateException("No database configured for sessions");
        }
    }
}
Also used : NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 25 with InitialContext

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

the class TestMailSessionReference method testMailSessionReference.

@Test
public void testMailSessionReference() throws Exception {
    InitialContext icontext = new InitialContext();
    MailSessionReference sref = new MailSessionReference();
    sref.setUser("janb");
    sref.setPassword("OBF:1xmk1w261z0f1w1c1xmq");
    Properties props = new Properties();
    props.put("mail.smtp.host", "xxx");
    props.put("mail.debug", "true");
    sref.setProperties(props);
    NamingUtil.bind(icontext, "mail/Session", sref);
    Object x = icontext.lookup("mail/Session");
    assertNotNull(x);
    assertTrue(x instanceof javax.mail.Session);
    javax.mail.Session session = (javax.mail.Session) x;
    Properties sessionProps = session.getProperties();
    assertEquals(props, sessionProps);
    assertTrue(session.getDebug());
    Context foo = icontext.createSubcontext("foo");
    NameParser parser = icontext.getNameParser("");
    Name objectNameInNamespace = parser.parse(icontext.getNameInNamespace());
    objectNameInNamespace.addAll(parser.parse("mail/Session"));
    NamingUtil.bind(foo, "mail/Session", new LinkRef(objectNameInNamespace.toString()));
    Object o = foo.lookup("mail/Session");
    assertNotNull(o);
    Session fooSession = (Session) o;
    assertEquals(props, fooSession.getProperties());
    assertTrue(fooSession.getDebug());
    icontext.destroySubcontext("mail");
    icontext.destroySubcontext("foo");
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) Session(javax.mail.Session) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) Session(javax.mail.Session) Name(javax.naming.Name) LinkRef(javax.naming.LinkRef) Test(org.junit.Test)

Aggregations

InitialContext (javax.naming.InitialContext)1068 Test (org.junit.Test)325 EJBException (javax.ejb.EJBException)228 Properties (java.util.Properties)213 Context (javax.naming.Context)194 RemoteException (java.rmi.RemoteException)173 TestFailureException (org.apache.openejb.test.TestFailureException)172 NamingException (javax.naming.NamingException)168 AssertionFailedError (junit.framework.AssertionFailedError)168 JMSException (javax.jms.JMSException)167 RemoveException (javax.ejb.RemoveException)66 CreateException (javax.ejb.CreateException)57 DataSource (javax.sql.DataSource)55 Hashtable (java.util.Hashtable)54 Assembler (org.apache.openejb.assembler.classic.Assembler)47 EjbJar (org.apache.openejb.jee.EjbJar)41 NameNotFoundException (javax.naming.NameNotFoundException)40 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)38 Connection (java.sql.Connection)37 StatelessBean (org.apache.openejb.jee.StatelessBean)30