1

所以,我正在研究 CQ5。我想将捆绑的组件部署为服务,以过滤和修改 .inifinity.json 输出(来自 sling)到 CQ5。

我能够构建和部署,并且组件和捆绑包都处于活动状态。但是,当页面或调用 infinity.json 时,我在日志中看不到输出。我怀疑是因为服务没有正确安装?或其他一些服务在运行我的服务之前返回呼叫?没有把握。这是我的代码:

package com.my.test;
import javax.servlet.*;
import java.io.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import aQute.bnd.annotation.component.*;



@Component(
        provide=Filter.class,
        immediate=true
)
public class TestFilter implements Filter {

    private static final Logger LOGGER = LoggerFactory.getLogger(TestFilter.class);
    private FilterConfig filterConfig;

    public void init (FilterConfig filterConfig)  {
        LOGGER.info ("INIT .");
        this.setFilterConfig(filterConfig);
    }


    public void destroy() {
        LOGGER.info ("Destroy me NOW!!...");
    }


    public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain){
        try
        {
            LOGGER.info ("Within Simple Filter ... :) ");
            LOGGER.info  ("Filtering the Request ...");

          chain.doFilter (request, response);

          LOGGER.info ("Within Simple Filter ... ");
          LOGGER.info ("Filtering the Response ...");

        } catch (IOException io) {
            LOGGER.info ("IOException raised in SimpleFilter");
        } catch (ServletException se) {
            LOGGER.info  ("ServletException raised in SimpleFilter");
        }
    }

    public FilterConfig getFilterConfig() {
        return this.filterConfig;
    }

    public void setFilterConfig (FilterConfig filterConfig){
        this.filterConfig = filterConfig;
    }

}

我在注释中遗漏了什么吗?或者我应该做的任何事情?

4

2 回答 2

1

查看此处此处的讨论线程,您似乎需要添加注释来设置sling.filter.scope @Property,并且还需要声明 @Service。

像这样的东西:

@Component(
    provide=Filter.class,
    immediate=true
    )
@Service(javax.servlet.Filter.class)
@Properties({
    @Property(name = "sling.filter.scope", value = "request") 
    })
于 2012-10-11T14:17:44.243 回答
1

Sling 集成测试服务源代码在 [1] 处包含一些过滤器,您可以将其用作示例。正如大卫所说,您可能只是缺少 @Service 注释。

http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/

于 2012-10-12T07:05:51.553 回答