use of javax.naming.Context in project hibernate-orm by hibernate.
the class JndiRegionFactoryTest method afterStandardServiceRegistryBuilt.
@Override
protected void afterStandardServiceRegistryBuilt(StandardServiceRegistry ssr) {
if (bindToJndi) {
try {
// Create an in-memory jndi
namingServer = new SingletonNamingServer();
namingMain = new Main();
namingMain.setInstallGlobalService(true);
namingMain.setPort(-1);
namingMain.start();
props = new Properties();
props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
final String cfgFileName = (String) ssr.getService(ConfigurationService.class).getSettings().get(InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP);
manager = new DefaultCacheManager(cfgFileName == null ? InfinispanRegionFactory.DEF_INFINISPAN_CONFIG_RESOURCE : cfgFileName, false);
Context ctx = new InitialContext(props);
bind(JNDI_NAME, manager, EmbeddedCacheManager.class, ctx);
} catch (Exception e) {
throw new RuntimeException("Failure to set up JNDI", e);
}
}
}
use of javax.naming.Context in project jersey by jersey.
the class ThreadLocalNamedInvoker method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// if no instance yet exists for the current thread then look one up and stash it
if (this.get() == null) {
Context ctx = new InitialContext();
T t = (T) ctx.lookup(name);
this.set(t);
}
return super.invoke(proxy, method, args);
}
use of javax.naming.Context in project javaee7-samples by javaee-samples.
the class UserTransactionTest method should_work_with_jndi.
@Test
public void should_work_with_jndi() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException, NamingException {
Context context = new InitialContext();
UserTransaction ut = (UserTransaction) context.lookup("java:comp/UserTransaction");
ut.begin();
ut.commit();
}
use of javax.naming.Context in project javaee7-samples by javaee-samples.
the class EmployeeBean method postConstruct.
@PostConstruct
public void postConstruct() {
try {
Context context = new InitialContext();
em = (EntityManager) context.lookup("java:comp/env/persistence/myJNDI");
} catch (NamingException ex) {
Logger.getLogger(EmployeeBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of javax.naming.Context in project hudson-2.x by hudson.
the class AbstractModelObject method getConfiguredHudsonProperty.
/**
* Checks jndi,environment, hudson environment and system properties for specified key.
* Property is checked in direct order:
* <ol>
* <li>JNDI ({@link InitialContext#lookup(String)})</li>
* <li>Hudson environment ({@link EnvVars#masterEnvVars})</li>
* <li>System properties ({@link System#getProperty(String)})</li>
* </ol>
* @param key - the name of the configured property.
* @return the string value of the configured property, or null if there is no property with that key.
*/
protected String getConfiguredHudsonProperty(String key) {
if (StringUtils.isNotBlank(key)) {
String resultValue;
try {
InitialContext iniCtxt = new InitialContext();
Context env = (Context) iniCtxt.lookup("java:comp/env");
resultValue = StringUtils.trimToNull((String) env.lookup(key));
if (null != resultValue) {
return resultValue;
}
// look at one more place. See http://issues.hudson-ci.org/browse/HUDSON-1314
resultValue = StringUtils.trimToNull((String) iniCtxt.lookup(key));
if (null != resultValue) {
return resultValue;
}
} catch (NamingException e) {
// ignore
}
// look at the env var next
resultValue = StringUtils.trimToNull(EnvVars.masterEnvVars.get(key));
if (null != resultValue) {
return resultValue;
}
// finally check the system property
resultValue = StringUtils.trimToNull(System.getProperty(key));
if (null != resultValue) {
return resultValue;
}
}
return null;
}
Aggregations