2 Replies Latest reply on Jun 12, 2007 4:56 AM by Chris Lowe

    Problem while Communicating between simple java class and Ht

    Shashank Newbie

      Hello Everybody,

      I'am using JBoss 3.2.3 and trying to connect to a Servlet from a Simple Java class and passing a User Defined object from client to servlet :

      The code that is used on the client:

      URL url = new URL("http://localhost:8080/rfid/ApplicationController");
      httpURLConnection = (HttpURLConnection) url.openConnection();
      OutputStream os = httpURLConnection.getOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(os);
      oos.writeObject(cpl); /* Where cpl is a user defined java object*/

      The code on the servlet is as follows:

      System.out.println("Request object value = "+req);
      ServletInputStream sis = req.getInputStream();
      System.out.println("Got ServletInput Stream ..."+sis);
      ObjectInputStream ois= new ObjectInputStream(sis); ----> It throws java.io.EOFException while creating ObjectInputStream
      System.out.println("Got ObjectInputStream in the server = "+ois);
      ClientParameterList cpl = (ClientParameterList)ois.readObject();

      The snippet of output on the server console is as given below:

      19:52:54,828 INFO [STDOUT] Request object value = org.apache.coyote.tomcat4.CoyoteRequestFacade@c66ec7
      19:52:54,978 INFO [STDOUT] Got ServletInput Stream ...org.apache.coyote.tomcat4.CoyoteInputStream@92eb86
      19:52:55,199 INFO [STDOUT] Got BufferedInputStream ...java.io.BufferedInputStream@a4ea4f
      19:52:55,409 INFO [STDOUT] ******* EOFException :java.io.EOFException
      19:52:56,400 INFO [STDOUT] Finally Block Executed

      The same piece of code works fine when used on tomcat 4.1.29. Could anyone please let me know, where i'm going wrong or any additional care that needs to be taken in JBoss.

      I would really appreciate a response as this is extremely urgent.

      Thanks in advance,

        • 1. Re: Problem while Communicating between simple java class an
          Shashank Newbie

          Hi Guys,

          I was able to solve the communication problem between java client and HTTP Sevlet.

          My Servlet had these steps in sequence:

          String strReqType = req.getParameter("requestType");
          ObjectInputStream ois= new ObjectInputStream(req.getInputStream());

          So if you try creating an ObjectInputStream object after an request.getParameter() it will thow an java.io.EOFException.

          To solve this problem I changed my flow by creating the ObjectInputStream object prior to doing the request.getParameter() operation as given below.

          ObjectInputStream ois= new ObjectInputStream(req.getInputStream());
          String strReqType = req.getParameter("requestType");

          Thanks and Regards,

          • 2. Re: Problem while Communicating between simple java class an
            Chris Lowe Apprentice

            Just been bitten by this in JBoss 4.2.0.GA - I can't believe this is still around after all this time.

            My code used to work just fine under Tomcat 5.5.17.

            Thanks to the original author of this post for persevering and posting a solution!