J2ME with Hessian

From: Mehdi Mehdi <mehdi_cit@xxx.com>
Date: Fri Aug 12 2005 - 13:06:03 PDT

Hello list.
I'm having a problem runing the simple example
("http://www.caucho.com/hessian/test/basic")
from ahand held device (Actually I'musing sun's MDP1 emulator from whithing
Eclipse-EclipseME).
The same example does wotk from a simple Java App!
I hope someone can help me with understanding what'sgoing on!
Or else provide some examples that do work (J2ME compliant) .
The actuall J2ME code I'm using comes from some book (I lost the book and
kept the code -:) )
I get an exception while expecting some return value from the server (a
String, after callingthe hello function).

Here's the whole code followed by the exception.

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import com.caucho.hessian.io.*;
import com.caucho.hessian.micro.MicroHessianOutput;
import com.caucho.hessian.micro.MicroHessianInput;
import java.io.*;

public class TestMidlet extends MIDlet {
        private Display display;
        public TestMidlet() { super();}
        protected void startApp() throws MIDletStateChangeException {
                display = Display.getDisplay(this);
            try {
              String url = "http://www.caucho.com/hessian/test/basic";
              HttpConnection c = (HttpConnection) Connector.open(url);
              c.setRequestMethod(HttpConnection.POST);
              OutputStream os = c.openOutputStream();
              MicroHessianOutput out = new MicroHessianOutput(os);
              out.startCall("hello"); out.writeNull(); out.completeCall();
              InputStream is = c.openInputStream();
              MicroHessianInput in = new MicroHessianInput(is);
              System.out.println("B4 in.startReply(); ...");
              in.startReply();
              String value = in.readString();
              System.out.println("String value = " + value);
              in.completeReply();
              TextBox t = new TextBox("Http Test", value, value.length(), 0);
              display.setCurrent(t);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("Exception e.getMessage() = (" + e.getMessage()
+")");
            }
        }
        protected void pauseApp() { }
        protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{ }
}
----------------------
Here's the output:
B4 in.startReply(); ...
java.io.IOException: expected string at m
        at com.caucho.hessian.micro.MicroHessianInput.readString(+29)
        at TestMidlet.startApp(+98)
        at javax.microedition.midlet.MIDletProxy.startApp(+7)
        at com.sun.midp.midlet.Scheduler.schedule(+270)
        at com.sun.midp.main.Main.runLocalClass(+28)
        at com.sun.midp.main.Main.main(+116)
Exception e.getMessage() = (expected string at m)
----------------------
PS: If I use a string other than "hello" I get a slightly different output,
namely
I get (expected string at f) instead of (expected string at m)
Ofcourse hello refers to the hello() function that is provided by
theserver!!

Thx in advance
Received on Fri 12 Aug 2005 13:06:03 -0700

This archive was generated by hypermail 2.1.8 : Thu Sep 28 2006 - 20:16:41 PDT