【问题标题】:Restlet get remaining path when Router uses MODE_STARTS_WITH当路由器使用 MODE_STARTS_WITH 时,Restlet 获取剩余路径
【发布时间】:2018-04-07 20:18:54
【问题描述】:

我正在创建一个基于Restlet 的服务,该服务将传入请求与特定初始路径相匹配。在处理匹配的 ServerResource 中,我想访问剩余路径。

Router parentRouter;
parentRouter.attach("/svc/", new MyService());
parentRouter.attach("/svc/1.0/", new MyService());

public class MyService extends Router
{
  public MetricsService()
  {
    attach("/m/", MyResource.class).setMatchingMode(Template.MODE_STARTS_WITH);
  }
}

public class MyResource extends ServerResource 
{
  @Override
  protected void doInit() throws ResourceException
  {
     String remainingPath = ???   <-- how do I do this?
  }
  @Get
  protected void doit() throws ResourceException
  {
    ...
  }
}

现在例如以下请求会导致以下剩余路径:

http://localhost/svc/m/                  -->  ""
http://localhost/svc/m/a                 -->  "a"
http://localhost/svc/v1.0/m/some/m/path  --> "some/m/path"

当然,总有一些变通方法可以解决此问题,但使用现有的 Restlet 框架检索此问题可能更优雅。特别是因为路由器已经知道剩余的路径。

任何帮助或建议表示赞赏。

【问题讨论】:

    标签: java restlet


    【解决方案1】:

    经过一番折腾,我找到了答案:

    @Override
    protected void doInit() throws ResourceException
    {
       String remainingPath = getReference().getRemainingPart();
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-04
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 2016-04-13
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 2018-03-11
      相关资源
      最近更新 更多