}
public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain )
throws ServletException, IOException
{
WatchDog w = m_engine.getCurrentWatchDog();
try
{
NDC.push( m_engine.getApplicationName()+":"+((HttpServletRequest)request).getRequestURI() );
w.enterState("Filtering for URL "+((HttpServletRequest)request).getRequestURI(), 90 );
HttpServletResponseWrapper responseWrapper;
if( m_useOutputStream )
{
log.debug( "Using ByteArrayResponseWrapper" );
responseWrapper = new ByteArrayResponseWrapper( (HttpServletResponse)response, m_wiki_encoding );
}
else
{
log.debug( "Using MyServletResponseWrapper" );
responseWrapper = new MyServletResponseWrapper( (HttpServletResponse)response, m_wiki_encoding );
}
// fire PAGE_REQUESTED event
String pagename = DefaultURLConstructor.parsePageFromURL(
(HttpServletRequest)request, response.getCharacterEncoding() );
fireEvent( WikiPageEvent.PAGE_REQUESTED, pagename );
super.doFilter( request, responseWrapper, chain );
// The response is now complete. Lets replace the markers now.
// WikiContext is only available after doFilter! (That is after
// interpreting the jsp)
try
{
w.enterState( "Delivering response", 30 );
WikiContext wikiContext = getWikiContext( request );
String r = filter( wikiContext, responseWrapper );
if (m_useOutputStream)
{
OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream(),
response.getCharacterEncoding());
out.write(r);
out.flush();
out.close();
}
else
{
response.getWriter().write(r);
}
// Clean up the UI messages and loggers
if( wikiContext != null )
{
wikiContext.getWikiSession().clearMessages();
}
// fire PAGE_DELIVERED event
fireEvent( WikiPageEvent.PAGE_DELIVERED, pagename );
}
finally
{
w.exitState();
}
}
finally
{
w.exitState();
NDC.pop();
NDC.remove();
}
}