AEM as a Cloud Service并不直接支持SlingRequestProcessor,但是可以通过Sling Filter实现类似的功能。
下面是一个示例代码,使用Sling Filter替代SlingRequestProcessor:
@Component(
service = Filter.class,
property = {
"sling.filter.scope=request",
"sling.filter.pattern=/content/mysite/*"
}
)
public class CustomFilter implements Filter {
private SlingRequestProcessor requestProcessor;
@Reference
protected void bindRequestProcessor(SlingRequestProcessor requestProcessor) {
this.requestProcessor = requestProcessor;
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
if (slingRequest.getRequestPathInfo().getExtension().equals("html")) {
// do some custom processing
// you can use requestProcessor here to simulate SlingRequestProcessor
}
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// nothing to do here
}
@Override
public void destroy() {
// nothing to do here
}
}
这个示例代码中,我们创建了一个Sling Filter,并注入了SlingRequestProcessor。在doFilter
中,我们检查了请求的后缀是否为html
,如果是,我们可以把请求交给requestProcessor
来进行自定义的处理。
上一篇:AEM安装无需注册
下一篇:AEMAuthor滞缓