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

Web and WebWorks Development

Reply
Developer
Posts: 26
Registered: ‎01-13-2010
My Device: 8330
My Carrier: Telus

Random null response in Ajax request

[ Edited ]

I've been building a widget since Beta 1. I've noticed that when making ajax requests, sometimes, the responseText of the XmlHttpRequest object is null

 

The Ajax requests are made to a server which renders text or xml based on the GET parameters in the URL.The server is running a J2EE app, the text is rendered via JSPs.

 

The MDS Simulator is running. The browser in the simulator is able to connect to websites.

 

As a basic test I created a simple widget to make an ajax request to a service and display the responseText on the screen at the click of a button.

 

The runDiagnostics is hooked up to an onclick event in a button:

On the server side, the runDiagnostics web service performs some tests and returns a plain string based on the results of those test.

 

"Success - Connection with Web Services has been established - Ref: 2100000a Success: Found user associated with device - Ref: 2100000a Success: Connected to backend system."

 

The test widget is as follows:

 

var req;

function runDiagnostics() {
try {
var url = "http://192.168.2.203:8080/WebServiceConsumer/MobileWebService.do?action=runDiagnostics&pin=2100000a";
req = new XMLHttpRequest();
req.open("GET", url, true);
req.onreadystatechange = handleResponse;
req.send(null);
} catch(e) {
alert('Run Exception: ' + e.name + '; ' + e.message);
}
}

function handleResponse() {
try {
displayOutput("Ready state is " +req.readyState);
if (req.readyState == 4) {
displayOutput(req.status);
if (req.status == 200) {
displayOutput("Response Text: " + req.responseText);
} else {
displayOutput("Error: " + req.statusText + " " + req.responseText);
}
}
displayOutput("Returning from handler");
} catch(e) {
alert('handleResponse exception: ' + e.name + '; ' + e.message);
}
}

 

 

In one particular test, the output was the following. I performed this test by clicking the button, waiting for a response, and clicking the button again.

 

Ready state is 1

Returning from handler

Ready state is 2

Returning from handler

Ready state is 4

200

Response Text: null

Returning from handler

Ready state is 1

Returning from handler

Ready state is 2

Returning from handler

Ready state is 3

Returning from handler

Ready state is 4

200

Response Text: Success - Connection with Web Services has been established - Ref: 2100000a Success: Found user associated with device - Ref: 2100000a Success: Connected to backend system.

Returning from handler

 

A few things to point out.

- When the null is in the response, the XmlHttpRequest never passes through the readyState=3

- the null appears randomly, sometimes first, sometimes after 2 or 3 successful calls.

- I've noticed in my production widget that shortening the size of the response, makes the null problem disappear.

- the null response always occurs with a readystate=4 and status = 200

- When running the widget in debug mode in eclipse, in the XmlHttpView tab, when the null problem happens, there is an entry in the XmlHttp Request tab, but NO corresponding entry in the XMlHttpResponse tab.

-when the null response does NOT happen, there are corresponding entries in both tabs

 

Local Environment:

Widget Packager SDK Beta 3 (also in Betas 1 and 2)

MDS/Email Simulator 4.1.4

OS of the 9500 simulator is 5.0.0.451

OS of the 9700 simulator is 5.0.0.442

OS of the 9550 simulator is 5.0.0.334

OS of the 9500 simulator is 5.0.0.252

Java 1.6

Windows Vista Business 32 bit

 

Server Enviroment:

Windows Vista Business 32 bit

Java 1.6

Sun GlassFish 2.1

 

Any help is greatly appreciated.

 

Thanks

 

Developer
Posts: 26
Registered: ‎01-13-2010
My Device: 8330
My Carrier: Telus

Re: Random null response in Ajax request

Also note, the same piece of code works when deployed to a server and accessed via the Blackberry Browser on the above listed simulators.

Contributor
Posts: 13
Registered: ‎12-26-2008
My Device: Not Specified

Re: Random null response in Ajax request

I am having the same problem. For loading smaller pages, the responseText is null about half of the time, but if I try to load a large page, it is null almost all of the time. 

 

My code does not work in a browser because I am fetching data from a cross-domain source, so it gives my a cross-domain error. And I can't write my own server side code for this project, so I need to be able to fetch data from another server directly from my blackberry. 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Random null response in Ajax request

The development and testing team came back with some results.  One finding is that the JavaScript string has a max length of 512KB.  So if your return data is longer than 512KB and you are trying to access the responseText it may return null.

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Developer
Posts: 26
Registered: ‎01-13-2010
My Device: 8330
My Carrier: Telus

Re: Random null response in Ajax request

Hi Tim,

 

I checked the raw response was from my web service using a simple java program which reads data via a socket and counts the bytes. The response I'm getting random nulls with, including http headers and body is 514 BYTES, well below the threshold of 512 KB. Any other thoughts?

 

Thanks

 

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Random null response in Ajax request

Are you running on a network that uses a Proxy?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Developer
Posts: 26
Registered: ‎01-13-2010
My Device: 8330
My Carrier: Telus

Re: Random null response in Ajax request

Hi Tim,

 

We are not using a proxy. Along with that, the simulator's browser works perfectly when connecting to resources. If i deploy the html from my widget to the same web server running my web services and access the page via the simulator's browser, I have no problems either.

 

Thanks

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Random null response in Ajax request

Can you check to see if you have the same scenario if you do the following:

 

- run the device simulator

- don't run MDS

- configure the WiFi on the simulator and use the Hotspot browser.

 

This will give more of an apples to apples comparison.. for a test

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Developer
Posts: 26
Registered: ‎01-13-2010
My Device: 8330
My Carrier: Telus

Re: Random null response in Ajax request

Hey Tim,

 

Performed the tasks as you said on a (9700) 5.0.0.422 simulator using wifi/hotspot browser. The random null did NOT present it self. I ran the tests more the triple the amount of times it usually takes for it to pop up in the widget.

 

Also, when I finished that test, I deployed the widget on the simulator, utlized the wifi connection and the null problem occured.

 

Thanks

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Random null response in Ajax request

thanks nrizz!!

 

This is great information, and I will provide it to our testing team to see if we can come up with something further.  If at all possible, if you could forward some code that would reproduce the problem to our devsupport@rim.com group it would greatly help us get to the bottom of the issue.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter