Skip to main content

Parsing WBXML POSt Request Data

3 replies [Last post]
thdevqueen
Offline
Joined: 2007-11-15
Points: 0

Hi!
I want to read WBXML formatted SyncML data sent by a Mobile Device
There is a servlets at server side which receives the http request of the
device and tries to read the contents of the POST request data by using .
Request.getInputStream(); method....
I then Pass this data to a method "wbxmlToXml(req.getInputStream().toString().getBytes()) "
I am using kxml as XML parsing the Initial Lines of the method are as following
"
public static String wbxmlToXml(byte[] wbxml) throws IOException {
String xml = null;
try {
// Construct an InputStream on byte[] to be used by WbxmlParser
ByteArrayInputStream in = new ByteArrayInputStream(wbxml);
AbstractXmlParser parser; //org.kxml.parser.AbstractXmlParser
parser = new WbxmlParser(in);
// Construct a DOM Document to parse WBXML
Document document = new Document();
document.parse(parser);------------------> Error :java.io.IOException: id 54 undef.
....
.....
"
I get "java.io.IOException: id 54 undef." error as mentioned above.

Please somebody guide regarding this problem

Regards,
Maneesha

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
oleksiys
Offline
Joined: 2006-01-25
Points: 0

req.getInputStream().toString().getBytes()

is not correct way to get byte[] from InputStream.
From your code it's not clear why you're trying to get byte[] from Servlet's InputStream and then transform it again to the ByteBufferInputStream.
IMHO it makes sense to pass req.getInputStream() and use it, when creating WbxmlParser.

thdevqueen
Offline
Joined: 2007-11-15
Points: 0

Thanks for The reply....Actually I wanted to convert the WBXML to XML byte array thats y the method was returning another byteArray but XML formatted.

Any ways i have changed the method as Foloowing

public static void wbxmlToXml(InputStream in)
throws Exception {
try {
AbstractXmlParser parser= new WbxmlParser(in);--------->>>Error Here
// Construct a DOM Document to parse WBXML
Document document = new Document();
document.parse(parser);
System.out.println(document.getRootElement().getName());
in.close();
} catch (Throwable t) {
throw new Exception(t.getMessage(), t);
}
}

and while passing request.getInputStream to this method i got following error.

Caused by: java.io.IOException: Unexpected EOF
at org.kxml.wap.WbxmlParser.readByte(WbxmlParser.java:470)

oleksiys
Offline
Joined: 2006-01-25
Points: 0

Not sure what could be the reason.
Either client sends corrupted request, or parser has some error.
Unfortunately I don't have any WBXML experience, so can not help much here.
May be others could have some thoughts?