我有这个代码,我需要能够在访问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;
}
只有在访问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
添加到请求中。
这种情况可能有什么解决方案?
答案 0 :(得分:1)
我会尝试设置目录的默认索引名称,如下所示:
Directory directory = new Directory(getContext(), "war:///doc");
directory.setIndexName("index.html");