Re: Problems while reading an InputStream

Stefan Haustein <[email protected]> Wed, 10 Sep 2003 15:57:21 +0200
Newsgroups gmane.comp.java.enhydra.ksoap
Organization University of Dortmund
Message-ID <[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