List of usage examples for javax.naming InitialContext lookup
public Object lookup(Name name) throws NamingException
From source file:com.manning.junitbook.ch14.ejbs.TestAdministratorEJB.java
/** * @see TestCase#setUp()//from w ww.j av a 2 s . c om */ public void setUp() throws Exception { Properties properties = new Properties(); properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces"); InitialContext ctx = new InitialContext(properties); administrator = (IAdministratorLocal) ctx .lookup("ch14-cactus-ear-cactified/" + AdministratorBean.class.getSimpleName() + "/local"); Connection conn = getConnection(); Statement s = conn.createStatement(); s.execute("DROP TABLE USERS IF EXISTS"); s.execute("CREATE TABLE USERS(ID INT, NAME VARCHAR(40))"); PreparedStatement psInsert = conn.prepareStatement("INSERT INTO USERS VALUES (?, ?)"); psInsert.setInt(1, 1); psInsert.setString(2, "User 1"); psInsert.executeUpdate(); psInsert.setInt(1, 2); psInsert.setString(2, "User 2"); psInsert.executeUpdate(); }
From source file:org.meveo.service.job.JobExecutionService.java
@TransactionAttribute(TransactionAttributeType.NEVER) public void executeJob(String jobName, JobInstance jobInstance, User currentUser, JobCategoryEnum jobCategory) { try {//from w w w.j a v a2 s .co m HashMap<String, String> jobs = JobInstanceService.jobEntries.get(jobCategory); InitialContext ic = new InitialContext(); Job job = (Job) ic.lookup(jobs.get(jobName)); job.execute(jobInstance, currentUser); } catch (Exception e) { log.error("failed to execute timer job", e); } }
From source file:hudson.model.AbstractModelObject.java
/** * Checks jndi,environment, hudson environment and system properties for specified key. * Property is checked in direct order:/* w ww . ja v a 2 s .c o m*/ * <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; }
From source file:eu.uqasar.util.UQasarUtil.java
/** * Writes the user entities to rdf/*from ww w. j a v a 2 s . com*/ */ private static OntModel writeUserEntries() { OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); try { thewebsemantic.Bean2RDF writer = new Bean2RDF(model); InitialContext ic = new InitialContext(); UserService userService = (UserService) ic.lookup("java:module/UserService"); List<User> users = userService.getAll(); for (User u : users) { writer.save(u); } } catch (Exception e) { e.printStackTrace(); } return model; }
From source file:jms.queue.TestQueueSender.java
public void init(PublisherConfig conf) throws NamingException, JMSException { String queueName = conf.getQueueName(); Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, conf.getInitialContextFactory()); properties.put(conf.getConnectionFactoryPrefix() + "." + conf.getConnectionFactoryName(), conf.getTCPConnectionURL()); properties.put("queue." + queueName, queueName); InitialContext ctx = new InitialContext(properties); // Lookup connection factory QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(conf.getConnectionFactoryName()); queueConnection = connFactory.createQueueConnection(); queueConnection.start();/* w w w.j av a 2 s . c o m*/ if (conf.isTransactional()) { queueSession = queueConnection.createQueueSession(true, 0); } else { queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); } // Queue queue = (Queue)ctx.lookup(queueName); Queue queue = queueSession.createQueue(queueName); queueSender = queueSession.createSender(queue); config = conf; }
From source file:org.sample.jms.SampleQueueReceiver.java
public MessageConsumer registerSubscriber() throws NamingException, JMSException { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF); properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(userName, password)); properties.put("queue." + queueName, queueName); InitialContext ctx = new InitialContext(properties); // Lookup connection factory QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME); queueConnection = connFactory.createQueueConnection(); queueConnection.start();/*from w w w. ja v a2s . c o m*/ queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); Queue queue = (Queue) ctx.lookup(queueName); MessageConsumer consumer = queueSession.createConsumer(queue); return consumer; }
From source file:org.wso2.carbon.andes.ui.client.QueueReceiverClient.java
/** * Method used to register a subscriber to a queue. * @param nameOfQueue name of queue/*from w w w. j ava2 s. c o m*/ * @param username User's username as per user store * @param accesskey as generated by andes authentication service for the user. * @return javax.jms.Queue * @throws NamingException * @throws JMSException * @throws FileNotFoundException * @throws XMLStreamException * @throws AndesException */ public Queue registerReceiver(String nameOfQueue, String username, String accesskey) throws NamingException, JMSException, FileNotFoundException, XMLStreamException, AndesException { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF); properties.put(CF_NAME_PREFIX + CF_NAME, UIUtils.getTCPConnectionURL(username, accesskey)); properties.put("queue." + nameOfQueue, nameOfQueue); properties.put(CarbonConstants.REQUEST_BASE_CONTEXT, "true"); InitialContext ctx = new InitialContext(properties); // Lookup connection factory QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME); queueConnection = connFactory.createQueueConnection(); queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); //Receive message Queue queue = (Queue) ctx.lookup(nameOfQueue); queueConsumer = queueSession.createConsumer(queue); queueConnection.start(); return queue; }
From source file:org.hawkular.inventory.impl.tinkerpop.sql.SqlGraphProvider.java
@Override public SqlGraph instantiateGraph(Configuration configuration) { try {// w w w. j a v a 2 s. c o m Map<String, String> conf = configuration.prefixedWith("sql.") .getImplementationConfiguration(sysPropsAsProperties()); String jndi = conf.get("sql.datasource.jndi"); if (jndi == null || jndi.isEmpty()) { Log.LOG.iUsingJdbcUrl(conf.get("sql.datasource.url")); return new SqlGraph(new MapConfiguration(conf)); } else { InitialContext ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(jndi); Log.LOG.iUsingDatasource(jndi); return new SqlGraph(ds, new MapConfiguration(conf)); } } catch (Exception e) { throw new IllegalArgumentException("Could not instantiate the SQL graph.", e); } }
From source file:org.exoplatform.services.jcr.impl.storage.JDBCWDCTest.java
public void testContainerStartUp() throws Exception { // log.info("Container "+container); InitialContext context = new InitialContext(); DataSource ds = (DataSource) context.lookup(sourceName); assertNotNull(sourceName);/* w w w . java 2 s . c o m*/ Connection conn = ds.getConnection(); assertNotNull(conn); // conn = ds.getConnection(); // conn = ds.getConnection(); // conn = ds.getConnection(); // conn = ds.getConnection(); // conn = ds.getConnection(); // conn = ds.getConnection(); // // COMMONS-DBCP /////// // BasicDataSource bds = (BasicDataSource)ds; // System.out.println("getMaxActive: "+bds.getMaxActive()); // System.out.println("getInitialSize: "+bds.getInitialSize()); // System.out.println("getNumActive: "+bds.getNumActive()); // System.out.println("getNumIdle: "+bds.getNumIdle()); // System.out.println("getMaxWait: "+bds.getMaxWait()); // ////////////// // (conn instanceof PooledConnection) // System.out.println("CONN: "+conn); // System.out.println("Container "+container); }
From source file:org.sample.jms.SampleQueueSender.java
public void sendMessages() throws NamingException, JMSException { PropertyConfigurator.configure("log4j.properties"); Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF); properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(userName, password)); properties.put(QUEUE_NAME_PREFIX + queueName, queueName); InitialContext ctx = new InitialContext(properties); // Lookup connection factory QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME); queueConnection = connFactory.createQueueConnection(); queueConnection.start();/*w ww . j ava2 s . c o m*/ queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); Queue queue = (Queue) ctx.lookup(queueName); QueueSender queueSender = queueSession.createSender(queue); TextMessage textMessage; for (long i = 0; i < RECORD_COUNT; i++) { // create the message to send textMessage = queueSession.createTextMessage("Test Message Content" + messageCount); // Send message queueSender.send(textMessage); messageCount++; } queueSender.close(); queueSession.close(); queueConnection.close(); }