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
nrizz
Posts: 26
Registered: ‎01-13-2010
My Device: 8330
Accepted Solution

Ajax Troubles after Beta 3

[ Edited ]

Hi,

 

I recently installed the beta 3 SDK. Afterwhich, the widget I had built under Beta 2 stopped functioning. After some digging it appears that the piece that broke is the Ajax requests.

 

The Error:

The response comes back with a 500 error and a responseText telling me the url is not found in my config.xml when it is.

 

The Ajax requests are made to a server which renders XML based on the GET parameters in the URL.The server is running a J2EE app, the xml 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. The request is made to the following address:

 

http://windev3:8080/WebServiceConsumer/MobileWebService.do

 

The request is made as follows, the runDiagnostics is hooked up to an onclick event in a button:

 

 

var req;

function runDiagnostics() {
try {
var url = "http://windev3: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);
   }
}

 

 

The server returns text with diagnostic information. When running the widget code in a regular web browser (Firefox), everything works as expected. However, when I run it as a widget in the simulator, it fails. I've tried all the following settings in my config.xml

 

Attempt 1: Fails with error specified above

 <access subdomains="true" uri="http://windev3"/>

All <feature>s added to <access> elements

 

Attempt 2: Fails with error specified above

 <access subdomains="true" uri="http://windev3"/>

No <feature>s added to <access> elements

 

Attempt 3: Fails with error specified above

 <access subdomains="false" uri="http://192.168.2.203"/>

No <feature>s added to <access> elements

 

Attempt 4: Fails with error specified above

 <access subdomains="false" uri="http://192.168.2.203:8080"/>

No <feature>s added to <access> elements

 

Attempt 5: Fails with error specified above

 <access subdomains="false" uri="http://windev3:8080/webServices/runDiagnostics.do"/>

No <feature>s added to <access> elements

 

Attempt 6: Partial Success

  <access subdomains="true" uri="*"/>

 

The ready state is 4, response code is 200. response text is "null" the first few times I make the request but by the 4th or 5th request the desired text is seen. I've actually had this issue while working under Beta 2.

 

Local Environment:

Widget Packager SDK Beta 3

MDS/Email Simulator 4.1.4

Java 1.6

Most recent 9700 and 9500 simulators

Windows Vista Business 32bit

 

Server Enviroment:

Windows Vista Business 32bit

Java 1.6

Sun GlassFish 2.1

 

Any help is greatly appreciated.

 

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Ajax Troubles after Beta 3

Hi nrizz,

 

Have you tried the following access element:

 

 

<access subdomains="true" uri="http://windev3:8080" />

 

Can you also list the OS version being used by the simulators.

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
nrizz
Posts: 26
Registered: ‎01-13-2010
My Device: 8330

Re: Ajax Troubles after Beta 3

[ Edited ]

Hi Tim,

 

I tried it a few times with the setting you suggested. (with and without a trailing '/'). And received the following in the statusText and responseText respectively.

 

"Error selecting resource http://windev3:8080/WebServiceConsumer/MobileWebService.htm?action=runDiagnostics&pin=2100000a"

 

"Could not select proper transport descriptor for http://windev3:8080/WebServiceConsumer/

MobileWebService.htm?action=runDiagnostics&pin=2100000a"

 

readystate 4

status 500

 

OS of the 9500 is 5.0.0.451

OS of the 9700 is 5.0.0.442

 

Also note that I tried with the IP address/port combination again and had partial success. It still get random "null" responses in the responseText when the readystate is 4 and response Code is 200.

 

After this I reconfirmed with JUST the IP address and no port and it says it is not found in my config.xml

 

Thanks for the quick reply

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Ajax Troubles after Beta 3

Interesting...

 

Have you changed the default transport order list?  If you have can you post what your transport order list currently is?  

 

Thanks

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
nrizz
Posts: 26
Registered: ‎01-13-2010
My Device: 8330

Re: Ajax Troubles after Beta 3

Hi Tim,

 

I haven't changed the order. The option to override the connection order is unchecked, the fields are greyed out.

 

As an example, here the raw xml of a setup that gives me the partial success as described in my previous post.

 

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0.0">
  <name>BugWidget</name>
  <author href="www.company.com">Company</author>
  <access subdomains="true" uri="http://192.168.2.203:8080"/>
  <content src="index.htm"/>
</widget>

For these tests, I've basically only tweaked the access-uri element via the eclipse property editor.

 

 Thanks

 

Please use plain text.
New Developer
bbswede
Posts: 10
Registered: ‎12-02-2009
My Device: Not Specified

Re: Ajax Troubles after Beta 3

I have seen the same error message in the simulator when trying to access web resources from a Widget. I suspected the problem was caused by running the simulator behind a proxy, see the following post:

 

http://supportforums.blackberry.com/t5/Web-Development/Widget-in-simulator-can-not-access-web-resour...

 

BR,

/olle

Please use plain text.
Developer
nrizz
Posts: 26
Registered: ‎01-13-2010
My Device: 8330

Re: Ajax Troubles after Beta 3

[ Edited ]

Hi   bbswede,

 

Thanks for the reply. It got me thinking. We do not have a proxy server but we do have a domain. After trying a few settings, it appears that using the fully qualified domain name WITH the port number works.

 

For future people who may read this thread. The following assumes that the remote resource you are trying to access is on a specific port. I'm not sure if this applies when using the default 80.

 

 

http://computerName.domain.com:port - works

http.//xxx.xxx.xxx.xxx:port - works


http://computerName.domain.com - does not work

http.//xxx.xxx.xxx.xxx- does not work

 

 

 

computerName - the network name of a computer

domain.com - is the domain the computer is on

xxx.xxx.xxx.xxx the IP address of the resource you are trying to use

 

Some final questions for the RIM team. Will including the port in the <access> be a continued practice in future releases?

 

Is the random null responseText I am getting related to this or some other issue? Should I start a new thread with this issue.

 

Thanks

 

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Ajax Troubles after Beta 3

If the port number is something other than port 80 then it will be required to specify it in the access element.

 

I would suggest opening up another thread around the random null response.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.