繁体   English   中英

用Restlet和GAE过滤ROOT路径

[英]Filtering ROOT path with Restlet and GAE

我有这样的代码,我需要能够触发MyFilter时ROOT_URI访问:

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;
}

仅当访问ROOT_REST_URI时才触发MyFilter。 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添加到请求中。

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

我将尝试为目录设置默认索引名称,如下所示:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM