3

Making an HTTP Request on BlackBerry

Posted by jason on Oct 6, 2009 in BlackBerry

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.

BlackBerry MDS

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.

TCP Stack

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";

Wi-Fi

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";

WAP 1.x

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";

WAP 2.0

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;

Going Forward

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.

 
0

Blackberry development environment

Posted by jason on Oct 5, 2009 in BlackBerry

Blackberry applications are written in Java.  Since the java mantra is write once, test everywhere.  er.  sorry, run everywhere.  You would think that you could choose whatever OS you would like to develop for the Blackberry.  While the documentation claims you can write Blackberry code on any platform, the reality for a new developer is quite different.  The Eclipse plugin they offer only runs on Windows.  Very irritating considering I can run eclipse on my Mac as well as my Windows machine.  Rather than fight it, I am going with the flow and using Windows XP 32bit inside my Parallels virtual machine.

Very important that you pay attention to the version of eclipse that the plugin works with.  I didn’t and installed the lastest eclipse (3.5 as I write this).  I went to “Help > install new software…” using “http://www.blackberry.com/go/eclipseUpdate”.  I got the following error:

Cannot complete the install because one or more required items could not be found.
  Software being installed: BlackBerry JDE Plug-in for Eclipse 1.0.0.67 (net.rim.EclipseJDE.feature.group 1.0.0.67)
  Missing requirement: BlackBerry JDE Plug-in for Eclipse 1.0.0.67 (net.rim.EclipseJDE.feature.group 1.0.0.67)
  requires 'org.eclipse.debug.ui [3.4.0,3.5.0)' but it could not be found

I had to download the gannymede 3.4.2 version of eclipse and install it.  Then I did the software update using the http://www.blackberry.com/go/eclipseUpdate URL.  It prompted me half a dozen times for my Blackberry Developer zone ID.  I dutifully entered it each time (annoying).  After this, I had a working environment.

In the BlackBerry JDE Plug-in for Eclipse Installation and Configuration demo video, They show configuring the BlackBerry workspace.  Well, this option is not enabled until you created a BlackBerry project.  Also in this video, you will see them run the simulator just by clicking run.  This did not work for me.  In order to actually launch the application in the simulator, you need to right click the project and select “Activate for Blackberry”.  If you don’t do this, Eclipse will launch the simulator and you will see debug output, but your project will not show up on the device.

The next step is to get it working on an actual BlackBerry device.  When I first attempted this, it would not work with my old version of parallels.  I updated to the latest build of parallels and then Windows could recognize the USB device.  My mac took control and parallels did not prompt me like it usually does when I connect a USB device.  There is an icon in the lower right of the frame.  Click the USB icon there and select “Research in Motion”

I haven’t been able to get the Eclipse IDE to install and run the application on my device.  I’ve had to use the tool JavaLoader.exe which is located in the bin directory of your JDE installation.

JavaLoader.exe -usb load HelloWorld.jad
JavaLoader.exe -usb erase -f HelloWorld.jad

These commands will install and remove your application.  This assumes that the bin directory is in your path and you are in the location where your *.jad and *.cod file.

 
0

Install MySql5 on Snow Leopard using MacPorts

Posted by admin on Oct 1, 2009 in MySQL

Install MacPorts before you do anything.

Install MySQL5

sudo port install mysql5
sudo port install mysql5-server 
sudo -u mysql mysql_install_db5

Secure MySQL5

To secure your MySQL5 installation, you can either change the password manually like so:

/opt/local/lib/mysql5/bin/mysqladmin -u root password {new-password}

or on a production system, you can run the secure script and not only change the password, but remove anonymous access and prevent remote root login.

/opt/local/lib/mysql5/bin/mysql_secure_installation

To start the MySQL daemon, type:

sudo /opt/local/lib/mysql5/bin/mysqld_safe &

or to make sure MySQL5 is launched at startup every time:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

Create a symbolic link

sudo ln -s /opt/local/bin/mysql5 /opt/local/bin/mysql

Test the installation

mysql -u root -p

It should prompt you for a password and you should see the “mysql>” prompt

Copyright © 2010 programming with passion All rights reserved. Theme by Laptop Geek.