Hi,

I'm using JRun 3.0, developer version to test servlets and jsps on my local
machine before deploying code on our group's server.  We are doing
applet-servlet communication via serialized objects.  We are either doing
GETs or POSTs to communicate from the applet to the servlet.  If we're
sending lots of data from the applet to the servlet, we use POST.  If it's a
small amount of data, we're using GET.  If we read an object back when a GET
is done, there is no problem.  However, trying to read an object back when
doing a POST results in a StreamCorruptedException and a message indicating
that there is no object in the stream.  This code works fine with IBM's
Websphere, leading me to think that it's a bug in JRun 3.0.

Has anyone seen this problem before?  Is it fixed in the upcoming service
pack?  Or am I doing something wrong?

Thanks,

-jon

Here is the code which we're using to communicate:

applet side:
  /**
   * Get an object from the server.
   */
  public Object performGetCommand(String servletName, String inCommand) {
    Object result = null;
    try {
      URL theURL = new URL(getBaseURL(servletName).toExternalForm() +
"?command=" + inCommand);
      URLConnection theConnection = theURL.openConnection();
      theConnection.setUseCaches(false);
      InputStream theInputStream = theConnection.getInputStream();
      ObjectInputStream theObjectInputStream = new
ObjectInputStream(theInputStream);
      result = theObjectInputStream.readObject();
      theObjectInputStream.close();
    } catch(Exception e) {
      e.printStackTrace();
    }
    return result;
  }

  /**
   * Send an object to the server.
   */
  public Object performSetCommand(String servletName, String inCommand,
Hashtable inHashtable) {
    inHashtable.put("command", inCommand);
    Object result = null;
    try {
        System.out.println("getting ready to send object");
      URLConnection theConnection =
getBaseURL(servletName).openConnection();
      theConnection.setDoInput(true);
      theConnection.setDoOutput(true);
      theConnection.setUseCaches(false);
      theConnection.setRequestProperty("Content-Type",
"application/octet-stream");// "java-internal/" +
inHashtable.getClass().getName());
      ObjectOutputStream theOutputStream = new
ObjectOutputStream(theConnection.getOutputStream());
      theOutputStream.writeObject(inHashtable);
      theOutputStream.flush();
      theOutputStream.close();
        System.out.println("sent object");
      InputStream theInputStream = theConnection.getInputStream();
      System.out.println("theInputStream == " + theInputStream);
     ObjectInputStream theObjectInputStream = new
ObjectInputStream(theInputStream);
      System.out.println("theObjectInputStream == " + theObjectInputStream);
      result = theObjectInputStream.readObject();
      System.out.println("result == " + result);
      theObjectInputStream.close();
        System.out.println("read return object");
    } catch(Exception e) {
      System.out.println("Exception in DataAccess.performSetCommand()");
      e.printStackTrace();
    }
    return result;
  }

servlet side:
        public void doGet(HttpServletRequest req, HttpServletResponse res)
throws javax.servlet.ServletException, java.io.IOException {
                String theCommand = req.getParameter("command");
                if (theCommand != null) {
                        ObjectOutputStream theOutputStream = new
ObjectOutputStream(res.getOutputStream());
                        System.out.println("command == " + theCommand);
                        System.out.println("object == " +
_commands.get(theCommand));
        
theOutputStream.writeObject(((ServletGetCommand)_commands.get(theCommand)).e
xecute(req));
                        theOutputStream.close();
                }
        }

        public void doPost(HttpServletRequest req, HttpServletResponse res)
throws javax.servlet.ServletException, java.io.IOException {
                try {
                        System.out.println("in doPost");
                        ObjectInputStream theInputStream = new
ObjectInputStream(req.getInputStream());
                        ObjectOutputStream theOutputStream = new
ObjectOutputStream(res.getOutputStream());
                        Object theObject = theInputStream.readObject();
                        theInputStream.close();
                        if (theObject != null && theObject instanceof
Hashtable) {
                                Hashtable theHashtable =
(Hashtable)theObject;
                                String theCommand =
(String)theHashtable.get("command");
                                System.out.println("command == " +
theCommand);
                                if (theCommand != null) {
                                        System.out.println("object == " +
_commands.get(theCommand));
                                        Object out =
((ServletPostCommand)_commands.get(theCommand)).execute(theHashtable);
                                        if(out != null) {
                                                System.out.println("res == "
+ res);
        
System.out.println("res.getOutputStream() == " + res.getOutputStream());
        
System.out.println("theOutputStream == " + theOutputStream);
        
theOutputStream.writeObject(out);
                                              theOutputStream.flush();
                                                theOutputStream.close();
                                        }
                                }
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }


------------------------------------------------------------------------------
Archives: http://www.egroups.com/group/jrun-interest/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/jrun_talk
or send a message to [EMAIL PROTECTED] with 'unsubscribe' in the 
body.

Reply via email to