List of usage examples for javax.naming InitialContext InitialContext
public InitialContext(Hashtable<?, ?> environment) throws NamingException
From source file:it.cnr.isti.labsedc.glimpse.MainMonitoring.java
public static boolean init() { boolean successfullInit = false; try {//from ww w. ja va 2 s . c om //the connection are initialized Properties environmentParameters = Manager.Read(ENVIRONMENTPARAMETERSFILE); initConn = new InitialContext(environmentParameters); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "Connection Parameters"); DebugMessages.line(); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.factory.initial " + environmentParameters.getProperty("java.naming.factory.initial")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.provider.url " + environmentParameters.getProperty("java.naming.provider.url")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.security.principal " + environmentParameters.getProperty("java.naming.security.principal")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.security.credentials " + environmentParameters.getProperty("java.naming.security.credentials")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "connectionFactoryNames " + environmentParameters.getProperty("connectionFactoryNames")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "topic.serviceTopic " + environmentParameters.getProperty("topic.serviceTopic")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "topic.probeTopic " + environmentParameters.getProperty("topic.probeTopic")); DebugMessages.line(); DebugMessages.print(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "Setting up TopicConnectionFactory"); connFact = (TopicConnectionFactory) initConn.lookup("TopicCF"); DebugMessages.ok(); DebugMessages.line(); successfullInit = true; } catch (NamingException e) { e.printStackTrace(); successfullInit = false; } catch (Exception e) { e.printStackTrace(); successfullInit = false; } return successfullInit; }
From source file:com.redhat.consulting.eapquickstarts.mutualauth.remoting.ejb.client.RemoteEJBClient.java
private static Context getInitialContext() throws NamingException { if (null == ctx) { ctx = new InitialContext(iniCtxProps); // ctx = new InitialContext(props); }//from ww w . j a v a2 s. c o m return ctx; }
From source file:com.mirth.connect.connectors.jms.JmsConnector.java
protected void initJndiContext() throws NamingException, InitialisationException { if (jndiContext == null) { Hashtable props = new Hashtable(); if (jndiInitialFactory != null) { props.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialFactory); } else if (jndiProviderProperties == null || !jndiProviderProperties.containsKey(Context.INITIAL_CONTEXT_FACTORY)) { throw new InitialisationException(new Message(Messages.X_IS_NULL, "jndiInitialFactory"), this); }//from www . j a v a 2 s . c om if (jndiProviderUrl != null) { props.put(Context.PROVIDER_URL, replacer.replaceValues(jndiProviderUrl)); } if (jndiProviderProperties != null) { props.putAll(jndiProviderProperties); } jndiContext = new InitialContext(props); } }
From source file:com.mirth.connect.connectors.jms.JmsReceiverTests.java
private static ConnectionFactory lookupConnectionFactoryWithJndi(JmsConnectorProperties connectorProperties) throws Exception { Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.PROVIDER_URL, connectorProperties.getJndiProviderUrl()); env.put(Context.INITIAL_CONTEXT_FACTORY, connectorProperties.getJndiInitialContextFactory()); env.put(Context.SECURITY_PRINCIPAL, connectorProperties.getUsername()); env.put(Context.SECURITY_CREDENTIALS, connectorProperties.getPassword()); initialContext = new InitialContext(env); String connectionFactoryName = connectorProperties.getJndiConnectionFactoryName(); return (ConnectionFactory) initialContext.lookup(connectionFactoryName); }
From source file:net.sf.ehcache.distribution.JNDIManualRMICacheManagerPeerProvider.java
/** * Register a new peer by looking it up in JNDI and storing * in a local cache the Context./* w w w. j a v a 2 s. c o m*/ * * @param jndiProviderUrl */ private Context registerPeerToContext(String jndiProviderUrl) { String initialContextFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); if (LOG.isDebugEnabled()) { LOG.debug("registerPeerToContext: " + jndiProviderUrl + " " + extractProviderUrl(jndiProviderUrl) + " with " + initialContextFactory); } Hashtable hashTable = new Hashtable(1); hashTable.put(Context.PROVIDER_URL, extractProviderUrl(jndiProviderUrl)); Context initialContext = null; try { initialContext = new InitialContext(hashTable); registerPeerToContext(jndiProviderUrl, initialContext); } catch (NamingException e) { LOG.warn(jndiProviderUrl + " " + e.getMessage()); registerPeerToContext(jndiProviderUrl, null); } return initialContext; }
From source file:it.openutils.mgnlaws.magnolia.init.ClasspathProviderImpl.java
/** * @see info.magnolia.repository.Provider#init(info.magnolia.repository.RepositoryMapping) *///from w w w .ja v a 2s . c om public void init(RepositoryMapping repositoryMapping) throws RepositoryNotInitializedException { checkXmlSettings(); this.repositoryMapping = repositoryMapping; /* connect to repository */ Map params = this.repositoryMapping.getParameters(); String configFile = (String) params.get(CONFIG_FILENAME_KEY); if (!StringUtils.startsWith(configFile, ClasspathPropertiesInitializer.CLASSPATH_PREFIX)) { configFile = Path.getAbsoluteFileSystemPath(configFile); } String repositoryHome = (String) params.get(REPOSITORY_HOME_KEY); repositoryHome = getRepositoryHome(repositoryHome); // cleanup the path, to remove eventual ../.. and make it absolute try { File repoHomeFile = new File(repositoryHome); repositoryHome = repoHomeFile.getCanonicalPath(); } catch (IOException e1) { // should never happen and it's not a problem at this point, just pass it to jackrabbit and see } String clusterid = SystemProperty.getProperty(MAGNOLIA_CLUSTERID_PROPERTY); if (StringUtils.isNotBlank(clusterid)) { System.setProperty(JACKRABBIT_CLUSTER_ID_PROPERTY, clusterid); } // get it back from system properties, if it has been set elsewhere clusterid = System.getProperty(JACKRABBIT_CLUSTER_ID_PROPERTY); log.info("Loading repository at {} (config file: {}) - cluster id: \"{}\"", new Object[] { repositoryHome, configFile, StringUtils.defaultString(clusterid, "<unset>") }); bindName = (String) params.get(BIND_NAME_KEY); jndiEnv = new Hashtable<String, Object>(); jndiEnv.put(Context.INITIAL_CONTEXT_FACTORY, params.get(CONTEXT_FACTORY_CLASS_KEY)); jndiEnv.put(Context.PROVIDER_URL, params.get(PROVIDER_URL_KEY)); try { InitialContext ctx = new InitialContext(jndiEnv); // first try to find the existing object if any try { this.repository = (Repository) ctx.lookup(bindName); } catch (NameNotFoundException ne) { log.debug("No JNDI bound Repository found with name {}, trying to initialize a new Repository", bindName); ClasspathRegistryHelper.registerRepository(ctx, bindName, configFile, repositoryHome, true); this.repository = (Repository) ctx.lookup(bindName); } this.validateWorkspaces(); } catch (NamingException e) { log.error("Unable to initialize repository: " + e.getMessage(), e); throw new RepositoryNotInitializedException(e); } catch (RepositoryException e) { log.error("Unable to initialize repository: " + e.getMessage(), e); throw new RepositoryNotInitializedException(e); } catch (TransformerFactoryConfigurationError e) { log.error("Unable to initialize repository: " + e.getMessage(), e); throw new RepositoryNotInitializedException(e); } }
From source file:it.doqui.index.ecmengine.client.engine.EcmEngineDirectDelegateImpl.java
protected EcmEngineSearchBusinessInterface createSearchService() throws Throwable { this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] BEGIN "); Properties properties = new Properties(); /* Caricamento del file contenenti le properties su cui fare il binding */ rb = ResourceBundle.getBundle(ECMENGINE_PROPERTIES_FILE); /*//w ww. ja v a 2s. c o m * Caricamento delle proprieta' su cui fare il binding all'oggetto di business delle funzionalita' * implementate per la ricerca. */ try { this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] P-Delegata di search."); this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] context factory vale : " + rb.getString(ECMENGINE_CONTEXT_FACTORY)); properties.put(Context.INITIAL_CONTEXT_FACTORY, rb.getString(ECMENGINE_CONTEXT_FACTORY)); this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] url to connect vale : " + rb.getString(ECMENGINE_URL_TO_CONNECT)); properties.put(Context.PROVIDER_URL, rb.getString(ECMENGINE_URL_TO_CONNECT)); /* Controllo che la property cluster partition sia valorizzata per capire se * sto lavorando in una configurazione in cluster oppure no */ String clusterPartition = rb.getString(ECMENGINE_CLUSTER_PARTITION); this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] clusterPartition vale : " + clusterPartition); if (clusterPartition != null && clusterPartition.length() > 0) { properties.put("jnp.partitionName", clusterPartition); this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] disable discovery vale : " + rb.getString(ECMENGINE_DISABLE_DISCOVERY)); properties.put("jnp.disableDiscovery", rb.getString(ECMENGINE_DISABLE_DISCOVERY)); } // Get an initial context InitialContext jndiContext = new InitialContext(properties); log.debug("[" + getClass().getSimpleName() + "::createSearchService] context istanziato"); // Get a reference to the Bean Object ref = jndiContext.lookup(ECMENGINE_SEARCH_JNDI_NAME); // Get a reference from this to the Bean's Home interface EcmEngineSearchHome home = (EcmEngineSearchHome) PortableRemoteObject.narrow(ref, EcmEngineSearchHome.class); // Create an Adder object from the Home interface return home.create(); } catch (Throwable e) { this.log.error("[" + getClass().getSimpleName() + "::createSearchService] " + "Impossibile l'EJB di management: " + e.getMessage()); throw e; } finally { this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] END "); } }
From source file:it.openutils.mgnlaws.magnolia.init.ClasspathProviderImpl.java
public void shutdownRepository() { log.info("Shutting down repository bound to '{}'", bindName); try {// w ww. jav a2s .com Context ctx = new InitialContext(jndiEnv); RegistryHelper.unregisterRepository(ctx, bindName); } catch (NamingException e) { log.warn("Unable to shutdown repository " + bindName + ": " + e.getMessage(), e); } catch (Throwable e) { log.error("Failed to shutdown repository " + bindName + ": " + e.getMessage(), e); } }