protected void service()

in src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalyzerWebConsole.java [84:142]


    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (req.getRequestURI().endsWith(RAW_FILE_MARKER) || req.getRequestURI().endsWith(ZIP_FILE_MARKER)) {

            InputStream input = null;
            OutputStream output = null;
            try {
                input = new FileInputStream(this.logFile);
                output = resp.getOutputStream();

                if (req.getRequestURI().endsWith(ZIP_FILE_MARKER)) {
                    ZipOutputStream zip = new ZipOutputStream(output);
                    zip.setLevel(Deflater.BEST_SPEED);

                    ZipEntry entry = new ZipEntry(this.logFile.getName());
                    entry.setTime(this.logFile.lastModified());
                    entry.setMethod(ZipEntry.DEFLATED);

                    zip.putNextEntry(entry);

                    output = zip;
                    resp.setContentType("application/zip");
                } else {
                    resp.setContentType("text/plain");
                    resp.setCharacterEncoding("UTF-8");
                    resp.setHeader("Content-Length", String.valueOf(this.logFile.length())); // might be bigger than
                }
                resp.setDateHeader("Last-Modified", this.logFile.lastModified());

                IOUtils.copy(input, output);
            } catch (IOException ioe) {
                throw new ServletException("Cannot create copy of log file", ioe);
            } finally {
                IOUtils.closeQuietly(input);

                if (output instanceof ZipOutputStream) {
                    ((ZipOutputStream) output).closeEntry();
                    ((ZipOutputStream) output).finish();
                }
            }

            resp.flushBuffer();

        } else if (req.getRequestURI().endsWith(WINDOW_MARKER)) {

            if (canOpenSwingGui(req)) {
                showWindow();
            }

            String target = req.getRequestURI();
            target = target.substring(0, target.length() - WINDOW_MARKER.length());
            resp.sendRedirect(target);
            resp.flushBuffer();

        } else {

            super.service(req, resp);

        }
    }