[jboss-cvs] JBossAS SVN: r72783 - trunk/ejb3/src/main/org/jboss/ejb3/client.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 28 08:54:19 EDT 2008


Author: scott.stark at jboss.org
Date: 2008-04-28 08:54:18 -0400 (Mon, 28 Apr 2008)
New Revision: 72783

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
Log:
Dump the client enc on startup for now

Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java	2008-04-28 12:31:31 UTC (rev 72782)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java	2008-04-28 12:54:18 UTC (rev 72783)
@@ -21,12 +21,15 @@
  */
 package org.jboss.ejb3.client;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -35,9 +38,11 @@
 import java.util.Properties;
 
 import javax.naming.Context;
+import javax.naming.LinkRef;
 import javax.naming.NameClassPair;
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
 
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.DependencyPolicy;
@@ -108,13 +113,10 @@
 
       Context ctx = InitialContextFactory.getInitialContext(jndiEnv);
       enc = (Context) ctx.lookup(applicationClientName);
-      log.debug("Client ENC("+applicationClientName+"):");
-      NamingEnumeration<NameClassPair> e = enc.list("");
-      while(e.hasMore())
-      {
-         NameClassPair ncp = e.next();
-         log.debug("  " + ncp);
-      }
+      StringBuffer encInfo = new StringBuffer("Client ENC("+applicationClientName+"):\n");
+      list(enc, "", encInfo, true);
+      log.info(encInfo.toString());
+
       //encEnv = (Context) enc.lookup("env");
 //      enc = ThreadLocalENCFactory.create(ctx);
 //      encEnv = Util.createSubcontext(enc, "env");
@@ -409,4 +411,157 @@
    {
       throw new NotImplementedException();
    }
+
+   /**
+    * Recursively display the naming context information into the buffer.
+    * 
+    * @param ctx
+    * @param indent
+    * @param buffer
+    * @param verbose
+    */
+   private static void list(Context ctx, String indent, StringBuffer buffer,
+         boolean verbose)
+   {
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      try
+      {
+         NamingEnumeration ne = ctx.list("");
+         while (ne.hasMore())
+         {
+            NameClassPair pair = (NameClassPair) ne.next();
+
+            String name = pair.getName();
+            String className = pair.getClassName();
+            boolean recursive = false;
+            boolean isLinkRef = false;
+            boolean isProxy = false;
+            Class c = null;
+            try
+            {
+               c = loader.loadClass(className);
+
+               if (Context.class.isAssignableFrom(c))
+                  recursive = true;
+               if (LinkRef.class.isAssignableFrom(c))
+                  isLinkRef = true;
+
+               isProxy = Proxy.isProxyClass(c);
+            }
+            catch (ClassNotFoundException cnfe)
+            {
+               // If this is a $Proxy* class its a proxy
+               if (className.startsWith("$Proxy"))
+               {
+                  isProxy = true;
+                  // We have to get the class from the binding
+                  try
+                  {
+                     Object p = ctx.lookup(name);
+                     c = p.getClass();
+                  }
+                  catch (NamingException e)
+                  {
+                     Throwable t = e.getRootCause();
+                     if (t instanceof ClassNotFoundException)
+                     {
+                        // Get the class name from the exception msg
+                        String msg = t.getMessage();
+                        if (msg != null)
+                        {
+                           // Reset the class name to the CNFE class
+                           className = msg;
+                        }
+                     }
+                  }
+               }
+            }
+
+            buffer.append(indent + " +- " + name);
+
+            // Display reference targets
+            if (isLinkRef)
+            {
+               // Get the 
+               try
+               {
+                  Object obj = ctx.lookupLink(name);
+
+                  LinkRef link = (LinkRef) obj;
+                  buffer.append("[link -> ");
+                  buffer.append(link.getLinkName());
+                  buffer.append(']');
+               }
+               catch (Throwable t)
+               {
+                  buffer.append("invalid]");
+               }
+            }
+
+            // Display proxy interfaces
+            if (isProxy)
+            {
+               buffer.append(" (proxy: " + pair.getClassName());
+               if (c != null)
+               {
+                  Class[] ifaces = c.getInterfaces();
+                  buffer.append(" implements ");
+                  for (int i = 0; i < ifaces.length; i++)
+                  {
+                     buffer.append(ifaces[i]);
+                     buffer.append(',');
+                  }
+                  buffer.setCharAt(buffer.length() - 1, ')');
+               }
+               else
+               {
+                  buffer.append(" implements " + className + ")");
+               }
+            }
+            else if (verbose)
+            {
+               buffer.append(" (class: " + pair.getClassName() + ")");
+            }
+
+            buffer.append('\n');
+            if (recursive)
+            {
+               try
+               {
+                  Object value = ctx.lookup(name);
+                  if (value instanceof Context)
+                  {
+                     Context subctx = (Context) value;
+                     list(subctx, indent + " |  ", buffer, verbose);
+                  }
+                  else
+                  {
+                     buffer.append(indent + " |   NonContext: " + value);
+                     buffer.append('\n');
+                  }
+               }
+               catch (Throwable t)
+               {
+                  buffer.append("Failed to lookup: " + name + ", errmsg=" + t.getMessage());
+                  buffer.append('\n');
+               }
+            }
+         }
+         ne.close();
+      }
+      catch (NamingException ne)
+      {
+         buffer.append("error while listing context " + ctx.toString() + ": " + ne.toString(true));
+         formatException(buffer, ne);
+      }
+   }
+   private static void formatException(StringBuffer buffer, Throwable t)
+   {
+      StringWriter sw = new StringWriter();
+      PrintWriter pw = new PrintWriter(sw);
+      buffer.append("<pre>\n");
+      t.printStackTrace(pw);
+      buffer.append(sw.toString());
+      buffer.append("</pre>\n");
+   }
 }




More information about the jboss-cvs-commits mailing list