在 Restlet 中获取应用程序的路径(上下文根)
我需要在 Restlet 资源类中获取应用程序根(它扩展了 ServerResource)。我的最终目标是尝试返回到另一个资源的完整显式路径。
我目前正在使用 getRequest().getResourceRef().getPath() 这几乎满足了我的需要。这不会返回完整的 URL(例如 http://example.com/app
),而是返回给我 /resourceName。因此,我遇到了两个问题,一个是它缺少架构(http 或 https 部分)和服务器名称,另一个是它不返回应用程序安装到的位置。
因此,在 'http://dev.example.com/app_name/person 处提供人员资源',我想找到一种方法来返回 'http://dev.example.com/app_name'。
我正在使用 Restlet 2.0 RC3 并将其部署到 GAE。
I am needing to get the application root within a Restlet resource class (it extends ServerResource). My end goal is trying to return a full explicit path to another Resource.
I am currently using getRequest().getResourceRef().getPath()
and this almost gets me what I need. This does not return the full URL (like http://example.com/app
), it returns to me /resourceName. So two problems I'm having with that, one is it is missing the schema (the http or https part) and server name, the other is it does not return where the application has been mounted to.
So given a person resource at 'http://dev.example.com/app_name/person', I would like to find a way to get back 'http://dev.example.com/app_name'.
I am using Restlet 2.0 RC3 and deploying it to GAE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来
getRequest().getRootRef().toString()
给了我我想要的东西。我尝试使用getRequest().getRootRef()
的方法调用组合(例如 getPath 或 getRelativePart),但它们要么给了我一些我想要的东西不想要或无效。It looks like
getRequest().getRootRef().toString()
gives me what I want. I tried using a combination of method calls ofgetRequest().getRootRef()
(like getPath or getRelativePart) but either they gave me something I didn't want or null.只需从服务上下文中获取基本 url,然后与资源共享并根据需要添加资源路径。
Just get the base url from service context, then share it with the resources and add resource path if needed.
request.getRootRef()
还是request.getHostRef()
?request.getRootRef()
orrequest.getHostRef()
?Servlet 的上下文可以从 Restlet 的应用程序访问:
The servlet's context is accessible from the restlet's application: