Showing a .txt or .xml file in tapestry 5

169 views Asked by At

I recently started working with tapestry. I have a text file named robots.txt, in src/main/resources in my tapestry app.

I want the file to be shown when I type the URL : localhost:8080/robots.txt.

How do I do this ?

1

There are 1 answers

3
lance-java On BEST ANSWER

You could use an Index page in the root of your application

package foo.bar.mybasepackage.pages;

public class Index {
    public Object onActivate(EventContext context) {
        if (context.getCount() == 1
                && "robots.txt".equals(context.get(String.class, 0)) {

           return getRobotsTxt();
        }
        if (context.getCount() != 0) {
           return new HttpError(404, "Not found");
        }
        return this;
    }

    private StreamResponse getRobotsTxt() {
        return new TextStreamResponse(...);
    }
}