Return non-HTML, non-JSON http bodies in Tapestry 5?

I need to implement an OAuth protocol service provider in a project that uses Tapestry5. So I just need to return a very simple HTTP response body, which is neither HTML nor JSON.

At first I tried using the standard tml and pojo (java class, page) approach, but this does not work because Tapestry is trying to parse the templates.

So I think I need to try something else. Maybe you can use the render () method on the page? But I could not find documentation that could answer this question.

Or should I use a different infrastructure that best suits my needs?

Thank you for your advice,

Richard

+4
source share
2 answers
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"); } 
+4
source

You can transfer 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 did this for a large number of pages, I think you could make your own DocumentLinker, which allows you to bypass all the xml / html / head files that Tapestry adds to the default page. Then you can return to using templates.

+3
source

All Articles