java.lang.IllegalStateException: Already connected at getOutputStream

there! I need your help again.

I am trying to make Tomcat1 pass parameters to Tomcat2 and the Tomcat2 pass the parameters to Tomcat3 using httpurlconnection.

It worked fine until yesterday but somehow it is not working today.

I looked up all questions about this already connected error but nothing worked with mine.

Here are my codes.

tomcat1Servlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("mainServlet is requested");


    String s_guid = (String)UUID.randomUUID().toString();
    String i_guid = (String)UUID.randomUUID().toString();
    String d_guid = (String)UUID.randomUUID().toString();

    System.out.println("s_guid: "+s_guid+"\n i_guid: "+i_guid+"\n d_guid: "+d_guid);

    //get parameters
    String[] trans = request.getParameterValues("transaction");

    Map<String, Object> map = new HashMap<String, Object>();
    ArrayList<String> transList = new ArrayList<String>();

    for(String tran : trans) {
        if(tran.equals("delete")) {

            String d_account = request.getParameter("d_account");
            map.put("d_account", d_account);
            map.put("d_guid", d_guid);
        }
        if(tran.equals("insert")) {

            String i_account = request.getParameter("i_account");
            map.put("i_account",i_account);
            map.put("i_guid", i_guid);
        }
        if(tran.equals("select")) {

            String s_account = request.getParameter("s_account");
            map.put("s_account", s_account);
            map.put("s_guid", s_guid);
        }

        transList.add(tran);

    }

    mainURL urlConn = new mainURL();
    String sb = urlConn.sendData(map, transList);

    request.setAttribute("json", sb);

    RequestDispatcher dispatcher = 
    request.getRequestDispatcher("resultPage.jsp");
    dispatcher.forward(request, response);
}

mainURL.java of Tomcat1

public String sendData(Map<String, Object> map, ArrayList<String> list) {
    StringBuffer sb = new StringBuffer();
    try {
        Properties prop = new Properties();
        prop.putAll(map);
        String encodedString = encodeString(prop);
        String encodedList = encodeString(list);

        String params = encodedString+"&"+encodedList;

        URL url = new URL("http://localhost:28080/socket_client1/tomcat2Servlet");

        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        conn.setRequestProperty("charset","utf-8");
        conn.setReadTimeout(20000);
        conn.setConnectTimeout(20000);
        conn.setRequestMethod("POST");
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setUseCaches(false);

        OutputStream os = conn.getOutputStream();
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(os, "UTF-8"));
        writer.write(params);
        writer.flush();
        writer.close();
        os.close();

        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

        String line;

        while((line = in.readLine()) != null) {
            sb.append(line);
        }
        in.close();
        System.out.println(sb.toString());
        conn.disconnect();


        }

    catch(Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

tomcat2Servlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("deleteServlet is requested");
    response.setContentType("text/html; UTF-8");

    String[] trans = request.getParameterValues("transaction");
    Map<String, Object> map = new HashMap<String, Object>();
    ArrayList<String> transList = new ArrayList<String>();
    PrintWriter out = response.getWriter();

    for(String tran : trans) {
        if(tran.equals("delete")) {
            clientDAO cDao = new clientDAO();
            String d_account = request.getParameter("d_account");
            map.put("d_account", d_account);
            cDao.insertData(d_account);
            out.println("delete complete!!");

            String guid = request.getParameter("d_guid");
            guidClass.getGUID(guid);
            map.put("d_guid", guid);
        }
        if(tran.equals("insert")) {
            String i_account = request.getParameter("i_account");
            map.put("i_account",i_account);

            String guid = request.getParameter("i_guid");
            map.put("i_guid", guid);

        }
        if(tran.equals("select")) {
            String s_account = request.getParameter("s_account");
            map.put("s_account", s_account);

            String guid = request.getParameter("s_guid");
            map.put("s_guid", guid);
        }

        transList.add(tran);

    }
    clientURL urlCon = new clientURL();     
    for(String tran : trans) {
        if(tran.equals("insert") || tran.equals("select")) {
            String jsonResult = urlCon.sendData(map, transList);
            out.print(jsonResult);
        }
    }
}

clientURL.java of Tomcat2

    public String sendData(Map<String, Object> map, ArrayList<String> list) {
        StringBuffer sb = new StringBuffer();
        try {
            Properties prop = new Properties();
            prop.putAll(map);
            String encodedString = encodeString(prop);
            String encodedList = encodeString(list);
            String params = encodedString+"&"+encodedList;

            URL url = new URL("http://localhost:38080/socket_client2/tomcat3Servlet");

            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            conn.setRequestProperty("charset","utf-8");
            conn.setReadTimeout(20000);
            conn.setConnectTimeout(20000);
            conn.setRequestMethod("POST");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);

            OutputStream os = conn.getOutputStream();
            BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(os, "UTF-8"));
            writer.write(params);
            writer.flush();
            writer.close();
            os.close();

            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

            String line;

            while((line = in.readLine()) != null) {
                sb.append(line);
            }
            in.close();
            System.out.println(sb.toString());
            conn.disconnect();

            }
        catch(Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

Tomcat3Servlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("insertServlet is requested");
        response.setContentType("text/html; UTF-8");


    String[] trans = request.getParameterValues("transaction");
    Map<String, Object> map = new HashMap<String, Object>();
    PrintWriter out = response.getWriter();

    for(String tran : trans) {
        if(tran.equals("insert")) {
            clientDAO dao = new clientDAO();
            String i_account = request.getParameter("i_account");
            dao.insertData(i_account);
            out.println("insert complete!!!");

            String guid = request.getParameter("i_guid");
            guidClass.getGUID(guid);

        }

  }
}

errorMEssage

java.lang.IllegalStateException: Already connected
    at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:3071)
    at aries.runtime.tracer.b.c.sendGuidByHttp(SourceFile:601)
    at aries.base.profile.ProfileService.sendGuidByHttp(ProfileService.java:216)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
    at socket.client.clientURL.sendData(clientURL.java:60)
    at servlet.client.deleteServlet.doGet(deleteServlet.java:81)
    at servlet.client.deleteServlet.doPost(deleteServlet.java:96)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:409)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

I get the error message at OutputStream os = conn.getOutputStream() in Tomcat2's clientURL.java

how can i solve this problem? thanks in advance.