Search code examples
javagoogle-app-enginerestlet

Filtering ROOT path with Restlet and GAE


I have this code that I need to be able to trigger the MyFilter when ROOT_URI is accessed:

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

The MyFilter is only triggered when ROOT_REST_URI is accessed. Restlet team already advised through mail group that I need to put a routing into the ROOT_URI first.

The question is,

  • the ROOT_URI is not in the routing because in the web.xml, a welcome-file setting is there pointing to index.html. So when http://localhost:8080/ is accessed it returns the index.html page.

I have also tried adding (as a routing to ROOT_URI to make MyFilter work on ROOT_URI):

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

Yet, this Directory routing would not work with GAE. It seems it does not trigger at all. accessing the http://localhost:8080/ with this Directory code in place, still the index.html is shown and no MyFilter is triggered.

Now if I remove the <welcome-file> in web.xml. The MyFilter gets triggered but the index.html cannot be shown now. Unless explicitly through adding /index.html to the request.

What solution there may be for this scenario?


Solution

  • I would try to set the default index name for the directory as follow:

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