Seems like it is rather complex to make a simple HTTP request on BlackBerry. The code for opening a connection is straightforward:
String url = "http://10.0.0.1";
HttpConnection conn = conn = (HttpConnection)Connector.open(url);
The complexity comes in because I am developing on a BlackBerry device without service. When I try to execute the above code, I get an IOException stating “Tunnel failed”. From searching, it appears that I get this message because APN is not set. I can not set it because I do not have service for this phone. If you don’t have the APN set, it does not automatically try and use the WIFI connection. Apparently there are six different methods for using a connection. Each one of these requires a different string appended to the URL to determine which one gets used.
The first method is using BlackBerry MDS. This forces all traffic to go through the BlackBerry enterprise server. It encrypts all traffic using AES or Triple DES. My task is to specifically avoid using the MDS because we are creating a cloud service where the customer does not need to have any server let alone a BlackBerry enterprise server.
String url = "http://10.0.0.1;deviceside=false";
BlackBerry Internet Service
The second method is to use the BlackBerry Internet Service. This is only available to approved BlackBerry Alliance Program members. There are different tiers. The public tier which is free does not offer the BlackBerry Internet service feature. The minimum tier that supports this is the BlackBerry Alliance Associate Member which costs $2,000/yr and requires 45 member points. To get this, you basically have to make losts of money using the BlackBerry platform or promot it in other ways. You can look at their FAQ for more details, but basically we don’t have this option available to me right now.
The third method is to use the TCP stack directly. In order to use this, you need to have the APN username and password.
String url = "http://10.0.0.1;deviceside=true";
The fourth method is to use wi-fi. This is what I’m interested in right now.
String url = "http://10.0.0.1;interface=wifi";
The fifth method is to use WAP 1.x gateway. This is supported over the carriers networks. You have to contact the carriers to get a list of their WAP gateway parameters.
String url = "http://10.0.0.1;WAPGatewayIP=127.0.0.1;WAPGatewayAPN=carrier.com.gprs";
The sixth way is to use WAP 2.0. You need to loop through the records and find the uid of the desired ServiceRecord in the ServiceBook. This is simpler than WAP 1.x because you don’t need all the gateways and settings from the carriers. This is supported as of 4.2 on the BlackBerry.
// String uid = get from the device
String url = "http://10.0.0.1;ConnectionUID=" + uid;
I would really like the device to try wi-fi first before attempting to use the potentially expensive data plan. I am going to have to write some code to test the wi-fi first, and then attempt the data connection if this fails. It is conceivable that the user wouldn’t want the app to transmit unless the wi-fi connection is available. Not as simple as just opening up a connection and firing off a GET request.