List of usage examples for javax.naming InitialContext lookup
public Object lookup(Name name) throws NamingException
From source file:org.squale.welcom.struts.plugin.WelcomContext.java
/** * @return le nom du welcomContext (java:com/env) declar sur le serveur *//*from w w w.j a v a 2s .c o m*/ private static String lookupWelcomContextName() { InitialContext ic; String welcomContextName; try { ic = new InitialContext(); welcomContextName = (String) ic.lookup("java:comp/env/welcomContext"); } catch (final NamingException e) { welcomContextName = DEFAULT_WELCOM_CONTEXT_NAME; } return welcomContextName; }
From source file:org.nuxeo.runtime.datasource.DataSourceHelper.java
public static <T> T getDataSource(String partialName, Class<T> clazz) throws NamingException { String jndiName = getDataSourceJNDIName(partialName); InitialContext context = new InitialContext(); Object resolved = context.lookup(jndiName); if (resolved instanceof Reference) { try {/* www .j a va 2s . c om*/ resolved = NamingManager.getObjectInstance(resolved, new CompositeName(jndiName), context, null); } catch (Exception e) { throw new RuntimeException("Cannot get access to " + jndiName, e); } } return clazz.cast(resolved); }
From source file:org.wso2.carbon.appfactory.jenkins.artifact.storage.Utils.java
public static String getEnvironmentVariable(String variableName) { String variableValue = null;/*from w w w. j av a 2 s . c om*/ try { InitialContext iniCtxt = new InitialContext(); Context env = (Context) iniCtxt.lookup("java:comp/env"); variableValue = (String) env.lookup(variableName); } catch (NamingException e) { log.error("Unable to read " + variableName + " from the environment"); } return variableValue; }
From source file:org.wso2.carbon.device.mgt.mobile.android.impl.dao.util.MobileDeviceManagementDAOUtil.java
public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) { try {/*from w w w . j a va 2 s . c o m*/ if (jndiProperties == null || jndiProperties.isEmpty()) { return (DataSource) InitialContext.doLookup(dataSourceName); } final InitialContext context = new InitialContext(jndiProperties); return (DataSource) context.lookup(dataSourceName); } catch (Exception e) { String msg = "Error in looking up data source: " + e.getMessage(); log.error(msg, e); throw new RuntimeException(msg + e.getMessage(), e); } }
From source file:org.nuxeo.ecm.core.storage.sql.ra.PoolingRepositoryFactory.java
protected static ConnectionManager lookupConnectionManager(RepositoryDescriptor descriptor) throws NamingException { String repositoryName = descriptor.getName(); // Check in container ConnectionManager cm = NuxeoContainer.getConnectionManager(repositoryName); if (cm != null) { return cm; }/* w w w .j a v a2 s .c o m*/ // Check in JNDI InitialContext context = new InitialContext(); for (String name : CM_NAMES_PREFIXES) { try { cm = (ConnectionManager) context.lookup(name + repositoryName); if (cm != null) { return cm; } } catch (NamingException e) { // try next one } } // Creation from descriptor pool config cm = NuxeoContainer.installConnectionManager(repositoryName, descriptor.getPool()); if (cm != null) { return cm; } throw new NamingException("NuxeoConnectionManager not found in JNDI"); }
From source file:arena.utils.ServletUtils.java
public static String getHostSetting(String jndiParam, String jvmArg) { String hostSetting = null;/*from w w w .j a v a 2 s . c om*/ // Get host settings via JNDI if available if (jndiParam != null) try { InitialContext initial = new InitialContext(); hostSetting = (String) initial.lookup(jndiParam); } catch (Throwable err) { /* Ignore - no jndi available, or no param set */ } if (hostSetting == null) { hostSetting = System.getProperty(jvmArg); } return hostSetting; }
From source file:org.culturegraph.mf.sql.util.JdbcUtil.java
public static Connection getConnection(final String datasourceName) { try {//from w ww .j a v a2s . co m final InitialContext ctx = new InitialContext(); final DataSource datasource = (DataSource) ctx.lookup(datasourceName); return datasource.getConnection(); } catch (final NamingException ne) { throw new MetafactureException(ne); } catch (final SQLException se) { throw new MetafactureException(se); } }
From source file:de.tud.inf.db.sparqlytics.bench.LDBCBenchmark.java
@AfterClass public static void unbindRepository() throws NamingException { InitialContext ctx = new InitialContext(); Repository repository = (Repository) ctx.lookup("ldbc"); Slf4jReporter.forRegistry(repository.getStatistics()).withLoggingLevel(Slf4jReporter.LoggingLevel.INFO) .prefixedWith("after:").build().report(); ctx.unbind("ldbc"); }
From source file:org.eclipse.ecr.core.storage.sql.ra.PoolingRepositoryFactory.java
protected static ConnectionManager lookupConnectionManager() throws NamingException { InitialContext context = new InitialContext(); int i = 0;//from w w w .j a va 2 s . c o m for (String name : CM_NAMES) { try { ConnectionManager connectionManager = (ConnectionManager) context.lookup(name); if (connectionManager != null) { if (i != 0) { // put successful name first for next time CM_NAMES[i] = CM_NAMES[0]; CM_NAMES[0] = name; } return connectionManager; } } catch (NamingException e) { // try next one } i++; } throw new NamingException("NuxeoConnectionManager not found in JNDI"); }
From source file:org.zanata.util.CleanDocumentStorageRule.java
public static String getDocumentStoragePath() { if (storagePath == null) { final Properties env = new Properties(); // env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName()); long portOffset = Integer.parseInt(PropertiesHolder.getProperty("cargo.port.offset", "0")); String rmiPort = System.getenv("JBOSS_REMOTING_PORT"); int rmiPortNum = rmiPort != null ? parseInt(rmiPort) : 4547; long realRmiPort = portOffset + rmiPortNum; String remoteUrl = "remote://localhost:" + realRmiPort; env.put(Context.PROVIDER_URL, remoteUrl); InitialContext remoteContext = null; try {/*from w w w. jav a 2s .c o m*/ remoteContext = new InitialContext(env); storagePath = (String) remoteContext.lookup("zanata/files/document-storage-directory"); } catch (NamingException e) { // wildfly uses 'http-remoting:' not 'remote:' String httpPort = System.getenv("JBOSS_HTTP_PORT"); int httpPortNum = httpPort != null ? parseInt(httpPort) : 8180; long realHttpPort = httpPortNum + portOffset; String httpRemotingUrl = "http-remoting://localhost:" + realHttpPort; log.warn("Unable to access {}: {}; trying {}", remoteUrl, e.toString(), httpRemotingUrl); try { env.put(Context.PROVIDER_URL, httpRemotingUrl); remoteContext = new InitialContext(env); storagePath = (String) remoteContext.lookup("zanata/files/document-storage-directory"); } catch (NamingException e1) { // fall back option: log.warn("Unable to access {}: {}", httpRemotingUrl, e.toString()); URL testClassRoot = Thread.currentThread().getContextClassLoader() .getResource("setup.properties"); File targetDir = new File(testClassRoot.getPath()).getParentFile(); storagePath = new File(targetDir, "zanata-documents").getAbsolutePath(); } } } return storagePath; }