tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Swati Rastogi -X (swrastog - Infosys at Cisco)" <swras...@cisco.com>
Subject HttpServletRequest.getReader() returns nothing
Date Mon, 27 Jul 2009 09:38:38 GMT
Hi All,
I am doing a HTTP POST on a servlet running on my local box. For this, I
am opening a socket on port 80 and sending the data.
When I call getReader() on HttpServletRequest object, I cannot find any
data. Instead of Calling getReader(), if I call getParameter() or
getParameterMap() on HttpServletRequest object, I can retrieve the data
which has been posted
 
This works well on Linux 4 with apache version 2.0 and tomcat version
4.X and jk2 i.e. getReader returns data.
The issue is seen on Linux 5 with apache version 2.2.3 and same tomcat
version 4.X and mod_jk1.2.27. 
 
Any clues as to what is going wrong?
 
Using tcpdump, I have seen the request - It looks as expected.
------------------------------------------------------------------------
----------------------
POST /servlet/Help HTTP/1.0
Content-Length: 17
Content-Type: application/x-www-form-urlencoded
 
Want to send this
------------------------------------------------------------------------
----------------------
 
SERVER CODE:
--------------------
getReader() on HttpServletRequest object returns me BufferedReader
object. 
If I call read() on buffer, I get -1. If I call readLine() on buffer, I
get NULL. 
 
This is how I am calling in my servlet:
                  java.io.BufferedReader _buffer = req.getReader();
                  System.out.println("****Is Buffer object ready " +
_buffer.ready());
                  System.out.println("****Is Buffer object char: " +
_buffer.read());
                  System.out.println("****Is Buffer object line: " +
_buffer.readLine());

Instead of Calling getReader(), if I call getParameter() or
getParameterMap() on HttpServletRequest object, I can retrieve the data
which has been posted.
 
 
 
CLIENT CODE:
-----------------
            // Construct data
            String data = "Sending simple data";
 
            // Create a socket to the host
            String hostname = "127.0.0.1";
            int port = 80;
            InetAddress addr = InetAddress.getByName(hostname);
            Socket socket = new Socket(addr, port);
 
            // Send header
            String path = "/servlet/Help";
            BufferedWriter wr = new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream(), "UTF8"));
            wr.write("POST "+path+" HTTP/1.0\r\n");
            wr.write("Content-Length: "+data.length()+"\r\n");
            wr.write("Content-Type:
application/x-www-form-urlencoded\r\n");
            wr.write("\r\n");
 
            // Send data
            wr.write(data);
            wr.flush();
 
            // Get response
            BufferedReader rd = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                // Process line...
                System.out.println(line);
            }
            wr.close();
            rd.close();

Regards,
Swati

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message