List of usage examples for javax.naming Context INITIAL_CONTEXT_FACTORY
String INITIAL_CONTEXT_FACTORY
To view the source code for javax.naming Context INITIAL_CONTEXT_FACTORY.
Click Source Link
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: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:org.wso2.carbon.automation.extensions.servers.jmsserver.client.JMSTopicMessageConsumer.java
public JMSTopicMessageConsumer(JMSBrokerConfiguration brokerConfiguration) throws NamingException { // Create a ConnectionFactory Properties props = new Properties(); props.setProperty(Context.INITIAL_CONTEXT_FACTORY, brokerConfiguration.getInitialNamingFactory()); if (brokerConfiguration.getProviderURL().startsWith("amqp://")) { //setting property for Qpid running on WSO2 MB props.put("connectionfactory.TopicConnectionFactory", brokerConfiguration.getProviderURL()); } else {//from w ww . j a va2 s.c o m //setting property for ActiveMQ props.setProperty(Context.PROVIDER_URL, brokerConfiguration.getProviderURL()); } Context ctx = new InitialContext(props); connectionFactory = (TopicConnectionFactory) ctx.lookup("TopicConnectionFactory"); }
From source file:com.clican.pluto.cms.ui.listener.StartupListener.java
public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); try {/*from w w w . ja v a 2 s . co m*/ Velocity.init( Thread.currentThread().getContextClassLoader().getResource("velocity.properties").getPath()); } catch (Exception e) { throw new RuntimeException(e); } ApplicationContext ctx = null; JndiUtils.setJndiFactory(MockContextFactory.class.getName()); Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put(Context.INITIAL_CONTEXT_FACTORY, MockContextFactory.class.getName()); try { ctx = (ApplicationContext) JndiUtils.lookupObject(ApplicationContext.class.getName()); if (ctx == null) { log.warn("Cannot get ApplicationContext from JNDI"); } } catch (Exception e) { log.warn("Cannot get ApplicationContext from JNDI"); } if (ctx == null) { ctx = (new ClassPathXmlApplicationContext(new String[] { "classpath*:META-INF/ui-*.xml", })); } XmlWebApplicationContext wac = (XmlWebApplicationContext) WebApplicationContextUtils .getRequiredWebApplicationContext(event.getServletContext()); wac.setParent(ctx); wac.refresh(); event.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); Constants.ctx = wac; }
From source file:org.pepstock.jem.junit.test.springbatch.java.RestRunnable.java
@Override public void run() { try {/*w w w . j a v a 2s. c o m*/ Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.pepstock.jem.node.tasks.jndi.JemContextFactory"); InitialContext context = new InitialContext(env); RestClient rest = (RestClient) context.lookup("JUNIT-REST-RESOURCE"); System.err.println(); System.err.println("*** REST XML"); get(rest, MediaType.APPLICATION_XML); get(rest, MediaType.APPLICATION_JSON); get(rest, MediaType.APPLICATION_XML); get(rest, MediaType.APPLICATION_JSON); } catch (NamingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } try { System.err.println(); System.err.println("*** REST XML"); get(restC, MediaType.APPLICATION_XML); get(restC, MediaType.APPLICATION_JSON); get(restC, MediaType.APPLICATION_XML); get(restC, MediaType.APPLICATION_JSON); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.eclipselabs.etrack.util.security.ldap.impl.LdapSecurityService.java
@Override public boolean authenticate(String id, char[] password) { String cachedPassword = credentialCache.get(id); String encodedPassword = null; try {//from w w w .j a v a 2 s . c o m encodedPassword = codec.encode(new String(password)); } catch (EncoderException e1) { } if (cachedPassword != null && encodedPassword != null && cachedPassword.equals(encodedPassword)) return true; Hashtable<String, String> environment = new Hashtable<String, String>(); environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); environment.put(Context.PROVIDER_URL, url); environment.put(Context.SECURITY_AUTHENTICATION, "simple"); environment.put(Context.SECURITY_PRINCIPAL, id); environment.put(Context.SECURITY_CREDENTIALS, new String(password)); try { InitialDirContext context = new InitialDirContext(environment); context.close(); if (encodedPassword != null) credentialCache.put(id, encodedPassword); return true; } catch (NamingException e) { return false; } }
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 ava2 s. c o m // 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:net.sf.ehcache.distribution.JNDIRMICacheReplicatorTest.java
/** * {@inheritDoc}//from w w w .ja v a 2s .c o m * Sets up two caches: cache1 is local. cache2 is to be receive updates * * @throws Exception */ protected void setUp() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, MockContextFactory.class.getName()); new MockContextFactory().clear(); CountingCacheEventListener.resetCounters(); manager1 = new CacheManager( AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-distributed-jndi1.xml"); manager2 = new CacheManager( AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-distributed-jndi2.xml"); manager3 = new CacheManager( AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-distributed-jndi3.xml"); manager4 = new CacheManager( AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-distributed-jndi4.xml"); manager5 = new CacheManager( AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-distributed-jndi5.xml"); //manager6 = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-distributed-jndi6.xml"); //allow cluster to be established Thread.sleep(1000); cache1 = manager1.getCache(cacheName); cache1.removeAll(); cache2 = manager2.getCache(cacheName); cache2.removeAll(); //enable distributed removeAlls to finish waitForProgagate(); }
From source file:org.pepstock.jem.junit.test.http.java.HttpConsumeSbTasklet.java
@Override public RepeatStatus run(StepContribution stepContribution, ChunkContext chuckContext) throws TaskletException { try {// w w w. j av a2 s . c o m Hashtable<String, String> env = this.createEnvironment(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.pepstock.jem.node.tasks.jndi.JemContextFactory"); InitialContext context = new InitialContext(env); // get http resource, note that jem-http is the name of the resource // present in the JCL InputStream httpStream = (InputStream) context.lookup("jem-http"); StringWriter writer = new StringWriter(); IOUtils.copy(httpStream, writer); String theString = writer.toString(); System.out.println("Read Http: " + theString); httpStream.close(); } catch (Exception e) { throw new TaskletException(e); } return RepeatStatus.FINISHED; }
From source file:org.dhatim.routing.jms.activemq.ActiveMQProvider.java
public ActiveMQProvider() { jndiProperties = new Properties(); jndiProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getName()); jndiProperties.setProperty(Context.PROVIDER_URL, DEFAULT_PROVIDER_URL); }