java - ReSTLet 路由不适用于路由中的目录?

标签 java restlet

我在使这些 ReSTLet 服务器资源正常工作时遇到了一些麻烦:

  private static final String ROOT_URI = "/rest/";
  @Override
  public Restlet createInboundRoot() {
    Router router = new Router(getContext());
    Directory directory = new Directory(getContext(), "war:///doc");
    directory.setIndexName("app.html");
    router.attach(ROOT_URI + "files", GaeFilesServerResource.class);
    router.attach(ROOT_URI + "files/{file_id}", GaeFileServerResource.class);
    router.attach("/gwtapp/", directory); // This is the only one that works
    router.attach("/", RootServerResource.class);
    return router;
  }

正如评论中所述,路线/gwtapp/是唯一有效的路线。访问 http://localhost:8080/gwtapp/ 转发到 http://localhost:8080/gwtapp/app.html 这是正确的。

问题是:

我想知道为什么 //rest/ 下的那些在这种情况下不起作用?

最佳答案

解决方案是附加:

router.attachDefault(RootServerResource.class);

相反。

关于java - ReSTLet 路由不适用于路由中的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34598062/

相关文章:

java - 无法分配给没有类型参数的 Function

java - 本地主机上运行的 JVM 列表

java - 如何将 reSTLet 附加到特定的 URL 路径方案(HTTP 或 HTTPS)?

java - 为什么要使用 REST @Produces 注解

apache-camel - 与 camel-jetty 和 camel-servlet 相比,Camel-reSTLet 的性能更好——有什么具体原因吗?

Java Scanner next() 扫描空 token

java - 检查控制台是否支持 Java 中的 ANSI 转义码

java - ReSTLet 错误。无法运行以下服务器端任务 httpserver.serverimpl

java - 如何在ReSTLet的ServerResource方法中请求另一个api作为客户端

java - Maven插件开发: is there a way to automatically run plugin when it's just declared in pom. xml?