views:

25

answers:

2

Hi,

I have to implement the service provider of the OAuth protocol in a project that uses Tapestry5. Therefor I just need to return a very simple HTTP response body that is neither HTML or JSON.

At first I tried to use the standard tml & pojo (java class, page) approach but this doesn't work because Tapestry tries to parse the templates.

So I think I have to try something different. Maybe it is possible to use a render() method in a page? But I couldn't find any documentation that would answer this question.

Or should I just use another framework that would better fit my needs?

Thank you for your advice,

Richard

+1  A: 

You can stream text directly from the page without using a template:

StreamResponse onActivate() {
  return new StreamResponse(
    public String getContentType() {
      return "text/plain";
    }

    public InputStream getStream() {
      return new ByteArrayInputStream("foo=bar".getBytes());
    }

    public void prepareResponse(Response response) {
      // response.setHeader(...
    }
}

If you were doing it for a lot of pages, I think you could contribute your own DocumentLinker that lets you bypass all the xml/html/head stuff that Tapestry adds to the page by default. Then you could go back to using templates.

Brian Deterling
Thank you so for hinting me in the right direction. My solution was even simpler.
Richard Metzler
Good catch - I didn't know about TextStreamResponse.
Brian Deterling
+2  A: 

Brian pushed me in the right direction, but the actual solution to the problem was even simpler:

StreamResponse onActivate() {
     return new TextStreamResponse("text/plain", "foo=bar");
}
Richard Metzler