List of usage examples for javax.naming InitialContext InitialContext
public InitialContext(Hashtable<?, ?> environment) throws NamingException
From source file:WeblogicDbServlet.java
public void init() throws ServletException { Context env = null;//from w w w. j a va2 s . co m Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); //ht.put(Context.PROVIDER_URL,"t3://localhost:7001"); try { env = new InitialContext(ht); pool = (javax.sql.DataSource) env.lookup("oracle-8i-athletes"); if (pool == null) throw new ServletException("'oracle-8i-athletes' is an unknown DataSource"); } catch (NamingException ne) { throw new ServletException(ne); } }
From source file:gov.nih.nci.cagrid.caarray.stubs.cql.CaArrayCQLQueryProcessor.java
private static synchronized CaArraySearchService getSearchService() { try {/* ww w .j a v a 2s . com*/ final Properties jndiProp = new Properties(); jndiProp.load(CaArraySvcImpl.class.getResourceAsStream("/gov/nih/nci/cagrid/caarray/jndi.properties")); if (jndiProp.getProperty("java.naming.factory.initial") == null || jndiProp.getProperty("java.naming.factory.url.pkgs") == null || jndiProp.getProperty("java.naming.provider.url") == null) { throw new IllegalArgumentException( "Unable to find all required properties in jndi.properties file."); } final Context context = new InitialContext(jndiProp); searchService = (CaArraySearchService) context.lookup(CaArraySearchService.JNDI_NAME); } catch (final Exception e) { throw new RuntimeException(e); } return searchService; }
From source file:com.sf.ddao.conn.JNDIDataSourceHandler.java
public void init(AnnotatedElement element, Annotation annotation) { JNDIDao daoAnnotation = (JNDIDao) annotation; String dsName = daoAnnotation.value(); try {/*ww w. ja v a2 s . c o m*/ InitialContext ic = new InitialContext(new Hashtable()); dataSource = (DataSource) ic.lookup(DS_CTX_PREFIX + dsName); } catch (Exception e) { throw new InitializerException("Failed to find DataSource " + dsName, e); } }
From source file:com.adaptris.core.runtime.RetryMessageErrorHandlerMonitorTest.java
public void setUp() throws Exception { super.setUp(); env.put(Context.INITIAL_CONTEXT_FACTORY, JndiContextFactory.class.getName()); initialContext = new InitialContext(env); }
From source file:jp.go.nict.langrid.serviceexecutor.db.ConnectionManager.java
private void initWithJNDI(String jndiName) throws NamingException { this.dataSource = (DataSource) new InitialContext(System.getProperties()).lookup(jndiName); }
From source file:any.ejbtest.MoviesTest.java
private void initEjbContext() throws Exception { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); p.put("openejb.deployments.classpath.ear", "true"); context = new InitialContext(p); moviesLocal = (Movies) context.lookup("MoviesImplLocal"); moviesLegacyLocal = (Movies) context.lookup("MoviesImplLegacyLocal"); }
From source file:com.microsoft.azure.servicebus.samples.jmsqueuequickstart.JmsQueueQuickstart.java
public void run(String connectionString) throws Exception { // The connection string builder is the only part of the azure-servicebus SDK library // we use in this JMS sample and for the purpose of robustly parsing the Service Bus // connection string. ConnectionStringBuilder csb = new ConnectionStringBuilder(connectionString); // set up JNDI context Hashtable<String, String> hashtable = new Hashtable<>(); hashtable.put("connectionfactory.SBCF", "amqps://" + csb.getEndpoint().getHost() + "?amqp.idleTimeout=120000&amqp.traceFrames=true"); hashtable.put("queue.QUEUE", "BasicQueue"); hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); Context context = new InitialContext(hashtable); ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF"); // Look up queue Destination queue = (Destination) context.lookup("QUEUE"); // we create a scope here so we can use the same set of local variables cleanly // again to show the receive side separately with minimal clutter {//from w w w . j ava 2 s. c om // Create Connection Connection connection = cf.createConnection(csb.getSasKeyName(), csb.getSasKey()); // Create Session, no transaction, client ack Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); // Create producer MessageProducer producer = session.createProducer(queue); // Send messages for (int i = 0; i < totalSend; i++) { BytesMessage message = session.createBytesMessage(); message.writeBytes(String.valueOf(i).getBytes()); producer.send(message); System.out.printf("Sent message %d.\n", i + 1); } producer.close(); session.close(); connection.stop(); connection.close(); } { // Create Connection Connection connection = cf.createConnection(csb.getSasKeyName(), csb.getSasKey()); connection.start(); // Create Session, no transaction, client ack Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); // Create consumer MessageConsumer consumer = session.createConsumer(queue); // create a listener callback to receive the messages consumer.setMessageListener(message -> { try { // receives message is passed to callback System.out.printf("Received message %d with sq#: %s\n", totalReceived.incrementAndGet(), // increments the tracking counter message.getJMSMessageID()); message.acknowledge(); } catch (Exception e) { logger.error(e); } }); // wait on the main thread until all sent messages have been received while (totalReceived.get() < totalSend) { Thread.sleep(1000); } consumer.close(); session.close(); connection.stop(); connection.close(); } System.out.printf("Received all messages, exiting the sample.\n"); System.out.printf("Closing queue client.\n"); }
From source file:de.tud.inf.db.sparqlytics.bench.LDBCBenchmark.java
@BeforeClass public static void bindRepository() throws Exception { SPARQLyticsParser parser = new SPARQLyticsParser( new InputStreamReader(LDBCBenchmark.class.getResourceAsStream("ldbc-snb-bi-repository.sparqlytics"), StandardCharsets.UTF_8)); parser.Start();/*from w w w . j a va 2 s.c o m*/ Repository repository = parser.getRepository(); Slf4jReporter.forRegistry(repository.getStatistics()).withLoggingLevel(Slf4jReporter.LoggingLevel.INFO) .prefixedWith("before:").build().report(); //Set system properties Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL in pom.xml new InitialContext(new Hashtable<Object, Object>()).bind("ldbc", repository); }
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 ww . j a va 2s. c om*/ 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:endpoint.protocol.jms.JMSBrokerController.java
public JMSBrokerController(String providerURL, Properties properties) { this.providerURL = providerURL; InitialContext ctx;// w w w . j a v a 2 s.com try { ctx = new InitialContext(properties); this.connectionFactory = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory"); } catch (NamingException e) { log.info("Error while creating connection factory"); } }