List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:net.chrisrichardson.foodToGo.ejb3.jndi.SpringBeanToJndiExporter.java
public void afterPropertiesSet() throws Exception { InitialContext ctx = new InitialContext(); FactoryBean factoryBean = (FactoryBean) beanFactory.getBean(beanName + "&"); Class type = beanFactory.getType(beanName); ctx.bind(jndiName, new ReferenceToSpringBean(type, beanName)); }
From source file:DatabaseInfo.java
public void doGet(HttpServletRequest inRequest, HttpServletResponse outResponse) throws ServletException, IOException { PrintWriter out = null;//w w w . j a v a 2 s .c om Connection connection = null; Statement statement; ResultSet rs; outResponse.setContentType("text/html"); out = outResponse.getWriter(); try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/AccountsDB"); connection = ds.getConnection(); DatabaseMetaData md = connection.getMetaData(); statement = connection.createStatement(); out.println("<HTML><HEAD><TITLE>Database Server Information</TITLE></HEAD>"); out.println("<BODY>"); out.println("<H1>General Source Information</H1>"); out.println("getURL() - " + md.getURL() + "<BR>"); out.println("getUserName() - " + md.getUserName() + "<BR>"); out.println("getDatabaseProductVersion - " + md.getDatabaseProductVersion() + "<BR>"); out.println("getDriverMajorVersion - " + md.getDriverMajorVersion() + "<BR>"); out.println("getDriverMinorVersion - " + md.getDriverMinorVersion() + "<BR>"); out.println("nullAreSortedHigh - " + md.nullsAreSortedHigh() + "<BR>"); out.println("<H1>Feature Support</H1>"); out.println("supportsAlterTableWithDropColumn - " + md.supportsAlterTableWithDropColumn() + "<BR>"); out.println("supportsBatchUpdates - " + md.supportsBatchUpdates() + "<BR>"); out.println("supportsTableCorrelationNames - " + md.supportsTableCorrelationNames() + "<BR>"); out.println("supportsPositionedDelete - " + md.supportsPositionedDelete() + "<BR>"); out.println("supportsFullOuterJoins - " + md.supportsFullOuterJoins() + "<BR>"); out.println("supportsStoredProcedures - " + md.supportsStoredProcedures() + "<BR>"); out.println("supportsMixedCaseQuotedIdentifiers - " + md.supportsMixedCaseQuotedIdentifiers() + "<BR>"); out.println("supportsANSI92EntryLevelSQL - " + md.supportsANSI92EntryLevelSQL() + "<BR>"); out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar() + "<BR>"); out.println("<H1>Data Source Limits</H1>"); out.println("getMaxRowSize - " + md.getMaxRowSize() + "<BR>"); out.println("getMaxStatementLength - " + md.getMaxStatementLength() + "<BR>"); out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect() + "<BR>"); out.println("getMaxConnections - " + md.getMaxConnections() + "<BR>"); out.println("getMaxCharLiteralLength - " + md.getMaxCharLiteralLength() + "<BR>"); out.println("<H1>SQL Object Available</H1>"); out.println("getTableTypes()<BR><UL>"); rs = md.getTableTypes(); while (rs.next()) { out.println("<LI>" + rs.getString(1)); } out.println("</UL>"); out.println("getTables()<BR><UL>"); rs = md.getTables("accounts", "", "%", new String[0]); while (rs.next()) { out.println("<LI>" + rs.getString("TABLE_NAME")); } out.println("</UL>"); out.println("<H1>Transaction Support</H1>"); out.println("getDefaultTransactionIsolation() - " + md.getDefaultTransactionIsolation() + "<BR>"); out.println( "dataDefinitionIgnoredInTransactions() - " + md.dataDefinitionIgnoredInTransactions() + "<BR>"); out.println("<H1>General Source Information</H1>"); out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect() + "<BR>"); out.println("getMaxColumnsInTable - " + md.getMaxColumnsInTable() + "<BR>"); out.println("getTimeDateFunctions - " + md.getTimeDateFunctions() + "<BR>"); out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar() + "<BR>"); out.println("getTypeInfo()<BR><UL>"); rs = md.getTypeInfo(); while (rs.next()) { out.println("<LI>" + rs.getString(1)); } out.println("</UL>"); out.println("</BODY></HTML>"); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.jabb.util.db.impl.JndiDataSourceProvider.java
public DataSource createDataSource(String source, String config) { DataSource ds = null;/*from w w w. j ava 2s . c o m*/ try { ds = (DataSource) new InitialContext().lookup(config); } catch (NamingException e) { log.warn("Cannot get data source for '" + source + "' from JNDI name '" + config + "'.", e); } catch (Exception e) { log.warn("Error getting data source for '" + source + "' from JNDI name '" + config + "'.", e); } return ds; }
From source file:fr.mosica.javawebtraining.WeatherResource.java
@GET @Consumes("application/json") @Produces("application/json") public Weather getCurrentWeather(@QueryParam("zip") String zip) throws NamingException { Client client = ClientBuilder.newClient(); // http://api.openweathermap.org/data/2.5/weather?zip=49600,fr&APPID=8c05dfed7d5d0d8ba3a2bc70b83b227f // rcupration JNDI -> classique Context ctx = new InitialContext(); String host = (String) ctx.lookup("java:comp/env/openweathermap/weather"); WebTarget target = client.target(host).path("data/2.5/weather").queryParam("zip", zip + ",fr") .queryParam("appid", "8c05dfed7d5d0d8ba3a2bc70b83b227f"); return target.request(MediaType.APPLICATION_JSON_TYPE).get(Weather.class); //[TODEL] return new Weather("Beauprau"); }
From source file:com.smhdemo.common.datasource.generate.factory.jndi.JndiDataSourceFactory.java
public JndiDataSourceFactory() { try {//from ww w . j a va2s. co m ctx = new InitialContext(); } catch (NamingException e) { logger.error("NamingException", e); throw new BaseRuntimeException(e); } }
From source file:com.codeasylum.stress.api.OuroborosImpl.java
public static Ouroboros getRemoteInterface(String rmiHost) throws NamingException { Ouroboros ouroboros;// w w w. ja v a 2 s . co m InitialContext initContext; Context rmiContext; initContext = new InitialContext(); rmiContext = (Context) initContext.lookup("rmi://" + rmiHost + ':' + registryPort.get()); ouroboros = (Ouroboros) PortableRemoteObject.narrow(rmiContext.lookup(Ouroboros.class.getName()), Ouroboros.class); rmiContext.close(); initContext.close(); return ouroboros; }
From source file:com.wso2telco.util.DbUtil.java
private static void initializeDatasources() throws AuthenticatorException { if (mConnectDatasource != null) { return;/*from w w w .j a v a 2 s . com*/ } String dataSourceName = null; try { Context ctx = new InitialContext(); dataSourceName = configurationService.getDataHolder().getMobileConnectConfig().getDataSourceName(); mConnectDatasource = (DataSource) ctx.lookup(dataSourceName); } catch (NamingException e) { handleException("Error while looking up the data source: " + dataSourceName, e); } }
From source file:br.com.icone.martan.security.AppUserDetailsService.java
public AppUserDetailsService() { try {//ww w . j ava 2 s . c o m InitialContext ctx = new InitialContext(); repositorio = (UserEJBRemote) ctx.lookup("br.com.icone.martan.modelo.repositorio.UserEJBRemote"); } catch (NamingException ex) { Logger.getLogger(UserEJBRemote.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.sb.suites.dao.ServiceLocator.java
private ServiceLocator() throws ServiceLocatorException { try {/*from w w w.j av a 2 s . co m*/ ic = new InitialContext(); //ec = (Context) ic.lookup("java:/comp/env"); cache = Collections.synchronizedMap(new HashMap<String, DataSource>()); } catch (NamingException ne) { throw new ServiceLocatorException(ne); } catch (Exception e) { throw new ServiceLocatorException(e); } }
From source file:wqm.web.bean.ConfigBean.java
public ConfigBean() throws NamingException { InitialContext ic = new InitialContext(); config = (WQMConfig) ic.lookup(WQMConfig.class.getCanonicalName()); }