<% out.print(""); %> <%@ page import=" org.apache.openejb.BeanType, org.apache.openejb.BeanContext, org.apache.openejb.loader.SystemInstance, org.apache.openejb.spi.ContainerSystem, javax.naming.Context, javax.naming.InitialContext "%> <%@ page import="javax.servlet.http.HttpServletRequest" %> <%@ 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.List" %> <%@ page import="java.util.Properties" %> <%@ page import="java.lang.reflect.Field" %> <%@ page import="java.lang.reflect.Method" %> TomEE
<% try{ String ejb = request.getParameter("ejb"); String jndiName = request.getParameter("jndiName"); String contextID = request.getParameter("ctxID"); if (ejb == null) { out.print("

No EJB specified

"); } else { printEjb(ejb,jndiName,contextID,out, session); } } catch (Exception e){ out.println("

FAIL:
"); out.print(e.getMessage() + "

"); throw e; //return; } %>

<%! private BeanContext getDeployment(String deploymentID) { try { ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); BeanContext ejb = containerSystem.getBeanContext(deploymentID); return ejb; } catch (Exception e) { return null; } } public void printEjb(String name,String jndiName, String contextID, javax.servlet.jsp.JspWriter out, HttpSession session) throws Exception { String id = (name.startsWith("/")) ? name.substring(1, name.length()) : name; BeanContext ejb = getDeployment(id); if (ejb == null) { out.print("

No such EJB: " + id + "

"); return; } String type = null; switch (ejb.getComponentType()) { case CMP_ENTITY: type = "EntityBean with Container-Managed Persistence"; break; case BMP_ENTITY: type = "EntityBean with Bean-Managed Persistence"; break; case STATEFUL: type = "Stateful SessionBean"; break; case STATELESS: type = "Stateless SessionBean"; break; case SINGLETON: type = "Singleton SessionBean"; break; case MANAGED: type = "Managed SessionBean"; break; default: type = "Unkown Bean Type"; break; } out.print("

" + type + "

"); out.print(""); printRow("JNDI Name", jndiName, out); if(ejb.getRemoteInterface() != null) printRow("Remote Interface", getClassRef(ejb.getRemoteInterface(),session), out); if(ejb.getHomeInterface() != null) printRow("Home Interface", getClassRef(ejb.getHomeInterface(),session), out); if(ejb.getBeanClass() != null) printRow("Bean Class", getClassRef(ejb.getBeanClass(),session), out); if(ejb.getBusinessLocalInterfaces().size() > 0) printRow("Business Local Interfaces", getClassRefs(ejb.getBusinessLocalInterfaces(),session), out); if(ejb.getBusinessRemoteInterfaces().size() > 0) printRow("Business Remote Interfaces", getClassRefs(ejb.getBusinessRemoteInterfaces(),session), out); if (ejb.getComponentType() == BeanType.BMP_ENTITY || ejb.getComponentType() == BeanType.CMP_ENTITY) { printRow("Primary Key", getClassRef(ejb.getPrimaryKeyClass(),session), out); } out.print("
"); // Browse JNDI with this ejb //javax.servlet.http.HttpSession session = this.session; //noinspection unchecked Map objects = (Map) session.getAttribute("objects"); Context ctx; if(contextID == null){ Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); p.put("openejb.loader", "embed"); ctx = new InitialContext(p); }else{ ctx = (Context)session.getAttribute(contextID); } Object obj = ctx.lookup(jndiName); // String objID = ejb.getHomeInterface().getName() + "@" + obj.hashCode(); String objID = ""+obj.hashCode(); //TODO: Not the best of the ID's, more meaningful ID would be better. Right now hashcode would suffice objects.put(objID, obj); String invokeURL = "Invoke this EJB"; Context enc = ejb.getJndiEnc(); String ctxID = "enc" + enc.hashCode(); session.setAttribute(ctxID, enc); String jndiURL = "Browse this EJB's private JNDI namespace"; out.print("
" + invokeURL + jndiURL + "
"); } protected void printRow(String col1, String col2, javax.servlet.jsp.JspWriter out) throws IOException { out.print(""); out.print("" + col1 + ""); out.print("" + col2 + ""); out.print(""); } public String getClassRef(Class clazz, HttpSession session) throws Exception { String name = clazz.getName(); session.setAttribute(name,clazz); return "" + name + ""; } public String getClassRefs(List classes, HttpSession session) throws Exception{ String refs = ""; for(Class clazz: classes){ refs += getClassRef(clazz,session)+"
"; } return refs; } %>