use of javax.naming.InitialContext in project camel by apache.
the class FileEndpointReferenceRouteTest method runTest.
@Test
public void runTest() throws Exception {
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.PROVIDER_URL, GuiceInitialContextFactory.class.getName());
env.put(Injectors.MODULE_CLASS_NAMES, MyModule.class.getName());
InitialContext context = new InitialContext(env);
Injector injector = (Injector) context.lookup(Injector.class.getName());
assertNotNull("Found injector", injector);
Object value = context.lookup("fileFilter");
assertNotNull("Should have found a value for foo!", value);
assertCamelContextRunningThenCloseInjector(injector);
}
use of javax.naming.InitialContext in project tomcat by apache.
the class InstanceKeyDataSource method testCPDS.
protected ConnectionPoolDataSource testCPDS(final String username, final String password) throws javax.naming.NamingException, SQLException {
// The source of physical db connections
ConnectionPoolDataSource cpds = this.dataSource;
if (cpds == null) {
Context ctx = null;
if (jndiEnvironment == null) {
ctx = new InitialContext();
} else {
ctx = new InitialContext(jndiEnvironment);
}
final Object ds = ctx.lookup(dataSourceName);
if (ds instanceof ConnectionPoolDataSource) {
cpds = (ConnectionPoolDataSource) ds;
} else {
throw new SQLException("Illegal configuration: " + "DataSource " + dataSourceName + " (" + ds.getClass().getName() + ")" + " doesn't implement javax.sql.ConnectionPoolDataSource");
}
}
// try to get a connection with the supplied username/password
PooledConnection conn = null;
try {
if (username != null) {
conn = cpds.getPooledConnection(username, password);
} else {
conn = cpds.getPooledConnection();
}
if (conn == null) {
throw new SQLException("Cannot connect using the supplied username/password");
}
} finally {
if (conn != null) {
try {
conn.close();
} catch (final SQLException e) {
// at least we could connect
}
}
}
return cpds;
}
use of javax.naming.InitialContext in project tomcat by apache.
the class EjbFactory method getLinked.
@Override
protected Object getLinked(Reference ref) throws NamingException {
// If ejb-link has been specified, resolving the link using JNDI
RefAddr linkRefAddr = ref.get(EjbRef.LINK);
if (linkRefAddr != null) {
// Retrieving the EJB link
String ejbLink = linkRefAddr.getContent().toString();
Object beanObj = (new InitialContext()).lookup(ejbLink);
return beanObj;
}
return null;
}
use of javax.naming.InitialContext in project tomcat by apache.
the class OpenEjbFactory method getObjectInstance.
// -------------------------------------------------- ObjectFactory Methods
/**
* Create a new EJB instance using OpenEJB.
*
* @param obj The reference object describing the DataSource
*/
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
Object beanObj = null;
if (obj instanceof EjbRef) {
Reference ref = (Reference) obj;
String factory = DEFAULT_OPENEJB_FACTORY;
RefAddr factoryRefAddr = ref.get("openejb.factory");
if (factoryRefAddr != null) {
// Retrieving the OpenEJB factory
factory = factoryRefAddr.getContent().toString();
}
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
RefAddr linkRefAddr = ref.get("openejb.link");
if (linkRefAddr != null) {
String ejbLink = linkRefAddr.getContent().toString();
beanObj = (new InitialContext(env)).lookup(ejbLink);
}
}
return beanObj;
}
use of javax.naming.InitialContext in project jetty.project by eclipse.
the class PlusDescriptorProcessor method bindEnvEntry.
/**
* @param name the jndi name
* @param value the value
* @throws Exception if unable to bind entry
*/
public void bindEnvEntry(String name, Object value) throws Exception {
InitialContext ic = null;
boolean bound = false;
//check to see if we bound a value and an EnvEntry with this name already
//when we processed the server and the webapp's naming environment
//@see EnvConfiguration.bindEnvEntries()
ic = new InitialContext();
try {
NamingEntry ne = (NamingEntry) ic.lookup("java:comp/env/" + NamingEntryUtil.makeNamingEntryName(ic.getNameParser(""), name));
if (ne != null && ne instanceof EnvEntry) {
EnvEntry ee = (EnvEntry) ne;
bound = ee.isOverrideWebXml();
}
} catch (NameNotFoundException e) {
bound = false;
}
if (!bound) {
//either nothing was bound or the value from web.xml should override
Context envCtx = (Context) ic.lookup("java:comp/env");
NamingUtil.bind(envCtx, name, value);
}
}
Aggregations