Currently i am developing a pluggable Webapplication with virgo-server and virgo snaps. Therefore i would like to implement some kind of templating where the
host provides a general layout. If a snap is called the snap should integrate its output in the hosts template.
My approach so far is to use a filter which wrapps html around the response of every snap. My problem is that the filter that i have defined after the SnapHostFilter in the web.xml is not executed.
If i define my filter before the SnapHostFilter it gets executed but then the actual response to the client only contains the wrapping-html but not the output from the snap.
Does anybody have an idea why it is not working? or how i could implement some kind of templating that is controlled by the host?
Thanks very much
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
OutputStream out = response.getOutputStream();
out.write("<HR>PRE<HR>".getBytes());
GenericResponseWrapper wrapper = new GenericResponseWrapper((HttpServletResponse) response);
chain.doFilter(request,wrapper);
out.write(wrapper.getData());
//out.write("<HR>POST<HR>".getBytes());
out.close();
}
Chris Frost Messages: 222 Registered: January 2010 Location: Southampton, England
Senior Member
If you look at the 'animals' sample application that comes with Snaps it does what you're looking for but in a different way. It uses JSPs to import a header and footer file from the host to all of the Snaps JSP files. I can't see anything obvious wrong with your web.xml but I also don't know much about their syntax. Should the template and host filters not have the same mapping to ensure that all content from snaps gets wrapped.
Hope that is of some help.
Chris.
------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
@ Chris Frost
I had alread checked out the animal-example. As far as I remember with this approach i would have to include the header and the bottom in every jsp file in every snap manually. My requirement is that the template is injected automatically without giving a snap the ability to mess around with it. I dont think with the animal-approach that is not possible right? With the filter you are right. I will change that.
@Dmitry Sklyut
Just looked at an example of sitemesh. looks promising! i will give it a try!