<%@ page import=" org.apache.openejb.BeanType, org.apache.openejb.DeploymentInfo, org.apache.openejb.loader.SystemInstance, org.apache.openejb.spi.ContainerSystem, javax.naming.Context, javax.naming.InitialContext "%> <%@ page import="javax.servlet.http.HttpSession" %> <%@ page import="java.io.IOException" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.Properties" %> <%@ page import="java.lang.reflect.Field" %> <%@ page import="java.lang.reflect.Method" %> OpenEJB/Tomcat
OpenEJBIndexJNDIEJBClassInvoke
   



OpenEJB Enterprise JavaBeans Viewer

<% try{ String ejb = request.getParameter("ejb"); if (ejb == null) { out.print("No EJB specified"); } else { printEjb(ejb,out, session); } } catch (Exception e){ out.println("FAIL: "); out.print(e.getMessage()); throw e; //return; } %>


 
<%! private DeploymentInfo getDeployment(String id, javax.servlet.jsp.JspWriter out) { // due to crazy class loader stuff, we need to use reflection try { Class clazz = getClass().getClassLoader().getParent().getParent().loadClass("org.apache.openejb.loader.SystemInstance"); // out.print("clazz=" + clazz + "

"); // out.print("resource=" + clazz.getClassLoader().getResource("") + "

"); Method getMethod = clazz.getMethod("get", new Class[0]); // out.print("getMethod=" + getMethod + "

"); Object systemInstance = getMethod.invoke(null, new Object[0]); // out.print("systemInstance=" + systemInstance + "

"); Method getComponentMethod = clazz.getMethod("getComponent", new Class[]{Class.class}); // out.print("getComponentMethod=" + getComponentMethod + "

"); // Field field = clazz.getDeclaredField("components"); // field.setAccessible(true); // Object components = field.get(systemInstance); // out.print("components=" + components + "

"); ContainerSystem containerSystem = (ContainerSystem) getComponentMethod.invoke(systemInstance, new Object[]{ContainerSystem.class}); // out.print("containerSystem=" + containerSystem + "

"); if (containerSystem == null) { return null; } DeploymentInfo ejb = containerSystem.getDeploymentInfo(id); // out.print("ejb=" + ejb + "

"); return ejb; } catch (Exception e) { return null; } } String tab = "    "; public void printEjb(String name, javax.servlet.jsp.JspWriter out, HttpSession session) throws Exception { String id = (name.startsWith("/")) ? name.substring(1, name.length()) : name; DeploymentInfo ejb = getDeployment(id, out); if (ejb == null) { out.print("No such EJB: " + id); return; } String type = null; BeanType beanType = ejb.getComponentType(); if (beanType == BeanType.CMP_ENTITY) { type = "EntityBean with Container-Managed Persistence"; } else if (beanType == BeanType.BMP_ENTITY) { type = "EntityBean with Bean-Managed Persistence"; } else if (beanType == BeanType.STATEFUL) { type = "Stateful SessionBean"; } else if (beanType == BeanType.STATELESS) { type = "Stateless SessionBean"; } else { type = "Unkown Bean Type"; } out.print("" + type + "
"); out.print(""); printRow("JNDI Name", name, out); printRow("Remote Interface", getClassRef(ejb.getRemoteInterface()), out); printRow("Home Interface", getClassRef(ejb.getHomeInterface()), out); printRow("Bean Class", getClassRef(ejb.getBeanClass()), out); if (ejb.getComponentType() == BeanType.BMP_ENTITY || ejb.getComponentType() == BeanType.CMP_ENTITY) { printRow("Primary Key", getClassRef(ejb.getPrimaryKeyClass()), out); } String pepperImg = ""; out.print("
"); out.print("

Actions:
"); out.print(""); // Browse JNDI with this ejb //javax.servlet.http.HttpSession session = this.session; //noinspection unchecked Map objects = (Map) session.getAttribute("objects"); if (objects == null) { objects = new HashMap(); session.setAttribute("objects", objects); } InitialContext ctx; Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); p.put("openejb.loader", "embed"); ctx = new InitialContext(p); Object obj = ctx.lookup(name); String objID = ejb.getHomeInterface().getName() + "@" + obj.hashCode(); objects.put(objID, obj); String invokerURL = "Invoke this EJB"; printRow(pepperImg, invokerURL, out); Context enc = ejb.getJndiEnc(); String ctxID = "enc" + enc.hashCode(); session.setAttribute(ctxID, enc); String jndiURL = "Browse this EJB's private JNDI namespace"; printRow(pepperImg, jndiURL, out); out.print("
"); } protected void printRow(String col1, String col2, javax.servlet.jsp.JspWriter out) throws IOException { out.print(""); out.print(col1); out.print(""); out.print(col2); out.print(""); } public String getClassRef(Class clazz) throws Exception { String name = clazz.getName(); return "" + name + ""; } public String getShortClassRef(Class clazz) throws Exception { if (clazz.isPrimitive()) { return "" + clazz.getName() + ""; } else if (clazz.isArray() && clazz.getComponentType().isPrimitive()) { return "" + clazz.getComponentType() + "[]"; } else if (clazz.isArray()) { String name = clazz.getComponentType().getName(); int dot = name.lastIndexOf(".") + 1; String shortName = name.substring(dot, name.length()); return "" + shortName + "[]"; } else { String name = clazz.getName(); int dot = name.lastIndexOf(".") + 1; String shortName = name.substring(dot, name.length()); return "" + shortName + ""; } } %>