RE: Problems while reading an InputStream

"Diego Ramirez Cardenas" <[email protected]> Thu, 11 Sep 2003 16:48:36 -0300
Newsgroups gmane.comp.java.enhydra.ksoap
Message-ID <[email protected]>
Stefan,
	I'm still having problems when I try to run my MIDP application in the device (Motorola A338). I've tried to implement the BoundInputStream class from kobjects, but as I mention before, it runs without problems on the emulator but when I try to run it on the device it fails. Let me explain the new "problems" that I've found.
	When running on the device the method HttpConnection.getLength() returns -1 while on the emulator it returns the correct content-length. I also noticed that when I run on the emulator I receive only the data in the InputStream, but when I run on the device I receive both the HTTP header and the data in the InputStream. (NOTE I'm trying to access the same URL both in the device and emulator)
	I really don't know how to workaround this, so if you have some new fresh idea I'll be very thankful.
	Thanks in advance.

Diego Ramirez Cardenas

-----Original Message-----
From: Stefan Haustein [mailto:[email protected]] 
Sent: quarta-feira, 10 de setembro de 2003 10:57
To: [email protected]

Diego Ramirez Cardenas wrote:
> Hi there folks,
> 	I'm having serious problems when I try to retrieve the response from a .NET Web Service. My MIDP application uses kSOAP to query my Web Service hosted on IIS 5.0. I have used the SoapRpcMethod attribute in my web method to make it RPC callable. Everything works fine in the emulator (I'm using JBuilder 9 Mobile Edition as IDE with JDK Wireless Toolkit 1.0.4).
> 	But when I test it on the device (Motorola A388), my app locks when it try to read the last block of data in the InputStream. It never reaches the end of file (InputStream.read() = -1). I'm posting below an snippet of kSoap code where the app stops (Even if I disable the debug flag, it also stops when the XmlParser try to read the stream).
> 

Diego,

some MIDP implementations seem to have strange problems with

- recognizing the end of the input stream
- supporting utf8

perhaps you can try to encapsulate the InputStream in a BoundInputStream 
available at kobjects.org to make sure that no more than 
"content-length" bytes are read, but that will help only if a valid 
"content-length" header is transmitted by the server.

Best,
Stefan



>             is = connection.openInputStream();
> 
>             if (debug) {
>                 bos = new ByteArrayOutputStream();
>                 byte[] buf = new byte[256];
> 
>                 while (true) {
>                     int rd = is.read(buf, 0, 256); -------> stops here when try to read the last block of data
>                     if (rd == -1)
>                         break;
>                     bos.write(buf, 0, rd);
>                 }
> 
>                 buf = bos.toByteArray();
>                 responseDump = new String(buf);
>                 is.close();
>                 is = new ByteArrayInputStream(buf);
>             }
> 
>             XmlPullParser xp = new KXmlParser();
>             xp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
>             xp.setInput (is, null); ---------> and stops here (inside setInput) if I disable the debug flag
> 
> 	I appreciate any help from you. My deadline is coming and I running out of ideas to solve this. Today I'll try to change the code to read the Content-Length in the header, and just read the exactly length of the stream. Without reaching the EOF, where resides my problem.
> 	Thanks in advance.
> 
> Diego Ramirez Cardenas
> CSIT Tecnologia e Serviços
> 
> 
> _______________________________________________
> Ksoap mailing list
> [email protected]
> http://www.enhydra.org/mailman/listinfo.cgi/ksoap


_______________________________________________
Ksoap mailing list
[email protected]
http://www.enhydra.org/mailman/listinfo.cgi/ksoap