【问题标题】:Filtering ROOT path with Restlet and GAE使用 Restlet 和 GAE 过滤 ROOT 路径
【发布时间】:2015-02-10 21:21:53
【问题描述】:

我有这段代码需要能够在访问ROOT_URI 时触发 MyFilter:

private static final String ROOT_URI = "/";
private static final String ROOT_REST_URI = "/rest/";

@Override
public Restlet createInboundRoot() {
    Guice.createInjector(new GuiceConfigModule(this.getContext()),
            new SelfInjectingServerResourceModule());

    Router router = new Router(getContext());

    router.attach(ROOT_URI + "{id}", new GaeRedirector(getContext(), "{id}"));
    router.attach(ROOT_REST_URI, GaeRootServerResource.class);

    MyFilter mFilter = new MyFilter(getContext());
    MyFilter.setNext(router);

    return mFilter;
}

MyFilter 仅在访问 ROOT_REST_URI 时触发。 Restlet 团队已经通过邮件组建议我需要先将路由放入 ROOT_URI。

问题是,

  • ROOT_URI 不在路由中,因为在 web.xml 中,welcome-file 设置指向 index.html。因此,当访问http://localhost:8080/ 时,它会返回 index.html 页面。

我也尝试添加(作为到 ROOT_URI 的路由以使 MyFilter 在 ROOT_URI 上工作):

Directory directory = new Directory(getContext(), "war:///doc");
router.attach(ROOT_URI, directory);

但是,此目录路由不适用于 GAE。似乎它根本没有触发。使用此目录代码访问http://localhost:8080/,仍然会显示 index.html,并且不会触发 MyFilter

现在,如果我删除 web.xml 中的 <welcome-file>。 MyFilter 被触发,但 index.html 现在无法显示。除非通过在请求中明确添加/index.html

这种情况可能有什么解决方案?

【问题讨论】:

    标签: java google-app-engine restlet


    【解决方案1】:

    我会尝试将目录的默认索引名称设置如下:

    Directory directory = new Directory(getContext(), "war:///doc");
    directory.setIndexName("index.html");
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-24
    • 2011-07-01
    • 1970-01-01
    • 2023-03-06
    • 2016-04-18
    • 2013-10-24
    • 1970-01-01
    相关资源
    最近更新 更多