List of usage examples for javax.naming Context lookup
public Object lookup(String name) throws NamingException;
From source file:org.geoserver.wfs.notification.StaticJMSEventHelper.java
protected JMSInfo createJMSInfo(Properties p) throws NamingException, JMSException { JMSInfo info = null;//w w w . j ava2 s. c o m Context ctx = new InitialContext(p); ConnectionFactory factory = (ConnectionFactory) ctx.lookup(coalesce( (String) p.getProperty("connectionFactoryName"), connectionFactoryName, "connectionFactory")); Connection connection = factory.createConnection(); // Find a list of destination names. // Try a provided list first List<String> destinationNames = this.destinationNames; if (destinationNames == null) { // If none were provided, scan the properties for likely suspects destinationNames = new ArrayList<String>(); for (String e : (((Map<String, String>) (Object) p).keySet())) { if (e.startsWith(DESTINATION_PREFIX)) { destinationNames.add(e.substring(DESTINATION_PREFIX.length())); } } } if (destinationNames.isEmpty()) { throw new IllegalArgumentException("No destination names were provided or found."); } List<Destination> destinations = new ArrayList<Destination>(destinationNames.size()); for (String name : destinationNames) { destinations.add((Destination) ctx.lookup(name)); } info = new JMSInfo(connection, destinations); return info; }
From source file:org.jboss.as.test.smoke.embedded.deployment.rar.AS7_1452.AS7_1452TestCase.java
/** * Test config properties//from w w w. j ava2 s. c om * * @throws Throwable Thrown if case of an error */ @Test public void testConfigProperties() throws Throwable { Context ctx = new InitialContext(); ConfigPropertyConnectionFactory connectionFactory = (ConfigPropertyConnectionFactory) ctx .lookup(CF_JNDI_NAME); assertNotNull(connectionFactory); ConfigPropertyAdminObjectInterface adminObject = (ConfigPropertyAdminObjectInterface) ctx .lookup(AO_JNDI_NAME); assertNotNull(adminObject); ConfigPropertyConnection connection = connectionFactory.getConnection(); assertNotNull(connection); assertEquals("A", connection.getResourceAdapterProperty()); assertEquals("B", connection.getManagedConnectionFactoryProperty()); assertEquals("C", adminObject.getProperty()); connection.close(); }
From source file:nl.b3p.catalog.kaartenbalie.KbJDBCHelper.java
protected Connection getConnection() throws NamingException, SQLException { Context initCtx = new InitialContext(); DataSource ds = (DataSource) initCtx.lookup(root.getJndiDataSource()); return ds.getConnection(); }
From source file:org.ambraproject.action.debug.DebugInfoAction.java
@Override public String execute() throws Exception { if (!checkAccess()) { return ERROR; }//from w ww . j a va2s . c om timestamp = new Date(System.currentTimeMillis()); Runtime rt = Runtime.getRuntime(); jvmFreeMemory = (double) rt.freeMemory() / (1024.0 * 1024.0); jvmTotalMemory = (double) rt.totalMemory() / (1024.0 * 1024.0); jvmMaxMemory = (double) rt.maxMemory() / (1024.0 * 1024.0); HttpServletRequest req = ServletActionContext.getRequest(); tomcatVersion = ServletActionContext.getServletContext().getServerInfo(); sessionCount = SessionCounter.getSessionCount(); host = req.getLocalName(); hostIp = req.getLocalAddr(); buildInfo = generateBuildInfo(); // The easiest way I found to get the URL and username for the DB. // It's not that easy and involves opening a connection... Context initialContext = new InitialContext(); Context context = (Context) initialContext.lookup("java:comp/env"); DataSource ds = (DataSource) context.lookup("jdbc/AmbraDS"); Connection conn = null; try { conn = ds.getConnection(); DatabaseMetaData metadata = conn.getMetaData(); dbUrl = metadata.getURL(); dbUser = metadata.getUserName(); } finally { conn.close(); } Configuration config = ConfigurationStore.getInstance().getConfiguration(); FileStoreService filestoreService = (FileStoreService) context.lookup("ambra/FileStore"); filestore = filestoreService.toString(); solrUrl = (String) config.getProperty("ambra.services.search.server.url"); configuration = dumpConfig(config); cmdLine = IOUtils.toString(new FileInputStream("/proc/self/cmdline")); return SUCCESS; }
From source file:biz.taoconsulting.dominodav.resource.DAVResourceJDBC.java
/** * /**/* w w w . j av a2 s .c om*/ * * @see biz.taoconsulting.dominodav.resource.DAVAbstractResource#getStream() */ public InputStream getStream() { Connection conn = null; Statement stmt = null; InputStream blobStream = null; try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); DataSource ds = (DataSource) // THe internal address of a JDBC source is the data source envCtx.lookup(this.repositoryMeta.getInternalAddress()); conn = ds.getConnection(); stmt = conn.createStatement(); // XXX: THat is plain wrong -- need to rework the JDBC data source // query ResultSet rs = stmt.executeQuery( "select f.fil_blocksize,f.fil_contents_blob from ibkuis_pp_files f where f.fil_id=" + this.getDBFileID()); if (rs.next()) { Blob blob = rs.getBlob(2); blobStream = blob.getBinaryStream(); } } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); if (conn != null) conn.close(); } catch (SQLException e) { /** Exception handling **/ } } return blobStream; }
From source file:biz.taoconsulting.dominodav.resource.DAVResourceJDBC.java
private void getInitDBFileValues() { Statement stmt = null;/*from w w w .j a v a 2 s . co m*/ Statement stmt1 = null; Connection conn = null; try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup(this.repositoryMeta.getInternalAddress()); conn = ds.getConnection(); stmt1 = conn.createStatement(); // TODO fix this stmt1.executeQuery("select uis_mid_onetimeinitweb('DATENADMIN','umsys','DE') as a from dual"); stmt = conn.createStatement(); // TODO: Fix that SQL ResultSet rs = stmt.executeQuery( "select t.dtyp_mimetype,d.*," + "f.fil_length,f.fil_id from umsys.ibkuis_co_filetype t," + "uis_pp_documents_v d, ibkuis_pp_files f where d.D_ID =" + this.getDBDocID() + "and f.fil_id = d.D_FIL_ID and t.dtyp_kz = upper(d.D_TYP)"); if (rs.next()) { this.setName(rs.getString("D_FILE")); this.setExtension(rs.getString("D_TYP")); this.setContentLength(rs.getString("FIL_LENGTH")); this.setDBFileID(rs.getString("FIL_ID")); this.setMimeType(rs.getString("dtyp_mimetype")); System.out.println("BREAK"); } } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); if (stmt1 != null) stmt1.close(); if (conn != null) conn.close(); } catch (SQLException e) { /** Exception handling **/ } } }
From source file:org.apache.catalina.realm.UserDatabaseRealm.java
/** * Prepare for active use of the public methods of this Component. * * @exception LifecycleException if this component detects a fatal error * that prevents it from being started/*from ww w . ja v a 2s .com*/ */ public synchronized void start() throws LifecycleException { try { StandardServer server = (StandardServer) ServerFactory.getServer(); Context context = server.getGlobalNamingContext(); database = (UserDatabase) context.lookup(resourceName); } catch (Throwable e) { e.printStackTrace(); log(sm.getString("userDatabaseRealm.lookup", resourceName), e); database = null; } if (database == null) { throw new LifecycleException(sm.getString("userDatabaseRealm.noDatabase", resourceName)); } // Perform normal superclass initialization super.start(); }
From source file:org.jboss.as.test.integration.security.vault.VaultDatasourceTestCase.java
@Test public void testRejectWrongPasswordThroughVaultDatasource() throws Exception { Context initialContext = new InitialContext(); DataSource ds = (DataSource) initialContext.lookup("java:jboss/datasources/" + VAULT_BLOCK_WRONG); Assert.assertNotNull(ds);//from w w w . ja v a 2 s . co m Connection con = null; try { con = ds.getConnection(); con.close(); fail("Connect to database with wrong password!"); } catch (Exception ex) { } }
From source file:it.infn.ct.security.actions.RegisterUser.java
private void sendMail(UserRequest usreq) throws MailException { javax.mail.Session session = null;//w ww . j a v a 2s . c o m try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); session = (javax.mail.Session) envCtx.lookup("mail/Users"); } catch (Exception ex) { log.error("Mail resource lookup error"); log.error(ex.getMessage()); throw new MailException("Mail Resource not available"); } Message mailMsg = new MimeMessage(session); try { mailMsg.setFrom(new InternetAddress(mailFrom, idPAdmin)); InternetAddress mailTo[] = new InternetAddress[1]; mailTo[0] = new InternetAddress(usreq.getPreferredMail(), usreq.getTitle() + " " + usreq.getGivenname() + " " + usreq.getSurname()); mailMsg.setRecipients(Message.RecipientType.TO, mailTo); String ccMail[] = mailCC.split(";"); InternetAddress mailCCopy[] = new InternetAddress[ccMail.length]; for (int i = 0; i < ccMail.length; i++) { mailCCopy[i] = new InternetAddress(ccMail[i]); } mailMsg.setRecipients(Message.RecipientType.CC, mailCCopy); mailMsg.setSubject(mailSubject); mailBody = mailBody.replaceAll("_USER_", usreq.getTitle() + " " + usreq.getGivenname() + " " + usreq.getSurname()); mailMsg.setText(mailBody); Transport.send(mailMsg); } catch (UnsupportedEncodingException ex) { log.error(ex); throw new MailException("Mail from address format not valid"); } catch (MessagingException ex) { log.error(ex); throw new MailException("Mail message has problems"); } }
From source file:org.jboss.as.test.integration.security.vault.VaultDatasourceTestCase.java
@Test public void testAccessThroughVaultDatasource() throws Exception { Context initialContext = new InitialContext(); DataSource ds = (DataSource) initialContext.lookup("java:jboss/datasources/" + VAULT_BLOCK); Assert.assertNotNull(ds);/*from w w w. ja v a 2 s. co m*/ Connection con = null; try { con = ds.getConnection(); } catch (Exception ex) { fail(ex.getMessage()); } ResultSet rs = con.prepareStatement("SELECT Name FROM TestPeople WHERE Surname='Smith'").executeQuery(); rs.next(); assertEquals(rs.getString("Name"), "John"); con.close(); }