List of usage examples for javax.naming Binding getClassName
public String getClassName()
From source file:EnvEntry.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); try {/*w w w . ja v a2 s . co m*/ Context initCtx = new InitialContext(); NamingEnumeration e = initCtx.listBindings("java:comp/env"); while (e.hasMore()) { Binding binding = (Binding) e.next(); out.println("Name: " + binding.getName()); out.println("Type: " + binding.getClassName()); out.println("Value: " + binding.getObject()); out.println(); } } catch (NamingException e) { e.printStackTrace(out); } }
From source file:binky.reportrunner.ui.actions.datasource.SetupEditJNDIDataSource.java
private List<String> listJNDINames(Context ctx, String ident) throws NamingException { List<String> names = new LinkedList<String>(); String indent = ""; NamingEnumeration<Binding> list = ctx.listBindings(""); while (list.hasMore()) { Binding item = (Binding) list.next(); String className = item.getClassName(); String name = item.getName(); logger.debug(indent + className + " " + name); Object o = item.getObject(); if (o instanceof javax.naming.Context) { names.addAll(listJNDINames((Context) o, name)); } else {/*from www . j a v a 2s. c om*/ names.add(ident + "/" + name); } } return names; }
From source file:jndi.view.JndiView.java
/** * @param ctx//from www .j a v a2 s. c o m * the Context we're examining * @param path * the path to examine * @param bindings * the {@link NamingEnumeration} of {@link Binding}s * @return List of {@link JndiEntry} * @throws NamingException * on exception */ private List<JndiEntry> examineBindings(final Context ctx, final String path, final NamingEnumeration<Binding> bindings) throws NamingException { if (null == bindings) { throw new NullPointerException("bindings is null!"); } final List<JndiEntry> entries = new ArrayList<JndiEntry>(); while (bindings.hasMore()) { final Binding binding = bindings.next(); final String name = binding.getName(); final String className = binding.getClassName(); logger.finest("name: " + name + " [" + className + "]"); final JndiEntry entry = new JndiEntry(name, className); final Object obj = binding.getObject(); if (obj instanceof Context) { entry.setContext(true); String link = name; if (!path.isEmpty()) { link = path + "/" + name; } entry.setLink(link); } else if (obj instanceof Reference) { final Reference ref = (Reference) obj; entry.setTargetClassName(ref.getClassName()); } else if ("org.glassfish.javaee.services.ResourceProxy".equals(className)) { // SUPPRESS CHECKSTYLE AvoidInlineConditionals final Object lookup = ctx.lookup(path.isEmpty() ? name : path + "/" + name); if (lookup != null) { final String lookedUpClassName = lookup.getClass().getName(); logger.finest("lookup(\"" + name + "\") returned " + lookedUpClassName); entry.setTargetClassName(lookedUpClassName); } } else if ("com.sun.ejb.containers.JavaGlobalJndiNamingObjectProxy".equals(className)) { inspectJndiNamingObjectProxy(entry, obj); } entries.add(entry); } return entries; }
From source file:org.apache.openejb.assembler.classic.Assembler.java
public synchronized void destroy() { try {/*from w w w .j a v a 2s .com*/ EjbTimerServiceImpl.shutdown(); } catch (Exception e) { logger.warning("Unable to shutdown scheduler", e); } logger.debug("Undeploying Applications"); Assembler assembler = this; for (AppInfo appInfo : assembler.getDeployedApplications()) { try { assembler.destroyApplication(appInfo.path); } catch (UndeployException e) { logger.error("Undeployment failed: " + appInfo.path, e); } catch (NoSuchApplicationException e) { } } NamingEnumeration<Binding> namingEnumeration = null; try { namingEnumeration = containerSystem.getJNDIContext().listBindings("openejb/Resource"); } catch (NamingException ignored) { // no resource adapters were created } while (namingEnumeration != null && namingEnumeration.hasMoreElements()) { Binding binding = namingEnumeration.nextElement(); Object object = binding.getObject(); if (object instanceof ResourceAdapter) { ResourceAdapter resourceAdapter = (ResourceAdapter) object; try { logger.info("Stopping ResourceAdapter: " + binding.getName()); if (logger.isDebugEnabled()) { logger.debug("Stopping ResourceAdapter: " + binding.getClassName()); } resourceAdapter.stop(); } catch (Throwable t) { logger.fatal("ResourceAdapter Shutdown Failed: " + binding.getName(), t); } } else if (object instanceof org.apache.commons.dbcp.BasicDataSource) { logger.info("Closing DataSource: " + binding.getName()); try { ((org.apache.commons.dbcp.BasicDataSource) object).close(); } catch (Throwable t) { //Ignore } } else if (logger.isDebugEnabled()) { logger.debug("Not processing resource on destroy: " + binding.getClassName()); } } SystemInstance.get().removeComponent(OpenEjbConfiguration.class); SystemInstance.get().removeComponent(JtaEntityManagerRegistry.class); SystemInstance.get().removeComponent(TransactionSynchronizationRegistry.class); SystemInstance.get().removeComponent(EjbResolver.class); SystemInstance.reset(); }
From source file:org.springframework.ejb.support.JndiEnvironmentBeanDefinitionReader.java
/** * Creates new JNDIBeanFactory// www . j ava 2s .c o m * @param root likely to be "java:comp/env" */ public JndiEnvironmentBeanDefinitionReader(BeanDefinitionRegistry beanFactory, String root) throws BeansException { // We'll take everything from the NamingContext and dump it in a // Properties object, so that the superclass can efficiently manipulate it // after we've closed the context. HashMap m = new HashMap(); Context initCtx = null; try { initCtx = new InitialContext(); // Parameterize NamingEnumeration bindings = initCtx.listBindings(root); // Orion 1.5.2 doesn't seem to regard anything under a / // as a true subcontext, so we need to search all bindings // Not all that fast, but it doesn't matter while (bindings.hasMore()) { Binding binding = (Binding) bindings.next(); logger.debug("Name: " + binding.getName()); logger.debug("Type: " + binding.getClassName()); logger.debug("Value: " + binding.getObject()); m.put(binding.getName(), binding.getObject()); } bindings.close(); PropertiesBeanDefinitionReader propReader = new PropertiesBeanDefinitionReader(beanFactory); propReader.registerBeanDefinitions(m, BEANS_PREFIX); } catch (NamingException ex) { logger.debug("----- NO PROPERTIES FOUND " + ex); } finally { try { if (initCtx != null) { initCtx.close(); } } catch (NamingException ex) { // IGNORE OR THROW RTE? } } }
From source file:org.wso2.carbon.uuf.core.API.java
/** * Returns a map of service implementation class names and instances of all OSGi services for the given service * class name./*from w ww . ja v a 2 s .c om*/ * * @param serviceClassName service class name * @return a map of implementation class and instances */ public static Map<String, Object> getOSGiServices(String serviceClassName) { try { Context context = new InitialContext(); NamingEnumeration<Binding> enumeration = context.listBindings("osgi:service/" + serviceClassName); Map<String, Object> services = new HashMap<>(); while (enumeration.hasMore()) { Binding binding = enumeration.next(); services.put(binding.getClassName(), binding.getObject()); } return services; } catch (NamingException e) { throw new UUFException( "Cannot create the initial context when calling OSGi service '" + serviceClassName + "'."); } }