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:org.betaconceptframework.astroboa.test.AstroboaTestContext.java
private AstroboaTestContext() { try {/* w w w . ja v a 2s . c om*/ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory"); System.setProperty(Context.PROVIDER_URL, "localhost"); System.setProperty("org.betaconceptframework.astroboa.configuration.dir", new ClassPathResource("/").getFile().getAbsolutePath()); removeRepositoryResources(TestConstants.TEST_REPOSITORY_ID); removeRepositoryResources(TestConstants.TEST_IDENTITY_STORE_REPOSITORY_ID); removeRepositoryResources(TestConstants.TEST_CLONE_REPOSITORY_ID); //Initialize Spring - Order is SIGNIFICANT. Spring context must be initialized at the end applicationContext = new ClassPathXmlApplicationContext(getConfigLocations()); } catch (Exception e) { throw new CmsException(e); } }
From source file:org.exist.messaging.JmsMessageSender.java
@Override public NodeImpl send(JmsMessagingConfiguration config, MessagingMetadata metadata, Item content) throws XPathException { // JMS specific checks config.validateContent();// w ww .j a v a 2s .c o m // Retrieve relevant values String initialContextFactory = config.getInitalContextProperty(Context.INITIAL_CONTEXT_FACTORY); String providerURL = config.getInitalContextProperty(Context.PROVIDER_URL); String connectionFactory = config.getConnectionFactory(); String destination = config.getDestination(); // TODO split up, use more exceptions, add better reporting try { Properties props = new Properties(); props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); props.setProperty(Context.PROVIDER_URL, providerURL); javax.naming.Context context = new InitialContext(props); // Setup connection ConnectionFactory cf = (ConnectionFactory) context.lookup(connectionFactory); Connection connection = cf.createConnection(); // Lookup queue Destination dest = (Destination) context.lookup(destination); // Create session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create message producer MessageProducer producer = session.createProducer(dest); // Create message Message message = createMessage(session, content, metadata, xqcontext); // Write properties Map<String, String> kvs = metadata.getValueMap(); for (String key : kvs.keySet()) { message.setStringProperty(key, kvs.get(key)); } // Send message producer.send(message); // Close connection // TODO keep connection open for re-use, efficiency connection.close(); return createReport(message, xqcontext); } catch (Throwable ex) { LOG.error(ex); throw new XPathException(ex); } }
From source file:org.aludratest.service.jms.impl.JmsServiceImpl.java
@Override public void configure(Preferences preferences) { ValidatingPreferencesWrapper prefs = new ValidatingPreferencesWrapper(preferences); providerUrl = prefs.getRequiredStringValue("providerUrl"); String initialContextFactory = prefs.getRequiredStringValue("initialContextFactory"); String connectionFactoryName = prefs.getRequiredStringValue("connectionFactoryJndiName"); String userName = prefs.getStringValue("jmsUser"); String password = prefs.getStringValue("jmsPassword"); Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); env.put(Context.PROVIDER_URL, providerUrl); if (!StringUtils.isEmpty(userName)) { env.put(Context.SECURITY_PRINCIPAL, userName); }//from w w w .ja va 2 s. c o m if (!StringUtils.isEmpty(password)) { env.put(Context.SECURITY_CREDENTIALS, password); } try { initialContext = new InitialContext(env); connectionFactory = (ConnectionFactory) initialContext.lookup(connectionFactoryName); if (connectionFactory == null) { throw new ConfigurationException("The connection factory could not be found."); } } catch (NamingException e) { throw new TechnicalException("Could not retrieve objects from JNDI context", e); } action = new JmsActionImpl(connectionFactory, initialContext, userName, password); }
From source file:es.udl.asic.user.OpenLdapDirectoryProvider.java
public void init() { try {//from w w w. j ava2 s .c o m M_log.info("init()"); } catch (Throwable t) { M_log.warn("init(): ", t); } env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, getLdapHost() + ":" + getLdapPort()); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_CREDENTIALS, "secret"); }
From source file:org.apache.servicemix.jms.JmsSpringTest.java
protected AbstractXmlApplicationContext createBeanFactory() { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, SpringInitialContextFactory.class.getName()); System.setProperty(Context.PROVIDER_URL, "org/apache/servicemix/jms/jndi.xml"); return new ClassPathXmlApplicationContext("org/apache/servicemix/jms/spring.xml"); }
From source file:org.wso2.carbon.appfactory.stratos.listeners.TenantStratosSubscriptionDurableSubscriber.java
/** * Subscribe as a durable subscriber to the topic. * * @throws AppFactoryEventException/*from w ww . jav a2s .c o m*/ */ public void subscribe() throws AppFactoryEventException { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, AppFactoryConstants.ANDES_ICF); properties.put(AppFactoryConstants.CF_NAME_PREFIX + AppFactoryConstants.CF_NAME, Util.getTCPConnectionURL()); properties.put(CarbonConstants.REQUEST_BASE_CONTEXT, true); properties.put(AppFactoryConstants.TOPIC, topicName); try { ctx = new InitialContext(properties); connFactory = (TopicConnectionFactory) ctx.lookup(AppFactoryConstants.CF_NAME); topicConnection = connFactory.createTopicConnection(); topicSession = topicConnection.createTopicSession(false, TopicSession.CLIENT_ACKNOWLEDGE); Topic topic; try { topic = (Topic) ctx.lookup(topicName); } catch (NamingException e) { topic = topicSession.createTopic(topicName); } topicSubscriber = topicSession.createDurableSubscriber(topic, subscriptionId); topicSubscriber.setMessageListener( new TenantStratosSubscriptionMessageListener(topicConnection, topicSession, topicSubscriber)); topicConnection.start(); if (log.isDebugEnabled()) { log.debug("Durable Subscriber created for topic " + topicName + " with subscription id" + subscriptionId); } } catch (NamingException e) { String errorMsg = "Failed to subscribe to topic:" + topicName + " due to " + e.getMessage(); throw new AppFactoryEventException(errorMsg, e); } catch (JMSException e) { String errorMsg = "Failed to subscribe to topic:" + topicName + " due to " + e.getMessage(); throw new AppFactoryEventException(errorMsg, e); } }
From source file:it.unipmn.di.dcs.sharegrid.web.management.ManagementEnv.java
/** Initialized the JNDI. */ protected void initJNDI() throws ManagementException { try {//from w w w. jav a2s. c o m this.ctxFactoryBuild = new ManagementContextFactoryBuilder(); NamingManager.setInitialContextFactoryBuilder(this.ctxFactoryBuild); NamingManager.setObjectFactoryBuilder(this.ctxFactoryBuild); // Initial environment with various properties Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, ManagementContextFactory.class.getName()); //env.put(Context.PROVIDER_URL, ""); //env.put(Context.OBJECT_FACTORIES, "foo.bar.ObjFactory"); env.put(Context.URL_PKG_PREFIXES, ManagementContextFactory.class.getPackage().getName()); this.initCtx = new InitialContext(env); Context javaCompCtx = (Context) this.getOrCreateSubcontext("java:comp", initCtx); if (javaCompCtx == null) { throw new ManagementException("JNDI problem. Cannot get java:comp context from InitialContext."); } Context envCtx = (Context) this.getOrCreateSubcontext("env", javaCompCtx); if (envCtx == null) { throw new ManagementException("JNDI problem. Cannot get env context from java:comp context."); } Context jdbcCtx = (Context) this.getOrCreateSubcontext("jdbc", envCtx); if (jdbcCtx == null) { throw new ManagementException("JNDI problem. Cannot get jdbc context from java:comp/env context."); } // Create the DataSource //Properties properties = new Properties(); //properties.put( "driverClassName", "com.mysql.jdbc.Driver" ); //properties.put( "url", "jdbc:mysql://localhost:3306/DB" ); //properties.put( "username", "username" ); //properties.put( "password", "********" ); // //DataSource dataSource = BasicDataSourceFactory.createDataSource( properties ); //initContext.bind( "java:comp/env/jdbc/db", dataSource ); //Reference ref = new Reference( "javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null ); //ref.add(new StringRefAddr("driverClassName", "com.mysql.jdbc.Driver")); //ref.add(new StringRefAddr("url", "jdbc:mysql://localhost:3306/sharegrid")); //ref.add(new StringRefAddr("username", "root")); //ref.add(new StringRefAddr("password", "")); //initCtx.rebind( "java:comp/env/jdbc/mysql", ref ); java.util.Properties properties = new java.util.Properties(); properties.put("driverClassName", "com.mysql.jdbc.Driver"); properties.put("url", "jdbc:mysql://localhost:3306/sharegrid"); properties.put("username", "root"); properties.put("password", ""); javax.sql.DataSource dataSource = org.apache.commons.dbcp.BasicDataSourceFactory .createDataSource(properties); initCtx.rebind("java:comp/env/jdbc/mysql", dataSource); } catch (Exception ex) { throw new ManagementException("JNDI problem.", ex); } }
From source file:org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfigurationTests.java
@After public void close() { TestableInitialContextFactory.clearAll(); if (this.initialContextFactory != null) { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, this.initialContextFactory); } else {/*from w w w.j av a 2s.c om*/ System.clearProperty(Context.INITIAL_CONTEXT_FACTORY); } if (this.context != null) { this.context.close(); } Thread.currentThread().setContextClassLoader(this.threadContextClassLoader); }
From source file:org.apache.jackrabbit.ocm.spring.RepositoryUtil.java
/** * Unregister a repository/*w w w .j av a 2s . c o m*/ * * @param repositoryName The repository unique name * * @throws RepositoryException when it is not possible to unregister the repository */ public static void unRegisterRepository(String repositoryName) throws RepositoryException { try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory"); env.put(Context.PROVIDER_URL, "localhost"); InitialContext ctx = new InitialContext(env); RegistryHelper.unregisterRepository(ctx, repositoryName); } catch (Exception e) { throw new RepositoryException("Impossible to unregister the respository : " + repositoryName, e); } }
From source file:de.escidoc.core.admin.common.util.spring.RemoteJndiLocator.java
/** * Set the JNDI properties./* www . j a v a 2 s . c om*/ * * @throws WebserverSystemException * Thrown in case of an internal error. */ private void setInitialContextJndiProperties() throws WebserverSystemException { Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties.setProperty(Context.URL_PKG_PREFIXES, "org.jnp.interfaces:org.jboss.naming"); properties.setProperty(Context.PROVIDER_URL, jndiUrl); this.setJndiEnvironment(properties); }