better logging for rest endpoints deployed from application

git-svn-id: https://svn.apache.org/repos/asf/openejb/trunk@1429599 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/openejb/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java b/openejb/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
index 514c7c1..b5ded24 100644
--- a/openejb/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
+++ b/openejb/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
@@ -55,6 +55,9 @@
 import javax.ws.rs.core.Application;
 import javax.xml.bind.Marshaller;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -258,6 +261,9 @@
         }
         destination = (AbstractHTTPDestination) server.getDestination();
 
+        LOGGER.info("REST Application: " + prefix + "  -> " + application.getClass().getName());
+
+        final String base = prefix.substring(0, prefix.length() - wildcard.length());
         final JAXRSServiceImpl service = (JAXRSServiceImpl) factory.getServiceFactory().getService();
         final List<ClassResourceInfo> resources = service.getClassResourceInfos();
         for (final ClassResourceInfo info : resources) {
@@ -265,24 +271,83 @@
                 continue;
             }
 
-            final String address = singleSlash(prefix.substring(0, prefix.length() - wildcard.length()), info.getURITemplate().getValue());
+            final String address = singleSlash(base, info.getURITemplate().getValue());
 
             String clazz = info.getResourceClass().getName();
             if (restEjbs.containsKey(clazz)) {
-                LOGGER.info("REST EJB[" + clazz + "]  -> " + address);
+                LOGGER.info("    Service URI: " + address + " -> EJB " + clazz);
             } else {
-                LOGGER.info("REST Pojo[" + clazz + "]  -> " + address);
+                LOGGER.info("    Service URI: " + address + " -> Pojo " + clazz);
             }
 
-            clazz = info.getResourceClass().getSimpleName(); // the qualified name is already printed just make it clearer
             final MethodDispatcher md = info.getMethodDispatcher();
             for (OperationResourceInfo ori : md.getOperationResourceInfos()) {
-                LOGGER.info("     -> Method[" + clazz + "#" + ori.getMethodToInvoke().getName() + "]"
-                        + "  -> " + ori.getHttpMethod() + " " + singleSlash(address, ori.getURITemplate().getValue()));
+                LOGGER.info("        "
+                        + forceLength(ori.getHttpMethod(), 7) + " " + singleSlash(address, ori.getURITemplate().getValue())
+                        + "-> " + toGenericString(ori.getMethodToInvoke()));
             }
         }
     }
 
+    private static String forceLength(final String httpMethod, final int l) {
+        final StringBuilder builder = new StringBuilder();
+        for (int i = 0; i < l - httpMethod.length(); i++) {
+            builder.append(" ");
+        }
+        return builder.append(httpMethod).toString();
+    }
+
+    public static String toGenericString(final Method mtd) {
+        try {
+            final StringBuilder sb = new StringBuilder();
+            final Type[] typeparms = mtd.getTypeParameters();
+            if (typeparms.length > 0) {
+                boolean first = true;
+                sb.append("<");
+                for(Type typeparm: typeparms) {
+                    if (!first)
+                        sb.append(",");
+                    if (typeparm instanceof Class)
+                        sb.append(((Class)typeparm).getSimpleName());
+                    else
+                        sb.append(typeparm.toString().replace("java.lang.", ""));
+                    first = false;
+                }
+                sb.append("> ");
+            }
+
+            final Type genRetType = mtd.getGenericReturnType();
+            sb.append((genRetType instanceof Class) ?
+                    ((Class) genRetType).getSimpleName()
+                    : genRetType.toString().replace("java.lang.", "")).append(" ");
+
+            sb.append(mtd.getName()).append("(");
+            final Type[] params = mtd.getGenericParameterTypes();
+            for (int j = 0; j < params.length; j++) {
+                sb.append((params[j] instanceof Class)?
+                        ((Class)params[j]).getSimpleName():
+                        (params[j].toString()) );
+                if (j < (params.length - 1))
+                    sb.append(",");
+            }
+            sb.append(")");
+            final Type[] exceptions = mtd.getGenericExceptionTypes();
+            if (exceptions.length > 0) {
+                sb.append(" throws ");
+                for (int k = 0; k < exceptions.length; k++) {
+                    sb.append((exceptions[k] instanceof Class)?
+                            ((Class)exceptions[k]).getName():
+                            exceptions[k].toString());
+                    if (k < (exceptions.length - 1))
+                        sb.append(",");
+                }
+            }
+            return sb.toString();
+        } catch (Exception e) {
+            return "<" + e + ">";
+        }
+    }
+
     private static String singleSlash(final String address, final String value) {
         if (address.endsWith("/") && value.startsWith("/")) {
             return address + value.substring(1);
diff --git a/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java b/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
index 67111eb..1e7df77 100644
--- a/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
+++ b/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
@@ -385,8 +385,6 @@
         listener.deployApplication(application, address.complete, nopath.substring(NOPATH_PREFIX.length(), nopath.length() - wildcard.length()), additionalProviders, restEjbs, // app config
                 classLoader, injections, context, owbCtx, // injection/webapp context
                 new ServiceConfiguration(configuration, appInfo.services)); // deployment config
-
-        LOGGER.info("REST Application: " + address.complete + "  -> " + application.getClass().getName());
     }
 
     private static String appPrefix(final WebAppInfo info, final Class<?> appClazz) {