Search in sources :

Example 1 with WatchDog

use of org.apache.wiki.WatchDog in project jspwiki by apache.

the class WikiJSPFilter method doFilter.

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;
        responseWrapper = new MyServletResponseWrapper((HttpServletResponse) response, m_wiki_encoding, useEncoding);
        // fire PAGE_REQUESTED event
        String pagename = DefaultURLConstructor.parsePageFromURL((HttpServletRequest) request, response.getCharacterEncoding());
        fireEvent(WikiPageEvent.PAGE_REQUESTED, pagename);
        super.doFilter(request, responseWrapper, chain);
        try {
            w.enterState("Delivering response", 30);
            WikiContext wikiContext = getWikiContext(request);
            String r = filter(wikiContext, responseWrapper);
            if (useEncoding) {
                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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WikiContext(org.apache.wiki.WikiContext) WatchDog(org.apache.wiki.WatchDog) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpServletResponseWrapper (javax.servlet.http.HttpServletResponseWrapper)1 WatchDog (org.apache.wiki.WatchDog)1 WikiContext (org.apache.wiki.WikiContext)1