如何跟踪Struts2 Web应用程序运行的所有方法?

raj*_*aja -3 java eclipse debugging struts struts2

我需要对其他开发人员编写的Java-EE Struts2 Web应用程序进行一些更改.

由于我不确切知道它是如何工作的,因此我想映射每个请求上调用的所有操作和方法,以便在更改之前更好地理解Web应用程序工作流.

有没有办法实现这个目标?

And*_*ios 6

采用以下一种(或多种)方法:

  1. 查看struts.xml,了解配置元素(特别Actionsmethods)如何映射以及如何在编译时重现应用程序的行为.

  2. 编写一个Interceptor记录(或保存某处)在Stack中传递的所有Actions和方法的名称,从请求中读取它们;

  3. 实现Preparable Interface并从prepare()方法中执行请求记录;

  4. 动态获取类名和方法名

    Thread.currentThread().getStackTrace()[level].getMethodName();
    
    Run Code Online (Sandbox Code Playgroud)

    根据应用程序的结构,您可以选择将此行的调用"放在某处",以记录所有调用的类名和方法.

    我建议你这个实现,它解决了你的深度问题:

    public class Utilities {
        public static String getCurrentMethod() {
            return getCurrentMethodNameFromThread(0);
        }
    
        public static String getCallingMethodName() {
            return getCurrentMethodNameFromThread(1);
        }
    
        private static String getCurrentMethodNameFromThread(int stackLevel) {
            /*
             * 0 - dumpThreads
             * 1 - getStackTrace
             * 2 - thisMethod => getCurrentMethodNameFromThread
             * 3 - callingMethod => method calling thisMethod 
             * 4 - method calling callingMethod
             */
            StackTraceElement 
                stackTraceElement = 
                    Thread.currentThread().getStackTrace()[4 + stackLevel];
    
            String className = stackTraceElement.getClassName();
            String methodName = stackTraceElement.getMethodName();
    
            return className + "." + methodName;
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

  • @zzzz,你可以在这里解释你对这个问题的错误删除和假编辑吗?答案http://meta.stackexchange.com/questions/189115/the-strange-case-of-dr-upvoter-and-mr - 编辑?谢谢 (11认同)