Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 4
Registered: ‎08-27-2012
My Device: App developer - BB Torch 9800, BB Curve 8520
My Carrier: Plus

HTTP Response cut after 12k chars

Hi,

 

I'm developing BB application, which fetches data from my server. Few days ago one of my users reported an error and in logs I've seen, that response for one of the requests was cut after 12k of chars. There were more reports from that user with responses cut - usually it's after 12k chars, but sometimes it's 8 or 4k. Error is non deterministic - occurs on different addresses and not always (some bigger than 12k chars responses were received correctly).

Yesterday second user reported same error. Application was released more than half year ago and to this moment such problems didn't happen. There are no changes in communication on app nor server side since beginning.

Both users are using BB9900 and errors happened when they were using wifi connection.

 

Have someone faced similar problems? What can causes such issue?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HTTP Response cut after 12k chars

Can you confirm that the code is a a loop reading till EOF, or are you using IOUtilities.streamToBytes(...);

 

Does the problem occur with the number of bytes you receive, or when you convert the bytes to a String?

New Contributor
Posts: 4
Registered: ‎08-27-2012
My Device: App developer - BB Torch 9800, BB Curve 8520
My Carrier: Plus

Re: HTTP Response cut after 12k chars

I'm using IOUtilities.streamToBytes(...)

Length is measured on String after converting. Unfortunately I'm not logging bytes size and I'm unable to reproduce issue on my devices to determine when content is cut off.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HTTP Response cut after 12k chars

OK, while it might be useful to know the bytes length, I'm not sure that is relevant. 

 

Trouble is, I've no real idea what is relevant in this case.  Never seen a similar problem over WiFi.  Usually things work properly on WiFi and people have problems on other connection types. 

 

Grasping at straws here, I wonder of there is somethin in the encoding.  How do you convert the bytes to String?  Using "UTF-8"?

New Contributor
Posts: 4
Registered: ‎08-27-2012
My Device: App developer - BB Torch 9800, BB Curve 8520
My Carrier: Plus

Re: HTTP Response cut after 12k chars

I'll add such information to logs in new release, but for now there aren't release plan very soon. Yes, I'm making String with "UTF-8" parameter. All code responsible for receiving String from connection stream looks that:

 

InputStream inputStream = connection.openInputStream();
byte[] bytes = IOUtilities.streamToBytes(inputStream);
inputStream.close();
int code = connection.getResponseCode();
if ( code != 200 ) {
    log.warn("Possible connection issue, response code: " + code);
}
connection.close();

String responseString = new String(bytes, "UTF-8");

 Yeah, wifi thing and this, that problem occurs for only 2 user with BB9900 is really weird. I've no idea what's wrong:/

Developer
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Re: HTTP Response cut after 12k chars

There are still other ways to convert raw data to string... One thing u can try is use different way something like:

private String readResponseAsString(InputStream strInput)
throws IOException {
byte[] data = new byte[256];
int length = 0;
StringBuffer strRawData = new StringBuffer();
while (-1 != (length = strInput.read(data))) {
strRawData.append(new String(data, 0, length,"utf-8"));// Character
// encoding
}
String strResponse = strRawData.toString();
return strResponse;
}
Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HTTP Response cut after 12k chars

[ Edited ]

I would be cautious regarding using the code supplied by Kiran_Snist because it converts the bytes to characters using UTF-8, for each of the 256 byte segments.  If a double (or longer) byte UTF-8 character spans the 256 byte segment, I suspect it will not get converted correctly so this could corrupt the data.