/** * Check whether a default JNDI environment, as in a Java EE environment, * is available on this JVM. * @return {@code true} if a default InitialContext can be used, * {@code false} if not */ public static boolean isDefaultJndiEnvironmentAvailable() { if (shouldIgnoreDefaultJndiEnvironment) { return false; } try { new InitialContext().getEnvironment(); return true; } catch (Throwable ex) { return false; } }
/** * Check whether a default JNDI environment, as in a Java EE environment, * is available on this JVM. * @return {@code true} if a default InitialContext can be used, * {@code false} if not */ public static boolean isDefaultJndiEnvironmentAvailable() { if (shouldIgnoreDefaultJndiEnvironment) { return false; } try { new InitialContext().getEnvironment(); return true; } catch (Throwable ex) { return false; } }
/** * Initializes the {@link InitialContext} if not set. * * @throws Exception for any error */ public void init() throws Exception { if (initialContext == null) { initialContext = new InitialContext(); log.debug("initialContext.getEnvironment()=" + initialContext.getEnvironment()); jndiEnv = initialContext.getEnvironment(); } }
/** * Initializes the {@link InitialContext} if not set. * * @throws Exception for any error */ public void init() throws Exception { if (initialContext == null) { initialContext = new InitialContext(); log.debug("initialContext.getEnvironment()=" + initialContext.getEnvironment()); jndiEnv = initialContext.getEnvironment(); } }
/** * Check whether a default JNDI environment, as in a Java EE environment, * is available on this JVM. * @return {@code true} if a default InitialContext can be used, * {@code false} if not */ public static boolean isDefaultJndiEnvironmentAvailable() { if (shouldIgnoreDefaultJndiEnvironment) { return false; } try { new InitialContext().getEnvironment(); return true; } catch (Throwable ex) { return false; } }
public static Properties getDefaultProperties() { Properties defaultProperties = new Properties(); try { InitialContext context = new InitialContext(); defaultProperties.putAll(context.getEnvironment()); } catch (Exception e) { logger.debug("Unexpected exception when trying to retrieve default naming context.", e); } return defaultProperties; } }
public static Properties getDefaultProperties() { Properties defaultProperties = new Properties(); try { InitialContext context = new InitialContext(); defaultProperties.putAll(context.getEnvironment()); } catch (Exception e) { logger.debug("Unexpected exception when trying to retrieve default naming context.", e); } return defaultProperties; } }
public static Properties getDefaultProperties() { Properties defaultProperties = new Properties(); try { InitialContext context = new InitialContext(); defaultProperties.putAll(context.getEnvironment()); } catch (Exception e) { logger.debug("Unexpected exception when trying to retrieve default naming context.", e); } return defaultProperties; } }
InitialContext ic = new InitialContext(); System.out.println((String)ic.getEnvironment().get("java.naming.factory.initial"));
InitialContext ic = new InitialContext(); System.out.println((String)ic.getEnvironment().get("java.naming.factory.url.pkgs"));
@SuppressWarnings("unchecked") public static MBeanServerConnection getServer() { if (server == null) { Hashtable jndiEnv = null; try { InitialContext iniCtx = new InitialContext(); jndiEnv = iniCtx.getEnvironment(); server = (MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor"); } catch (NamingException ex) { throw new RuntimeException("Cannot obtain MBeanServerConnection using jndi props: " + jndiEnv, ex); } } return server; }
public JmsClient( final InitialContext context, final String defaultConnectionFactoryName, final String brokerURI ) throws NamingException { this.context = new InitialContext(context.getEnvironment()); this.defaultConnectionFactoryName = defaultConnectionFactoryName; this.brokerURI = brokerURI; if (this.brokerURI != null) { this.context.addToEnvironment(Context.PROVIDER_URL, this.brokerURI); } }
public InitialContext createInitialContext() throws NamingException { InitialContext ctx = delegate.createInitialContext(); log.debug("Using initial context: " + ctx.getEnvironment()); return ctx; }
@Override public Hashtable<?, ?> getEnvironment() throws NamingException { Hashtable<?, ?> out; if (this.initialContext == null) { out = this.defaultInitCtx.getEnvironment(); } else { out = this.initialContext.getEnvironment(); } return out; }
@Override public Hashtable<?, ?> getEnvironment() throws NamingException { Hashtable<?, ?> out; if (this.initialContext == null) { out = this.defaultInitCtx.getEnvironment(); } else { out = this.initialContext.getEnvironment(); } return out; }
/** * {@inheritDoc} */ public Hashtable<?, ?> getEnvironment() throws NamingException { if (isInitialContextInitializerCall()) { if (env == null) { // Must return non-null return new Hashtable(3, 0.75f); } else { return (Hashtable)env.clone(); } } return getContext().getEnvironment(); }
public static boolean checkForWildflyorWS() { String namingFactoryKey = null; try { InitialContext ic = new InitialContext(); namingFactoryKey = (String) ic.getEnvironment().get(EjbNaming.JBOSS.getKey()); if(namingFactoryKey == null || !EjbNaming.JBOSS.getValue().contains(namingFactoryKey)) { Object o = ic.lookup(EjbNaming.WEBSPHERE.getKey()); namingFactoryKey = o != null ? o.getClass().getName() : "Not JBoss or Websphere"; } } catch (NamingException e) { LOG.warn("No NamingFactory found -> using singleton bean data service."); return false; } boolean result = EjbNaming.JBOSS.getValue().contains(namingFactoryKey) || EjbNaming.WEBSPHERE.getValue().equals(namingFactoryKey); LOG.info("Value: '"+namingFactoryKey+"'"+" Return: "+result); return result; } }
Hashtable jndi = jndiContext.getEnvironment(); allKeys.addAll(jndi.keySet());
public Session getSession() throws EmailException { Session session = null; try { // get the session. InitialContext initialContext = new InitialContext(); printMap(initialContext.getEnvironment()); session = (Session)initialContext().lookup(jndiName); } catch( Exception e ) { log.info(e.getMessage(), e); throw new EmailException("Exception caught while looking up email session with jndi name '"+jndiName+"'.", e); } if( session == null ) { throw new EmailException("Could not look up email session with jndi name '"+jndiName+"'."); } return session; }
/** * context debugging info * * @throws NamingException */ private void traceContextInfo() throws NamingException { Hashtable<?, ?> ctxEnv; ctxEnv = context.getEnvironment(); LOG.info("Initial Context: " + ctxEnv); if (LOG.isDebugEnabled()) { final StringBuffer listBindings = new StringBuffer(); final NamingEnumeration<NameClassPair> nameClassPairs = context.list(""); while (nameClassPairs.hasMoreElements()) { final NameClassPair pair = nameClassPairs.nextElement(); listBindings.append("==> " + pair + "\n"); try { final NamingEnumeration<Binding> bindings = context.listBindings(pair.getName()); while (bindings.hasMoreElements()) { listBindings.append(" " + bindings.next() + "\n"); } } catch (final Exception e) { LOG.debug(pair.getName() + " throws: " + e.toString()); } } LOG.debug("list bound beans:\n" + listBindings); } }