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

Java Development

Reply
New Contributor
Posts: 7
Registered: ‎07-11-2012
My Device: BlackBerry Bold 9000
My Carrier: Mobily
Accepted Solution

HttpConnection works on WiFi but not 3G

[ Edited ]

Hi,

 

I am having the strangest issue. I have an application that connects to a remote server. Here are the use cases:

 

User Case #1:

  1. Install the app
  2. Insure WiFi is ON
  3. Start the app
  4. Press Submit => Works!!

User Case #2:

  1. Install the app
  2. Insure 3G connection is ON
  3. Start the app
  4. Press Submit => Works!!

User Case #3:

  1. Install the app
  2. Insure WiFi is ON
  3. Start the app
  4. Submit => Works!!
  5. Close the app
  6. Turn off WiFi and Insure 3G connection is ON
  7. Start the app => Fails!!

The application hangs on the red statement below then throws a Timeout error.

 

...

ConnectionFactory connFactory = new ConnectionFactory();

conn = connFactory.getConnection(serverURL);

...

 

Does anyone have the slightest clue why this could happen? I could not find any reasonable explanation to it except being a bug.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HttpConnection works on WiFi but not 3G

There is only one WiFi connection possible, but there are numbers of ways a wireless connection can connect and various carriers support various methods which further confuses.

 

You need to review the Networking Video:

http://supportforums.blackberry.com/t5/Java-Development/Networking-Transports-II/ta-p/446742

 

and the following KB article:

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

 

to understand the complexities.  Using the ConnectionFactory overcomes some of the complexities but not all.

 

In general I recommend that determine which connection option the ConnectionFactory is using in all cases and log that in case of errors.

 

In this case, it appears you are not getting a connection.  Are you trying for a secure connection (Https)?

New Contributor
Posts: 7
Registered: ‎07-11-2012
My Device: BlackBerry Bold 9000
My Carrier: Mobily

Re: HttpConnection works on WiFi but not 3G

[ Edited ]

Hi Peter,

 

Thank you for your swift response. Yes the server URL starts with HTTPS.

 

I have already reviewed all the documentation you have mentioned in your post. I tried using both the ConnectionFactory class and manually appending a connection string to the URL. Both yeilded the same result. Here is the getConnectionString() method we are using:

 

/**
 * Gets the connection string needed for HTTP connections.
 * @return The connection string.
 */
public static String getConnectionString(){
    
    // read the coverage type
    boolean isSimulator = DeviceInfo.isSimulator();
    boolean isWifi = WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED;
    boolean isMDS = (CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS;
    boolean isDirect = (CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT;
    boolean noCoverage = CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE;
    
    // get the connection string
    String connectionString="";
    if ( isSimulator ) {
        connectionString = ";deviceside=false";
    } else if( isWifi ){
        connectionString=";interface=wifi";
    } else if( isMDS ){
        connectionString = ";deviceside=false";
    } else if( isDirect ){
        String carrierUid=getCarrierBIBSUid();
        if(carrierUid == null) {
            connectionString = ";deviceside=true";
        } else {
            connectionString = ";deviceside=false;ConnectionUID="+carrierUid + ";##REMOVED##"; 
        }
    } else if( noCoverage ) {
        connectionString = "";
    } else {
        connectionString = ";deviceside=true";
    }
    
    // return the connection string
    return connectionString;
}

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HttpConnection works on WiFi but not 3G

The problem with https is that the session is actually started on the open, which for connection factory means that you don't get to know which method it has chosen before it attempts to connect.

 

But the usual reason for a timeout is an incorrect choice or the data connection is not supported, so I would download the network diagnostics code from here:

http://supportforums.blackberry.com/t5/Java-Development/What-Is-Network-API-alternative-for-legacy-O...

 

Test this on the failing device and figure out what options you actually have available.  Then review the transport options that ConnectionFactory is using and see if there is a mismatch.

New Contributor
Posts: 7
Registered: ‎07-11-2012
My Device: BlackBerry Bold 9000
My Carrier: Mobily

Re: HttpConnection works on WiFi but not 3G

I agree with you when using the ConnectionFactory, but if I use the connection string, for example ";interface=wifi", the device will use the TCP WiFi transport I am specifing. Right?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HttpConnection works on WiFi but not 3G

Correct.

New Contributor
Posts: 7
Registered: ‎07-11-2012
My Device: BlackBerry Bold 9000
My Carrier: Mobily

Re: HttpConnection works on WiFi but not 3G

Many thanks. So to the best of your knowledge, what could cause this statement to throw a timeout exception:

 

conn = (HttpConnection)Connector.open(serverURL, Connector.READ_WRITE, true);

 

Keeping in mind that serverURL contains the connection string strictly specifing the transport to be used.

New Contributor
Posts: 7
Registered: ‎07-11-2012
My Device: BlackBerry Bold 9000
My Carrier: Mobily

Re: HttpConnection works on WiFi but not 3G

When I used theNetworkDiagnostics application to test the server URL manually from the "dreaded device" we got the following results:

 

  1. Default FAILED (HTTP 400)
  2. TCP Cellular FAILED (Timeout)
  3. MDS FAILED (HTTP 400)
  4. BIS-B SUCCESS
  5. WAP FAILED
  6. WAP2 SUCCESS
  7. WiFi SUCCESS

Any comments?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: HttpConnection works on WiFi but not 3G

These look perfectly normal to me.  I'm confessed as to the timeout. If I am understanding you correctly ConnectionFactory and directly coding the extension fails for your URL, but works OK using the Network Diagnostic.  For example, if you directly code ";interface=wifi" using your URL, it times out on this device only, works fine on other devices, and the network diagnostic says WiFi is OK. Is this a fair statement? 

Highlighted
New Contributor
Posts: 7
Registered: ‎07-11-2012
My Device: BlackBerry Bold 9000
My Carrier: Mobily

Re: HttpConnection works on WiFi but not 3G

[ Edited ]

Finally, after long hours of debugging and testing. I have discovered that the issue is network related and have nothing to do with the device. I ended up using the connection string as follows. I hope this helps anyone facing a similar problem and saves long hours of debugging.

 

/**
 * Gets the connection string needed for HTTP connections.
 * @return The connection string.
 */
public static String getConnectionString(){
    
    // read the coverage type
    boolean isSimulator = DeviceInfo.isSimulator();
    boolean isWifi = WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED;
    boolean isMDS = CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS);
    boolean isBIS = CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_BIS_B);
    boolean isDirect = CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_DIRECT);
    boolean noCoverage = CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE;
    
    // get the connection string
    String connectionString="";
    if ( isSimulator ) {
        connectionString = ";deviceside=false";
    } else if( isWifi ){
        connectionString=";interface=wifi";
    } else if( isBIS ) {
        connectionString = ";deviceside=false;##REMOVED##"; 
    } else if( isMDS ){
        connectionString = ";deviceside=false";
    } else if( isDirect ){
        String carrierUid=getCarrierBIBSUid();
        if(carrierUid == null) {
            connectionString = ";deviceside=true";
        } else {
            connectionString = ";deviceside=false;ConnectionUID="+carrierUid + ";ConnectionType=mds_public"; //replace underscore with -
        }
    } else if( noCoverage ) {
        connectionString = "";
    } else {
        connectionString = ";deviceside=true";
    }
    
    // return the connection string
    return connectionString;
}

 

Thank you for your assistance peter. You have given a handful of helpful advices.