Hi everybody!

I've encountered a problem with Tomcat4-b5:

We implemented a client/server system for a callcenter. The client is an
applet running in a browser. The server is a servlet running in
Tomcat4-b5. The client sends a request to the servlet and waits for the
answer from the servlet. The applet/servlet communication is done using
serialized Java objects. Since there are approximately 800 clients each
sending one request per second to the servlet it is 
extremely important that Tomcat uses persistent http connections.
Otherwise there will be no useable socket on the server sooner or later.
If there's no wait time in the client sending requests to the servlet
there's no problem. But in the production system we've got a sleep(1000)
in the client before sending the next request to the servlet. 

This results in a "java.io.EOFException: Couln't read line" in
org.apache.catalina.connector.http.HttpProcessor in the method
process(Socket), when calling parseRequest(input, output) originating in
org.apache.catalina.connector.http.SocketInputStream.readRequestLine(HttpRequestLine).
Tomcat closes that socket and uses a new one for the next request of the
same client. 
But the strange thing is: This exception doesn't occur always. It
relates to the wait time for the next request. If there's a sleep(800)
in the client no sockets will be closed (if client and servlet are
running on the same machine). If there's a sleep(200) sockets will be
closed. Note: Socket timeout is turned off.

The following code shows the applet and servlet code to post and handle
the request.

Applet code:

>  public ServletResponse postRequest(ServletRequest req) {
>    ServletResponse result = null;
>
>    try {
>      HttpURLConnection con = (HttpURLConnection) this.mUrl.openConnection();
>
>      con.setDoOutput(true);
>      con.setUseCaches(false);
>      con.setDefaultUseCaches(false);
>      con.setRequestMethod("POST");
>      ByteArrayOutputStream bos = new ByteArrayOutputStream(3000);
>      ObjectOutputStream out = new ObjectOutputStream(bos);
>      out.writeObject(req);
>      out.flush();
>
>      con.setRequestProperty("Content-Length", String.valueOf(bos.size()));
>      con.setRequestProperty("Content-Type", "application/x-java-serialized-object");
>      bos.writeTo(con.getOutputStream());
>      bos.flush();
>
>      ObjectInputStream ois = new ObjectInputStream(con.getInputStream());
>      Object obj = ois.readObject();
>
>      if ( obj instanceof ServletResponse ) {
>        result = (ServletResponse) obj;
>      }
>
>      ois.close();
>      out.close();
>    }
>
>    catch ( ConnectException cex ) {
>      this.mDebug.error("", cex);
>    }
>
>    catch ( IOException ioex ) {
>      this.mDebug.error("", ioex);
>    }
>
>    catch ( ClassNotFoundException cnf ) {
>      this.mDebug.error("", cnf);
>    }
>
>    return result;
>  }

The servlet code to handle the request:

>  public void doPost(HttpServletRequest request, HttpServletResponse response) throws 
>ServletException, IOException
>  {
>    try {
>      ObjectInputStream in = new ObjectInputStream(request.getInputStream());
>      ServletRequest req = (ServletRequest) in.readObject();
>      ServletResponse responseObj = null;
>
>      responseObj = this.handleRequest(request, req);
>
>      ByteArrayOutputStream bos = new ByteArrayOutputStream(5000);
>      ObjectOutputStream out = new ObjectOutputStream(bos);
>      out.writeObject(responseObj);
>      out.flush();
>      int size = bos.size();

>      response.setContentType(CONTENT_TYPE_OBJECT);
>      response.setContentLength(size);
>      bos.writeTo(response.getOutputStream());
>    }
>
>    catch ( ClassNotFoundException cnf ) {
>      this.mDebug.debug("", cnf);
>    }
>
>    catch ( IOException ioex ) {
>      this.mDebug.debug("", ioex);
>    }
>
>  }


What's the problem? Is that a Tomcat bug or a problem in our code?
Thanks!

-- 

Regards

Ralf

----------------------------------------------------------- 
Ralf Bechtel
OptiSoft GmbH 
Pforzheimer Str. 68a     D-75242 Neuhausen 
email:  [EMAIL PROTECTED] http://www.optisoft.de 
phone:  ++49 7234 9518-51 fax: ++49 7234 9518-44 
-----------------------------------------------------------

Reply via email to