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

Java Development

New Contributor
Posts: 2
Registered: ‎05-20-2011
My Device: 9780
My Carrier: NA Simulator currently

HTTPConnection java.io.IOException

Hi all,


Been struggling for ages to get a 'reliable' HTTPConnection object. I quite often find (intermitant, just seems to start doing it sometimes) that there is a java.io.IOException when using the HTTPConnection class.


For reference purposes, my first attempt at doing a HTTPConnection was using the following code :


ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(strAddress);
if (connDesc == null) {
   WebCallError = "No connection available.";
   return false;
HttpConnection http;
http = (HttpConnection)connDesc.getConnection();


but the connDesc object would randomly start coming back null. And the only way to get it working again would be to take the Blackberry battery out and reboot the Blackberry (I was closing the HTTPConnection properly after each use).


So, I then did a lot of reading and discovered you could use old methods of getting an HTTPConnection by attaching the correct 'string' on the end of an address which is effectively what the ConnectionFactory should be doing for me I guess.


I used the following code (sorry for not referencing other peoples code, I have got these bits from all over the place) :


            String strConnect;
            strConnect = GetConnectionString();
            if ((strConnect == "NONE") || (strConnect == "UNKNOWN"))
            	WebCallError = "No connection available.";
            	return false;
            HttpConnection http = (HttpConnection)Connector.open(strAddress + strConnect);

private static String GetConnectionString()
    	if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
            Globals.addtolist("WEB", "WLAN connected.");
             return ";interface=wifi";
         } else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT)
             Globals.addtolist("WEB", "Carrier coverage.");
             String carrierUid = getCarrierBIBSUid();
             if (carrierUid == null)
                 // Has carrier coverage, but not BIBS.  So use the carrier's TCP network
             	Globals.addtolist("WEB", "No Uid, so settings deviceside=true;");
             	return ";deviceside=true";
             } else {
                 // otherwise, use the Uid to construct a valid carrier BIBS request
             	Globals.addtolist("WEB", "uid is: " + carrierUid);
                return ";deviceside=false;connectionUID=" + carrierUid + ";";
         } else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS)
         	Globals.addtolist("WEB", "MDS coverage found");
            return ";deviceside=false";
         } else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
         	Globals.addtolist("WEB", "There is no available connection.");
         	return "NONE";
         } else {
        	return "UNKNOWN";
    private static String getCarrierBIBSUid()
        ServiceRecord[] records = ServiceBook.getSB().getRecords();
        int currentRecord;
        for(currentRecord = 0; currentRecord < records.length; currentRecord++)        
        {             if(records[currentRecord].getCid().toLowerCase().equals("ippp"))            
        {                 if(records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0)
                    return records[currentRecord].getUid();
        return null;

 This code will eventually start getting an error of java.io.IOException (in the same fashion as the ConnectionFactory starting producing a NULL connDescriptor.


I am starting to give up a bit with Blackberry, it seems very difficult to just 'use a HTTP connection' and I have seen lots of other people having the same problems but no real code to solve the problem anywhere. Just links to 'help' documents which aren't of much help, and links given to other documents which equally don't have code on to just 'make a HTTP connection' Smiley Happy


Throughout all of my problems it is worth mentioning that the 'Browser' application does work and I could access the internet and the address I was trying to connect to without any problems.


Thank you for any help in advance.