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);
}
}
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);
}
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));
}
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");
}
}
}
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");
}
Aggregations