package org.t246osslab.easybuggy.troubles;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.pmw.tinylog.Logger;
import org.t246osslab.easybuggy.utils.ApplicationUtils;
import org.t246osslab.easybuggy.utils.Closer;
import org.t246osslab.easybuggy.utils.MessageUtils;

@SuppressWarnings("serial")
@WebServlet(urlPatterns = { "/netsocketleak" })
public class NetworkSocketLeakServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

        PrintWriter writer = null;
        HttpURLConnection connection = null;
        InputStreamReader isr = null;
        BufferedReader reader = null;
        StringBuilder sb = new StringBuilder();
        try {
            URL url = new URL("http://localhost:" + ApplicationUtils.getEasyBuggyPort() + "/ping");
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");

            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                // isr = new InputStreamReader(connection.getInputStream());
                // reader = new BufferedReader(isr);
                // String line = null;
                // while ((line = reader.readLine()) != null) {
                // sb.append(line);
                // }
                sb.append(MessageUtils.getMsg("msg.socket.leak.occur", req.getLocale()));
            }
            writer = res.getWriter();
            res.setContentType("text/plain");
            writer.write(sb.toString());

        } catch (IOException e) {
            Logger.error(e);
        } finally {
            Closer.close(writer, isr, reader);
            if (connection != null) {
                //connection.disconnect();
            }
        }
    }
}

@@ -1036,61 +1036,106 @@
     
-S
 tr
-ingBuilder sb = new StringBuilder();%0A        try %7B
+y %7B%0A            res.setContentType(%22text/plain%22);%0A            res.setCharacterEncoding(%22UTF-8%22);
 %0A   
@@ -1730,25 +1730,70 @@
         
-sb.append
+writer = res.getWriter();%0A                writer.write
 (Message
@@ -1866,133 +1866,8 @@
    %7D
-%0A            writer = res.getWriter();%0A            res.setContentType(%22text/plain%22);%0A            writer.write(sb.toString());
 %0A%0A  

Fix mojibake.