是否可以将变量放置在sling servlet内的资源路径中? [英] Is it possible to place variables into a resource path within a sling servlet?

查看:80
本文介绍了是否可以将变量放置在sling servlet内的资源路径中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试为外部端点提供一个干净的URI结构,以从CQ5中提取json信息。

We are trying to provide a clean URI structure for external endpoints to pull json information from CQ5.

例如,如果您要获取有关特定用户的信息历史记录(假设您具有权限等),理想情况下,我们希望端点能够执行以下操作:

For example, if you want to fetch information about a particular users history (assuming you have permissions etc), ideally we would like the endpoint to be able to do the following:

/ bin / api / user / abc123 / phone / 555 -klondike-5 / history.json

/bin/api/user/abc123/phone/555-klondike-5/history.json

在URI中,我们将指定/bin/api/user/{username}/phone/{phoneNumber}/history.json因此,很容易利用调度程序来使缓存更改等无效而又不会使大量缓存的信息无效。

In the URI, we would specifying /bin/api/user/{username}/phone/{phoneNumber}/history.json so that it is very easy to leverage the dispatcher to invalidate caching changes etc without invalidating a broad swath of cached information.

我们想使用一个吊索servlet来处理请求,但是,我不知道如何将变量放入路径。

We would like to use a sling servlet to handle the request, however, I am not aware as to how to put variables into the path.

如果有来自JaxRS的@PathParam之类的东西添加到吊索路径变量中,那会很好,但我怀疑它不可用。

It would be great if there were something like @PathParam from JaxRS to add to the sling path variable, but I suspect it's not available.

我们想到的另一种方法是使用选择器来识别访问api的时间,因此可以从路径中返回我们想要的任何内容,但这需要使用单数吊索servlet来实现。处理所有请求,因此我对该方法不满意,因为它将很多无关的代码粘合在一起。

The other approach we had in mind was to use a selector to recognise when we are accessing the api, and thus could return whatever we wanted to from the path, but it would necessitate a singular sling servlet to handle all of the requests, and so I am not happy about the approach as it glues a lot of unrelated code together.

任何对此的帮助将不胜感激。

Any help with this would be appreciated.

更新:

如果我们要使用OptingServlet,则在accepts函数中放入一些逻辑,我们可以堆叠一系列吊索servlet,并使用正则表达式从路径中做出接受决定。

If we were to use a OptingServlet, then put some logic inside the accepts function, we could stack a series of sling servlets on and make the acceptance decisions from the path with a regex.

然后在执行过程中,路径

Then during execution, the path itself can be parsed for the variables.

推荐答案

现在可以将jersy(JAX-RS)与CQ集成在一起。我们能够创建原始原型,向世界说你好。

It is now possible to integrate jersy(JAX-RS) with CQ. We are able to create primitive prototype to say "Hello" to the world.

https://github.com/hstaudacher/osgi-jax-rs-connector

有了这个,我们可以使用@PathParam映射请求

With this we can use the @PathParam to map the requests

感谢和问候,
San

Thanks and Regards, San

这篇关于是否可以将变量放置在sling servlet内的资源路径中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆