03-23-2010 04:49 PM - edited 03-23-2010 04:57 PM
Hi!
We have developed simple BlackBerry Widget (on Widget SDK Beta 3) that uses web-services. Calls to web-services are done with AJAX technique (XMLHttpRequest). During the development of application we came accross couple of issues and maybe someone could help us to clarify things ![]()
1) We weren't able to send requests with "Authentication" header. Header is added to request in code, but it seems not to be included when request is sent. Is it related to https://www.blackberry.com/jira/browse/WEBAPI-21 issue?
2) XMLHttpRequest object doesn't seem to work well with large data. As we have observed - if XMLHttpRequest object receives large XML in response, it stops processing after first portion of data. Here is sample code snippet:
var request = new XMLHttpRequest();
request.open("POST", "http://some-url", true);
request.onreadystatechange = function() {
alert(this.readyState + ": " + this.responseText.length);
};
/* assume that response to this request is 6806 bytes long */
request.send(some_xml);
Running this code in FireFox will produce following alerts:
1: 0
2: 0
3: 2820
3: 5640
3: 6806
4: 6806
Running this code as BlackBerry Widget results in:
1: 0
2: 0
3: 2048
Obviously for BlackBerry Widget XMLHttpRequest stops processing too fast. Did anyone had such problem? And what could be the reason for such behavior?
P.S.
When will be next version of Widget SDK available?
Thanks in advance!
03-25-2010 11:39 AM
Hi Guligo,
Thanks for your post. Let me answer your questions:
1) Yes, likely the reason why you are not seeing the Authentication header is due to this outstanding defect. I will update that issue tracker item when information becomes available about when this fix has been made. In the meantime, you can vote / follow it to stay up to date on it's progress.
2) I believe you may be missing some headers in your POST AJAX code. Ensure that the 'Content-type" and 'Content-length" headers are being sent. Try this:
var request = new XMLHttpRequest();
request.open("POST", "http://some-url", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.onreadystatechange = function() {
alert(this.readyState + ": " + this.responseText.length);
};
/* assume that response to this request is 6806 bytes long */
request.send(some_xml);
If you haven't done so already, I'd recommend checking out the XmlHttpRequest view window that is available to you through the BlackBerry Web Plug-in. This window lets you see the request and response data that is sent as part of XHR communication.
Cheers,
Adam
03-25-2010 10:03 PM
Also, there is a maximum JavaScript string length that is 512KB in size.
03-30-2010 12:54 PM - edited 03-30-2010 12:56 PM
Thanks for your responses!
As you proposed, I have tried to add 'Content-type' and 'Content-length' headers to request, but that gave no result. String size of XML response is only ~7000 bytes long, so that's not the problem.
Also have checked out XmlHttpRequest View in Eclipse. Under XmlHttp Requests tab there are all requests that application has sent, but under XmlHttp Response tab not all the responses are shown (the ones with large data aren't). However they definetely are sent back, because I have done request/response tracing on TCP level.
03-31-2010 10:48 AM - edited 03-31-2010 10:48 AM
Hi guligo,
Having a similar problem. You may want to checkout and/or keep an eye on these threads in case the issue is related:
What technology stack are you utilizing on your server side?
Thanks
04-01-2010 07:10 AM
Hi nrizz,
Tnx for the links! Will definetly subscribe for those threads...
First we used Google App Engine for server-side. Web-application itself is written in Java and I think Google Apps uses Jetty as web-server. We use no JSPs or other dynamic web-pages and in general all responses are generated from Java code.
Recently we re-wrote server-side so that it could be deployed on SAP NetWeaver.
04-01-2010 02:11 PM - edited 04-01-2010 02:13 PM
Hi Everyone,
We have been trying to get to the bottom of this. This is what we have tried so far:
1) Created a server side web page that randomly returns different lengths of data on each request
2) Created a client that uses AJAX to call this URL and then check the resultant string to ensure that it AJAX result is not null
3) Run this test in a loop for a thousand or so iterations
04-01-2010 02:37 PM
Another thought we had from one of our groups was that there may be some special characters in the returned data that is causing some kind of issue.
As you are running your tests, can you see if there is a relationship between some kind of special character in the return data and the null response?
04-06-2010 05:47 PM
Hi tneil,
Here is information about my dev-environment:
- Windows XP Professional SP2 (32bit version);
- BlackBerry Widget SDK 1.0 Beta 3;
- OS 5.0 (9000, 9500).
So far I haven't noticed any relationship between special characters and return data (have thought about it already before). However will try to check again, maybe will find something suspicious...
Thanks!
04-06-2010 06:05 PM - edited 04-06-2010 06:09 PM
Hi Tim,
Heres the info as requested:
Windows Vista Business 32-bit Service Pack 2
BlackBerry Widget SDK 1.0 Beta 3;
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
Have you guys tried a non-.net server? I noticed that guligo and I are both using Java to serve up our data. Did you receive my email to devsupport? And also, was that you guys pinging my server like crazy ![]()
Thanks!