You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2009/07/09 11:07:29 UTC

DO NOT REPLY [Bug 47500] New: request.getParameter lead to servlet can't receive READ event in CometProcessor class

https://issues.apache.org/bugzilla/show_bug.cgi?id=47500

           Summary: request.getParameter lead to servlet can't receive
                    READ event in CometProcessor class
           Product: Tomcat 6
           Version: 6.0.18
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: major
          Priority: P2
         Component: Servlet & JSP API
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: lxw7777@gmail.com


Created an attachment (id=23947)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=23947)
It include jsp and servlet file

Hello, 
  I wrote an example to practice Comet service in Tomcat 6, I found if I put
HttpServletRequest.getParameter during BEGIN event, then I never receive READ
event. If I remove it, then it can work. If I use getSession(), it can get READ
event also



My web.xml configuration

    <description>
      ww web chat.
    </description>
    <display-name>WW web chat</display-name>

<!-- Thomas Luo added -->
    <servlet>
        <servlet-name>wweb_chat</servlet-name>
        <servlet-class>wwebchat.wweb_chat</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>wweb_chat</servlet-name>
        <url-pattern>/wwebchat/wweb_chat</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>wweb_chat</servlet-name>
        <url-pattern>/a</url-pattern>
    </servlet-mapping>

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 47500] request.getParameter lead to servlet can't receive READ event in CometProcessor class

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47500


Paul Gonchar <pa...@coehl.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paul@coehl.com




--- Comment #1 from Paul Gonchar <pa...@coehl.com>  2009-07-10 14:52:59 PST ---
We have the same problem on Tomcat 6.0.18 and 6.0.20 (running on FreeBSD v7.2
amd64). Also, tried building from HEAD on 07/10/2009 with the same result.
We are trying to implement a servlet based on CometProcessor. Here is a snippet
of our server code:

   public void event( CometEvent _event ) throws IOException, ServletException
{
      CometEvent.EventType type = _event.getEventType();
        switch ( type ) {
          case BEGIN:
            // needed for APR connector
            if (
_event.getHttpServletRequest().getAttribute("org.apache.tomcat.comet.timeout.support")
== Boolean.TRUE ) {
              _event.setTimeout( getTimeout() );
            }
            break;
          case READ:
            processRead( _event );
            _event.getHttpServletResponse().flushBuffer();
            break;
          case END:
          case ERROR:
            _event.close();
            break;
        }
  }


In the next method the call to getParameter("message") prevents response from
getting to the client. After some time some responses make it to the client,
but these responses contain only headers (for example, "Connection" header set
to "keep-alive" in the servlet by the call
_event.getHttpServletResponse().addHeader("Connection", "keep-alive")) - no
data is received.  We tracked this in Firebug under Firefox 3.5 . 

If we invoke event.close() after processing of handshake(the same way it is
done in BayeuxServlet.handleEvent(xxx) in the HEAD) then the client gets the
response and servlet will get another "connect" request. However, there is
nowhere to write the next response to because output stream is already closed.

When we remove the call to
_event.getHttpServletRequest().getParameter("message") everything works fine. 

private int processRead( CometEvent _event ) throws IOException,
ServletException {
    String msg = _event.getHttpServletRequest().getParameter("message"); //
---------<<<<<<<< THE PROBLEM CALL
    try {
      JSONArray jobj = new JSONArray( msg );
      for (int i = 0; i < jobj.length(); i++) {
        JSONObject jMsg = jobj.getJSONObject(i);
          PrintWriter out = _event.getHttpServletResponse().getWriter();
          if ( "/meta/handshake".equals( jMsg.optString("channel") ) ) {
            out.print( "[" + handshake( jMsg) + "]" );
            out.flush();
          } else if ( "/meta/connect".equals( jMsg.optString("channel") ) ) {
            out.print( "[ { json response } ]" );
            out.flush();
          }
      }
    } catch ( Exception ex ) {
      throw new ServletException( ex );
    }
    return 0;
  }

private JSONObject handshake( JSONObject _msg ) throws JSONException {
    JSONObject response = new JSONObject();
    response.put( "channel", "/meta/handshake");
    response.put( "version", "1.0");
    response.put( "minimumVersion", "0.9");
    response.put( "clientId", bayeux.newClient().getId() );
    response.put( "successful", true);
    response.put( "supportedConnectionTypes", new String[] { "long-polling",
"callback-polling" } );
    response.put( "id", _msg.optInt("id") );
    return response;
}

Here is our test client page:

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <script type="text/javascript"
src="http://localhost:8180/dojo/1.3.1/dojo/dojo.js" djConfig="parseOnLoad:
true, isDebug: true">
  <script type="text/javascript">
    dojo.require("dojox.cometd");
    dojo.addOnLoad( function() { dojox.cometd.init("/functionaltest/cometd");
});
  </script>
</head>

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 47500] request.getParameter lead to servlet can't receive READ event in CometProcessor class

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47500

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Mark Thomas <ma...@apache.org> 2009-12-01 16:18:07 GMT ---
That is as expected.

HttpServletRequest.getParameter() will drain the input stream reading the data
from the form so there is nothing left to generate a read() event.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org