CQ5自定义servlet路径

CQ5自定义servlet路径

本文介绍了Adobe CQ5自定义servlet路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为某些节点的json处理添加一些功能。因此,我编写了从 SlingSafeMethodsServlet 扩展的自定义servlet,当用户对以下URL进行GET时,需要执行该自定义servlet: /data/events/any_sequence/any_sequence.json /data/events/any_sequence/any_sequence.infinity.json 或例如 /data/events/any_sequence/any_sequence.2.json ,其中 any_sequence 当然是指任何有效的符号序列。



问题是我无法在吊索文档中找到如何映射此模板(如urls)。



我一直在尝试设置以下属性:

  @Component 
@Service
@Properties({
@Property(name = sling.servlet.resourceTypes,value = data / events /-/-),
@Property( name = sling.servlet.extensions,值= json),
@Property(name = sling.servlet.methods,值= GET),
@Property(name = service.description,值= JSON高级渲染器)
})

但这没有帮助。我检查了felix控制台,发现我的服务已经启动并正在运行,所以问题在于如何设置URL映射。因此,我的问题是在我的情况下如何设置URL映射以调用自定义servlet的doGet吗?



谢谢。

  @Component 
@Service
@Properties({
@Property(name = sling.servlet.resourceTypes,value = sling / servlet / default),
@Property(name = sling.servlet.extensions,值= json),
@Property(名称= sling.servlet.selectors,值=高级),
@Property(名称= sling .servlet.methods,值= GET),
@Property(name = service.description,值= JSON高级渲染器)
})

此代码表示,如果我尝试使用 *。advanced.json 在某个节点上进行GET 选择器和扩展名然后将请求转发到我的自定义servlet。



请参见


I am trying to add some functionality to json processing for some nodes. So I wrote custom servlet extended from SlingSafeMethodsServlet which I need to be executed when user makes GET for the following url : /data/events/any_sequence/any_sequence.json or /data/events/any_sequence/any_sequence.infinity.json or for example /data/events/any_sequence/any_sequence.2.json where any_sequence of course means any valid sequence of symbols.

The problem is that I cannot find in the sling docs how to map this template like urls.

I've been trying to set properties like this:

@Component
@Service
@Properties({
    @Property(name = "sling.servlet.resourceTypes", value = "data/events/-/-"),
    @Property(name = "sling.servlet.extensions", value = "json"),
    @Property(name = "sling.servlet.methods", value = "GET"),
    @Property(name = "service.description", value = "JSON advanced renderer")
})

But it didn't help. I checked felix console and found out that my service had started and running, so the problem is how to set url mappings. So my question is how to set url mapping in my case to invoke doGet of my custom servlet ?

Thanks.

解决方案

As far as I understand CQ5 does not provide ability to map custom servlets on wildcard urls. The only way to accomplish goal similiar to one I needed is to use some unique for this servlet selector like this:

@Component
@Service
@Properties({
    @Property(name = "sling.servlet.resourceTypes", value = "sling/servlet/default"),
    @Property(name = "sling.servlet.extensions", value = "json"),
    @Property(name = "sling.servlet.selectors", value = "advanced"),
    @Property(name = "sling.servlet.methods", value = "GET"),
    @Property(name = "service.description", value = "JSON advanced renderer")
})

This code means that if I'll try to make GET on some node with *.advanced.json selector and extension then request will be forwarded to my custom servlet.

See http://apache-sling.73963.n3.nabble.com/Register-servlet-for-subtree-td84106.html

这篇关于Adobe CQ5自定义servlet路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 02:09