problem when transfer wbxml information between j2me client and j2ee server

"Young Penny" <[email protected]> Tue, 11 May 2004 00:10:43 +0800
Newsgroups gmane.comp.java.enhydra.kxml
Message-ID <[email protected]>
Hi,everyone,I am developing a project based on the j2me and j2ee.I=20
encounter a problem when I want to use wbxml as the message format=20
transfered between the j2me client and servlet.My code follows the code i=
n=20
the article "Compressing XML for Faster Wireless Networking"=20
(http://developers.sun.com/techtopics/mobility/midp/ttips/compressxml/)
=20

The code of my client is as follows:
  private static final String tagTable[] =3D
		{
			"accountInfo",
			"accountName",
			"passWord",
			"personID",
			"mobilePhone",
			"e_mail" };

con =3D(HttpConnection) Connector.open(
	"http://127.0.0.1:28080/webmodule/servlet/account");
	con.setRequestMethod(HttpConnection.POST);
	out =3D con.openOutputStream();
	out.flush();
	xmlWriter =3D new WbxmlWriter(out);
	xmlWriter.setTagTable(0, tagTable);
	xmlWriter.startTag("accountInfo");
	xmlWriter.startTag("accountName");
	xmlWriter.write(accountName);
	xmlWriter.endTag();
           .........................................................

The server code of my server is as follows:
     in request.getInputStream();
     parser =3D new WbxmlParser(in);
     ParseEvent event =3D null;
     parser.setTagTable(0, tagTable);
     do {
           try {
		event =3D parser.read();
		if ((Xml.START_TAG =3D=3D event.getType())
			&& (event.getName().equalsIgnoreCase("accountName"))) {
			if (Xml.TEXT =3D=3D (event =3D parser.read()).getType()) {
			accountName =3D event.getText();
				=09
		}
	}
     ..............................................

But I find that I get an exception when the client trid to send the messa=
ge=20
to the servlet.
The exception information is below:
java.io.IOException: Unexpected EOF
	at org.kxml.wap.WbxmlParser.readByte(Unknown Source)
	at org.kxml.wap.WbxmlParser.readInt(Unknown Source)
	at org.kxml.wap.WbxmlParser.<init>(Unknown Source)
	at server.web.Accountlet.doGet(Accountlet.java:86)
=09
I am confused by the exception . So I checked the source code of kXML1.21=
.=20
I think that the problem may be inside the constructor of wbxmlparser.
The code of constructor of wbxmlparser is below:
this.in =3D in;
=09
	version =3D readByte ();=20
	publicIdentifierId =3D readInt (); =20
=09
	if (publicIdentifierId =3D=3D 0) readInt ();=20
=09
	charSet =3D readInt (); // skip charset
=09

             //Notice the problem may be here
	int strTabSize =3D readInt ();  =20

	StringBuffer buf =3D new StringBuffer (strTabSize);
	   =20
	for (int i =3D 0; i < strTabSize; i++)=20
	    buf.append ((char) readByte ());

	stringTable =3D buf.toString ();

The wbxmlwriter only writer three binary number in the constructor:
           out.write (0x01); // version
	out.write (0x01); // unknown or missing public identifier
	out.write (0x04); // iso-8859-1

But the wbxmlparser need more than three binary numbers.So the function=20
readByte() called by the function readInt() throws the Exception mentione=
d=20
above.
I don't know the use of strTabSize .It seems the client must write more=20
binary number to the stream.
Does anyone can tell me the right code(both the client and the server) to=
=20
transfer wbxml information between client and server?=20
Or tell me how to write the code correctly?
Do I really need to learn the knowledge of what the binary number stands=20
for(such as 0x01 stands for something ,0x03 stands for something)? I thin=
k=20
the knowledge of encoding with wbxml should be transparent to the users.

Any idea or suggestion is highly appreciated.
Thank you!
Best regards!
                                                                 Benny Yo=
ung

_________________________________________________________________
=C3=E2=B7=D1=CF=C2=D4=D8 MSN Explorer:   http://explorer.msn.com/lccn/ =20