【问题标题】:Log all request from flex / BlazeDS client using filter使用过滤器记录来自 flex / BlazeDS 客户端的所有请求
【发布时间】:2011-12-06 08:17:42
【问题描述】:

我有一个 Spring BlazeDS 集成应用程序。我想记录所有请求。

我打算使用过滤器。当我检查请求参数时,在我的过滤器中。它不包含与客户端请求相关的任何内容。如果我更改过滤器的顺序(我有 spring 安全性),那么它会打印一些与 spring 安全性相关的内容。

我无法记录用户请求。

感谢任何帮助。

【问题讨论】:

    标签: apache-flex spring filter request blazeds


    【解决方案1】:

    我通过使用 AOP (AspectJ) 将记录器语句注入通信端点方法来完成相同的功能。 -- 这对你来说也是一种替代方法。


    /** Logger advice and pointcuts for flex remoting stuff based on aspect J*/
    public aspect AspectJInvocationLoggerAspect {
    
        /** The name of the used logger. */
        public final static String LOGGER_NAME = "myPackage.FLEX_INVOCATION_LOGGER";
    
        /** Logger used to log messages. */
        private static final Logger LOGGER = Logger.getLogger(LOGGER_NAME);
    
        AspectJInvocationLoggerAspect() {
        }
    
        /**
         * Pointcut for all flex remoting methods.
         * 
         * Flex remoting methods are determined by two constraints:
         * <ul>
         *   <li>they are public</li>
         *   <li>the are located in a class of name Remoting* within (implement an interface)
         *   {@link com.example.remote} package</li>
         *   <li>they are located within a class with an {@link RemotingDestination} annotation</li>
         * </ul>
         */
        pointcut remotingServiceFunction()
            : (execution(public * com.example.remote.*.*Remote*.*(..)))  
            && (within(@RemotingDestination *));
    
        before() : remotingServiceFunction() {
            if (LOGGER.isDebugEnabled()) {
                Signature sig = thisJoinPointStaticPart.getSignature();
                Object[] args = thisJoinPoint.getArgs();
    
                String location = sig.getDeclaringTypeName() + '.' + sig.getName() + ", args=" + Arrays.toString(args);            
                LOGGER.debug(location + " - begin");
            }
        }
    
        /** Log flex invocation result at TRACE level. */
        after() returning (Object result): remotingServiceFunction() {
    
            if (LOGGER.isTraceEnabled()) {
                Signature sig = thisJoinPointStaticPart.getSignature();            
    
                String location = sig.getDeclaringTypeName() + '.' + sig.getName();
                LOGGER.trace(location + " - end = " + result);            
            }
        }
    }
    

    【讨论】:

    • 嗨,选择过滤器的原因是我想处理所有类型的客户端,MVC 和 flex。我用谷歌搜索了很多,我能找到的最近的是spltech.co.uk/blog/struts-2/… 但是如果我找不到使用过滤器的干净灵魂,那么我必须切换到拦截器或 AOP 。那么,您能否就如何使用 AOP 做同样的事情提出一些要点或链接。
    • @user1057094:我添加了一个示例
    • 感谢您的示例。我会试一试。但我仍然想知道,如何使用过滤器来做到这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 2014-11-05
    • 2014-09-19
    • 2021-06-23
    • 2013-07-02
    • 1970-01-01
    相关资源
    最近更新 更多