DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3905>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3905

request.getIntputStream()/Reader.close() problem.

           Summary: request.getIntputStream()/Reader.close() problem.
           Product: Tomcat 3
           Version: 3.3 Release Candidate 1
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Servlet
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


In trying to write code that sends an xml packet to a servlet in the content of
the request, it appears
that the tomcat server is not handling the getInputStream() code correctly.
What seems to happen is that the first close on the handle of the input
stream - closes the stream permanently.  This means that the same exact
request repeated 20 times will work the first time, but not the second
or any futher beyond the first request.   This problem shows up both
in 3.3 m4 and 3.3 rc1.  The message that shows up the second time is "stream
closed"

My code on the servlet side looks like:

public class processjdist
{
    public String contents ="";

    public processjdist()
    {
    } 
    
    public init(HttpServletRequest req, HttpServletResponse resp)
    {
        out = resp.getOutputStream();
        try 
         {
        if (req.getContentLength() > 0)
        {
           Reader r = req.getInputStream();
           BufferedReader bufReader = new BufferedReader(r);

           /// PROBLEM SHOWS UP HERE!!! Second time code is called
           /// on the server
           /// error is "Stream closed"
           while ((line = bufReader.readLine()) != null)
           {
                contents += line;
           }
         
           r.close();
         }
         } catch (IOException ioe)
         {  
              
         }
    }

    public doPost(HttpServletRequest req, HttpServletResponse resp)
    {
        init(req,resp);
    }
}

The client side looks like
public class jdistclient
{
     StringBuffer outputBuffer = new StringBuffer();
     public jdistclient()
     {
         String urlString ="http://www.netmech.com/customer/apprequest/get";;
        outputBuffer.append("<request>foo</request>");
        try
        {
            log.debug("fetch from urlFetch");
            // Send request to web server.
            URL appreq = new URL(urlString);
            
  
           
            URLConnection c = appreq.openConnection();
            log.debug("fetch 1"); 
            c.setDoOutput(true);
            c.setDoInput(true);
            //c.setDoInput(true);
            
            DataOutputStream dout = new DataOutputStream(c.getOutputStream());
            log.debug("fetch 1.5");
             
            log.debug("fetch 2");
            dout.writeBytes(outputbuffer.toString());
  
           
            log.debug("fetch 3");  
           
           
            dout.close();
            
            InputStream is = c.getInputStream();
            log.debug("fetch 3.1");
            
            
            log.debug("fetch 3.1.5");
            InputStreamReader r = new InputStreamReader(is);
            log.debug("fetch 3.2");
            BufferedReader in = new BufferedReader(r);
                                          
            log.debug("fetch 3.5"); 
            
            
            String inputLine;
             log.debug("fetch 4"); 
            while ((inputLine = in.readLine()) != null)
            {
                log.debug(inputLine);
                buffer.append(inputLine);
                buffer.append("\n");
            }
            is.close();
            in.close();
           
            
            log.debug("fetch 5"); 

        }
        catch (IOException ioe)
        {
            log.error("Error:"+ioe.getMessage());
            String s = ioe.getMessage();
            System.out.println("Error:"+s);
            System.out.println(ioe.getLocalizedMessage());
            System.out.println(ioe.toString());
        }

     
     }

     public static void main(String [] args)
     {
        for (int i=0; i < 20; i++)
         {
             jdistclient j = new jdistclient();

         }
     }
}

Reply via email to