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
Regular Contributor
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl
Accepted Solution

Application not work without wifi connection

hello i have problem with http connection

 

my code is

 

public class HttpConnectionFactory 
{

	/**
	 * Specifies that only wifi should be used
	 */
	public static final int TRANSPORT_WIFI = 1;

	/**
	 * Specifies that only BES (also known as MDS or corporate servers)
	 */
	public static final int TRANSPORT_BES = 2;

	/**
	 * Specifies that only BIS should be used (Basically RIM hosted BES)
	 */
	public static final int TRANSPORT_BIS = 4;

	/**
	 * Specifies that TCP should be used (carrier transport)
	 */
	public static final int TRANSPORT_DIRECT_TCP = 8;

	/**
	 * Specifies that WAP2 should be used (carrier transport)
	 */
	public static final int TRANSPORT_WAP2 = 16;

	/**
	 * Equivalent to: TRANSPORT_WIFI | TRANSPORT_BES | TRANSPORT_BIS |
	 * TRANSPORT_DIRECT_TCP | TRANSPORT_WAP2
	 */
	public static final int TRANSPORTS_ANY = TRANSPORT_WIFI | TRANSPORT_BES
			| TRANSPORT_BIS | TRANSPORT_DIRECT_TCP | TRANSPORT_WAP2;

	/**
	 * Equivalent to: TRANSPORT_WIFI | TRANSPORT_BES | TRANSPORT_BIS
	 */
	public static final int TRANSPORTS_AVOID_CARRIER = TRANSPORT_WIFI
			| TRANSPORT_BES | TRANSPORT_BIS;

	/**
	 * Equivalent to: TRANSPORT_DIRECT_TCP | TRANSPORT_WAP2
	 */
	public static final int TRANSPORTS_CARRIER_ONLY = TRANSPORT_DIRECT_TCP
			| TRANSPORT_WAP2;

	/**
	 * The default order in which selected transports will be attempted
	 * 
	 */
	public static final int DEFAULT_TRANSPORT_ORDER[] = { // TRANSPORT_DIRECT_TCP
	// ,TRANSPORT_WAP2
			TRANSPORT_WIFI,
			// TRANSPORT_BES, TRANSPORT_BIS,
			// TRANSPORT_WAP2,
			TRANSPORT_DIRECT_TCP };

	private static final int TRANSPORT_COUNT = DEFAULT_TRANSPORT_ORDER.length;

	private static ServiceRecord srMDS[], srBIS[], srWAP2[], srWiFi[];
	private static boolean serviceRecordsLoaded = false;

	private int curIndex = 0;
	private int curSubIndex = 0;
	// private String url;
	private final String extraParameters;
	private final int transports[];
	private int lastTransport = 0;

	/**
	 * Equivalent to
	 * <code>HttpConnectionFactory( url, null, HttpConnectionFactory.DEFAULT_TRANSPORT_ORDER )</code>
	 * 
	 * @see #HttpConnectionFactory(String, String, int[])
	 * @param url
	 *            See {@link #HttpConnectionFactory(String, String, int[])}
	 */
	public HttpConnectionFactory() {
		this(null, 0);
	}

	/**
	 * Equivalent to
	 * <code>HttpConnectionFactory( url, null, allowedTransports )</code>
	 * 
	 * @see #HttpConnectionFactory(String, String, int)
	 * @param url
	 *            See {@link #HttpConnectionFactory(String, String, int)}
	 * @param allowedTransports
	 *            See {@link #HttpConnectionFactory(String, String, int)}
	 */
	public HttpConnectionFactory(int allowedTransports) {
		this(null, allowedTransports);
	}
	public HttpConnectionFactory(int transportPriority[]) {
		this(null, transportPriority);
	}

	public HttpConnectionFactory(String extraParameters, int allowedTransports) {
		this(extraParameters, transportMaskToArray(allowedTransports));
	}
	public HttpConnectionFactory(String extraParameters,
			int transportPriority[]) {
		if (!serviceRecordsLoaded) {
			loadServiceBooks(false);
		}
		//
		// if (url == null) {
		// throw new IllegalArgumentException("Null URL passed in");
		// }
		// if (!url.toLowerCase().startsWith("http")) {
		// throw new IllegalArgumentException("URL not http or https");
		// }
		//
		// this.url = url;
		this.extraParameters = extraParameters;
		transports = transportPriority;
	}
	public Connection getNextConnection(String url)
			throws NoMoreTransportsException {
		Connection con = null;
		int countsWap = 0;
		int countsBis = 0;
		int countsBes = 0;
		int curTransport = 0;
		while (con == null && curIndex < transports.length) {
			System.out.println("con=" + con + " curid=" + curIndex);
			curTransport = transports[curIndex];
			switch (curTransport) {
			case TRANSPORT_WIFI:
				curIndex++;
				curSubIndex = 0;
				try {
					con = getWifiConnection(url);
				} catch (Exception e) {
				}
				break;
			case TRANSPORT_BES:
				curIndex++;
				curSubIndex = 0;
				try {
					if (countsBes > 3) {
						throw new NoMoreTransportsException();
					}
					con = getBesConnection(url);
					countsBes++;
				} catch (Exception e) {
				}
				break;
			case TRANSPORT_BIS:
				while (con == null) {
					try {
						if (countsBis > 3) {
							throw new NoMoreTransportsException();
						}
						con = getBisConnection(url, curSubIndex);
						countsBis++;
					} catch (NoMoreTransportsException e) {
						curIndex++;
						curSubIndex = 0;
						break;
					} catch (Exception e) {
					}
				}
				break;
			case TRANSPORT_DIRECT_TCP:
				curIndex++;
				try {
					con = getTcpConnection(url);
				} catch (Exception e) {
				}
				break;
			case TRANSPORT_WAP2:
				while (con == null) 
				{
					// try {
					// if (countsWap > 3) {
					// throw new NoMoreTransportsException();
					// }
					// // con = getWap2Connection(url, curSubIndex);
					// countsWap++;
					// } catch (NoMoreTransportsException e) {
					// curIndex++;
					// curSubIndex = 0;
					// break;
					// } catch (Exception e) {
					// }
				}
				break;
			}
		}
		if (con == null) {
			throw new NoMoreTransportsException();
		}

		lastTransport = curTransport;
		return con;
	}

	public Connection getCurrentConnection(String url)
			throws NoMoreTransportsException {
		Connection con = null;
		switch (lastTransport) {
		case TRANSPORT_WIFI:
			try {
				con = getWifiConnection(url);
			} catch (Exception e) {
			}
			break;
		case TRANSPORT_BES:
			try {
				con = getBesConnection(url);
			} catch (Exception e) {
			}
			break;
		case TRANSPORT_BIS:
			while (con == null) {
				try {
					con = getBisConnection(url, curSubIndex);
				} catch (NoMoreTransportsException e) {
					break;
				} catch (Exception e) {
				}
			}
			break;
		case TRANSPORT_DIRECT_TCP:
			try {
				con = getTcpConnection(url);
			} catch (Exception e) {
			}
			break;
		case TRANSPORT_WAP2:
			while (con == null) {
				try {
					con = getWap2Connection(url, curSubIndex);
					System.out.println("" + con);
				} catch (NoMoreTransportsException e) {
					break;
				} catch (Exception e) {
				}
			}
			break;
		}

		return con;
	}

	/**
	 * Returns the transport used in the connection last returned via
	 * {@link #getNextConnection()}
	 * 
	 * @return the transport used in the connection last returned via
	 *         {@link #getNextConnection()} or 0 if none
	 */
	public int getLastTransport() {
		return lastTransport;
	}

	/**
	 * Generates a connection using the BIS transport if available
	 * 
	 * @param index
	 *            The index of the service book to use
	 * @return An {@link HttpConnection} if this transport is available,
	 *         otherwise null
	 * @throws NoMoreTransportsException
	 * @throws IOException
	 *             throws exceptions generated by {@link getConnection( String
	 *             transportExtras1, String transportExtras2 )}
	 */
	private Connection getBisConnection(String url, int index)
			throws NoMoreTransportsException, IOException {
		System.out.println("BIS Try");
		if (index >= srBIS.length) {
			throw new NoMoreTransportsException("Out of BIS transports");
		}
		ServiceRecord sr = srBIS[index];
		return getConnection(url, ";deviceside=false;connectionUID=", sr
				.getUid());
	}

	/**
	 * Generates a connection using the BES transport if available
	 * 
	 * @return An {@link HttpConnection} if this transport is available,
	 *         otherwise null
	 * @throws IOException
	 *             throws exceptions generated by {@link getConnection( String
	 *             transportExtras1, String transportExtras2 )}
	 */
	private Connection getBesConnection(String url) throws IOException {
		System.out.println("BES try");
		if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS)) {
			return getConnection(url, ";deviceside=false", null);
		}
		return null;
	}

	/**
	 * Generates a connection using the WIFI transport if available
	 * 
	 * @return An {@link HttpConnection} if this transport is available,
	 *         otherwise null
	 * @throws IOException
	 *             throws exceptions generated by {@link getConnection( String
	 *             transportExtras1, String transportExtras2 )}
	 */
	private Connection getWifiConnection(String url) throws IOException {
		System.out.println("wifi try");
		// if (RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)
		// && (RadioInfo.getActiveWAFs() & RadioInfo.WAF_WLAN) != 0
		// && CoverageInfo.isCoverageSufficient(1 /*
		// * CoverageInfo.COVERAGE_DIRECT
		// */,
		// RadioInfo.WAF_WLAN, false)) {
		//
		// return getConnection(";deviceside=true;interface=wifi", null);
		// // return getConnection(";deviceside=true;interface=wifi", null);
		//
		// }
		// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED
				&& srWiFi.length > 0) {
			return getConnection(url, ";interface=wifi", null);
		}
		return null;
	}

	/**
	 * Generates a connection using the WAP2 transport if available
	 * 
	 * @param index
	 *            The index of the service book to use
	 * @return An {@link HttpConnection} if this transport is available,
	 *         otherwise null
	 * @throws NoMoreTransportsException
	 *             if index is outside the range of available service books
	 * @throws IOException
	 *             throws exceptions generated by {@link getConnection( String
	 *             transportExtras1, String transportExtras2 )}
	 */
	private Connection getWap2Connection(String url, int index)
			throws NoMoreTransportsException, IOException {
		System.out.println("WAP2 try");
		if (index >= srWAP2.length) {
			throw new NoMoreTransportsException("Out of WAP2 transports");
		}
		if (CoverageInfo
				.isCoverageSufficient(1 /* CoverageInfo.COVERAGE_DIRECT */)) {
			ServiceRecord sr = srWAP2[index];
			return getConnection(url, ";ConnectionUID=", sr.getUid());
		}
		return null;
	}

	/**
	 * Generates a connection using the TCP transport if available
	 * 
	 * @return An {@link HttpConnection} if this transport is available,
	 *         otherwise null
	 * @throws IOException
	 *             throws exceptions generated by {@link getConnection( String
	 *             transportExtras1, String transportExtras2 )}
	 */
	private Connection getTcpConnection(String url) throws IOException {
		System.out.println("direct try");
		if (CoverageInfo
				.isCoverageSufficient(1 /* CoverageInfo.COVERAGE_DIRECT */)) {
			String extraParameter = null;
			if (!DeviceInfo.isSimulator()) {
				url = url + ";deviceside=true";
			}

			return getConnection(url, null, null);
			// ";deviceside=true", null);
		}
		return null;
	}

	/**
	 * Utility method for actually getting a connection using whatever transport
	 * arguments the transport may need
	 * 
	 * @param transportExtras1
	 *            If not null will be concatenated onto the end of the
	 *            {@link url}
	 * @param transportExtras2
	 *            If not null will be concatenated onto the end of {@link url}
	 *            after transportExtras1
	 * @return An {@link HttpConnection} built using the url and transport
	 *         settings provided
	 * @throws IOException
	 *             any exceptions thrown by {@link Connector.open( String name
	 *             )}
	 */
	private Connection getConnection(String url, String transportExtras1,
			String transportExtras2) throws IOException {
		StringBuffer fullUrl = new StringBuffer();
		fullUrl.append(url);
		if (transportExtras1 != null) {
			fullUrl.append(transportExtras1);
		}
		if (transportExtras2 != null) {
			fullUrl.append(transportExtras2);
		}
		if (extraParameters != null) {
			fullUrl.append(extraParameters);
		}
		// fullUrl.append(";ConnectionTimeout=5000");
		System.out.println(fullUrl.toString());
		return Connector.open(fullUrl.toString(), Connector.READ_WRITE, true);
	}

	/**
	 * Public method used to reload service books for whatever reason (though I
	 * can't think of any)
	 */
	public static void reloadServiceBooks() {
		loadServiceBooks(true);
	}

	/**
	 * Loads all pertinent service books into local variables for later use.
	 * Called upon first instantiation of the class and upload {@link
	 * reloadServiceBooks()}
	 * 
	 * @param reload
	 *            Whether to force a reload even if they've already been loaded.
	 */
	private static synchronized void loadServiceBooks(boolean reload) {
		if (serviceRecordsLoaded && !reload) {
			return;
		}
		ServiceBook sb = ServiceBook.getSB();
		ServiceRecord[] records = sb.getRecords();
		Vector mdsVec = new Vector();
		Vector bisVec = new Vector();
		Vector wap2Vec = new Vector();
		Vector wifiVec = new Vector();

		if (!serviceRecordsLoaded) {
			for (int i = 0; i < records.length; i++) {
				ServiceRecord myRecord = records[i];
				String cid, uid;
				// sometimes service record is disabled but works
				if (myRecord.isValid() /* && !myRecord.isDisabled() */) {
					cid = myRecord.getCid().toLowerCase();
					uid = myRecord.getUid().toLowerCase();
					// BIS
					if (cid.indexOf("ippp") != -1 && uid.indexOf("gpmds") != -1) {
						bisVec.addElement(myRecord);
					}
					// WAP1.0: Not implemented.

					// BES
					if (cid.indexOf("ippp") != -1 && uid.indexOf("gpmds") == -1) {
						mdsVec.addElement(myRecord);
					}
					// WiFi
					if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") != -1) {
						wifiVec.addElement(myRecord);
					}
					// Wap2
					if (cid.indexOf("wptcp") != -1 && uid.indexOf("wap2") != -1) {
						wap2Vec.addElement(myRecord);
					}
				}
			}
			srMDS = new ServiceRecord[mdsVec.size()];
			mdsVec.copyInto(srMDS);
			mdsVec.removeAllElements();
			mdsVec = null;

			srBIS = new ServiceRecord[bisVec.size()];
			bisVec.copyInto(srBIS);
			bisVec.removeAllElements();
			bisVec = null;

			srWAP2 = new ServiceRecord[wap2Vec.size()];
			wap2Vec.copyInto(srWAP2);
			wap2Vec.removeAllElements();
			wap2Vec = null;

			srWiFi = new ServiceRecord[wifiVec.size()];
			wifiVec.copyInto(srWiFi);
			wifiVec.removeAllElements();
			wifiVec = null;

			serviceRecordsLoaded = true;
		}
	}

	/**
	 * Utility methd for converting a mask of transports into an array of
	 * transports in default order
	 * 
	 * @param mask
	 *            ORed collection of masks, example:
	 *            <code>TRANSPORT_WIFI | TRANSPORT_BES</code>
	 * @return an array of the transports specified in mask in default order,
	 *         example: { TRANSPORT_WIFI, TRANSPORT_BES }
	 */
	private static int[] transportMaskToArray(int mask) {
		if (mask == 0) {
			mask = TRANSPORTS_ANY;
		}
		int numTransports = 0;
		for (int i = 0; i < TRANSPORT_COUNT; i++) {
			if ((DEFAULT_TRANSPORT_ORDER[i] & mask) != 0) {
				numTransports++;
			}
		}
		int transports[] = new int[numTransports];
		int index = 0;
		for (int i = 0; i < TRANSPORT_COUNT; i++) {
			if ((DEFAULT_TRANSPORT_ORDER[i] & mask) != 0) {
				transports[index++] = DEFAULT_TRANSPORT_ORDER[i];
			}
		}
		return transports;
	}
}

 
hiii i use that class to make http call to server but everytime gives error No More TransportsException
application only work on wifi
i try both GET and  POST nothing work

device := 8520 os 5.0
BIS services provider :- vodaphone  plan 15/day
in that gtalk and facebook working fine

also i test this app in arab country there also not work

------------------------------after i am test using ---------------------------------------------
networkDignostic link :- http://supportforums.blackberry.com/t5/Java-Development/What-Is-Network-API-alternative-for-legacy-O...

use networkDignostic to test available transport connection

below is result

Radio Signal Level: -81 dBm
WLAN Signal Level: No Coverage
Network Name: Vodafone IN
Network Type: GPRS
Network Services: Data + EDGE + Voice
PIN: 27F03947
Battery: 81%
====End of Network Info====
Transport: Default (HTTP GET)
Result: fail
Response: -1
Length: -1
URL: http://www.google.ca:80/
Log:

Connecting to http://www.google.ca:80/
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: Default (Socket GET)
Result: fail
Response: -1
Length: -1
URL: socket://www.google.ca:80
Log:

Connecting to socket://www.google.ca:80
Opening connection..
Error: java.io.IOException: Invalid url parameter.
========END OF LOG========

Transport: Default (HTTP POST)
Result: fail
Response: -1
Length: -1
URL: http://www.google.ca:80/
Log:

Connecting to http://www.google.ca:80/
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: Default (Socket POST)
Result: fail
Response: -1
Length: -1
URL: socket://www.google.ca:80
Log:

Connecting to socket://www.google.ca:80
Opening connection..
Error: java.io.IOException: Invalid url parameter.
========END OF LOG========

Transport: TCP Cellular (HTTP GET)
Result: fail
Response: -1
Length: -1
URL: http://www.google.ca:80/;deviceside=true
Log:

Connecting to http://www.google.ca:80/;deviceside=true
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: TCP Cellular (Socket GET)
Result: fail
Response: -1
Length: -1
URL: socket://www.google.ca:80;deviceside=true
Log:

Connecting to socket://www.google.ca:80;deviceside=true
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: TCP Cellular (HTTP POST)
Result: fail
Response: -1
Length: -1
URL: http://www.google.ca:80/;deviceside=true
Log:

Connecting to http://www.google.ca:80/;deviceside=true
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: TCP Cellular (Socket POST)
Result: fail
Response: -1
Length: -1
URL: socket://www.google.ca:80;deviceside=true
Log:

Connecting to socket://www.google.ca:80;deviceside=true
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: MDS (HTTP GET)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: No MDS service records found.
Skipped test: MDS coverage is not available

Transport: MDS (Socket GET)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: No MDS service records found.
Skipped test: MDS coverage is not available

Transport: MDS (HTTP POST)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: No MDS service records found.
Skipped test: MDS coverage is not available

Transport: MDS (Socket POST)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: No MDS service records found.
Skipped test: MDS coverage is not available

Transport: BIS-B (HTTP GET)
Result: pass
Response: 200
Length: -1
URL: http://www.google.ca:80/;deviceside=false;ConnectionType=m*s-pub***
Log:

Connecting to http://www.google.ca:80/;***Only disclosed to ISV partners of RIM.
Opening connection..
        Connection opened
Setting request properties..
        Host: www.google.ca
        User-Agent: Mozilla/4.0
        Connection: close
Getting response code..
        Response code: 200
Got content length: -1 bytes
Downloading content..
        Download time: 3.034 seconds
        Downloaded: 37943 bytes
Closing connection..
        Connection closed
========END OF LOG========

Transport: BIS-B (Socket GET)
Result: pass
Response: 200
Length: 38696
URL: socket://www.google.ca:80;deviceside=false;ConnectionType=m*s-pu***c
Log:

Connecting to socket://www.google.ca:80;***Only disclosed to ISV partners of RIM.
Opening connection..
        Connection opened
Sent GET request:
"GET / HTTP/1.1
Host: www.google.ca
User-Agent: Mozilla/4.0
Connection: close

"
Downloading content..
        Download time: 2.397 seconds
        Downloaded: 38696 bytes
Closing connection
        Connection closed
========END OF LOG========

Transport: BIS-B (HTTP POST)
Result: fail
Response: 405
Length: 959
URL: http://www.google.ca:80/;deviceside=false;ConnectionType=m*s-p***ic
Log:

Connecting to http://www.google.ca:80/;***Only disclosed to ISV partners of RIM.
Opening connection..
        Connection opened
Request method set to POST
Setting request properties..
        Host: www.google.ca
        Content-Length: 1500
        Content-Type: application/octet-stream
        User-Agent: Mozilla/4.0
        Connection: close
Posting 1500 bytes..
        Posted 1500 bytes
Getting response code..
        Response code: 405
Got content length: 959 bytes
Downloading content..
        Download time: 1.044 seconds
        Downloaded: 959 bytes
Closing connection
Connection closed
========END OF LOG========

Transport: BIS-B (Socket POST)
Result: fail
Response: 405
Length: 1204
URL: socket://www.google.ca:80;deviceside=false;ConnectionType=m**-p**li*
Log:

Connecting to socket://www.google.ca:80;***Only disclosed to ISV partners of RIM.
Opening connection..
        Connection opened
Setting request properties..
Sent POST request:
"POST / HTTP/1.1
Host: www.google.ca
Content-Length: 1500
Content-Type: application/octet-stream
User-Agent: Mozilla/4.0
Connection: close

"
Posting 1500 bytes..
        Posted 1500 bytes
Downloading content..
        Download time: 2.041 seconds
        Downloaded : 1204 bytes
Closing connection
        Connection closed
========END OF LOG========

Transport: WAP (HTTP GET)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: No WAP service records found.
Skipped test: WAP coverage is not available
Skipped test: Please provide WAP APN and IP

Transport: WAP (Socket GET)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: No WAP service records found.
Skipped test: WAP coverage is not available
Skipped test: Please provide WAP APN and IP

Transport: WAP (HTTP POST)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: No WAP service records found.
Skipped test: WAP coverage is not available
Skipped test: Please provide WAP APN and IP

Transport: WAP (Socket POST)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: No WAP service records found.
Skipped test: WAP coverage is not available
Skipped test: Please provide WAP APN and IP

Transport: WAP2 (HTTP GET)
Result: fail
Response: -1
Length: -1
URL: http://www.google.ca:80/;deviceside=true;ConnectionUID=WAP2 trans
Log:

Connecting to http://www.google.ca:80/;deviceside=true;ConnectionUID=WAP2 trans
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: WAP2 (Socket GET)
Result: fail
Response: -1
Length: -1
URL: socket://www.google.ca:80;deviceside=true;ConnectionUID=WAP2 trans
Log:

Connecting to socket://www.google.ca:80;deviceside=true;ConnectionUID=WAP2 trans
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: WAP2 (HTTP POST)
Result: fail
Response: -1
Length: -1
URL: http://www.google.ca:80/;deviceside=true;ConnectionUID=WAP2 trans
Log:

Connecting to http://www.google.ca:80/;deviceside=true;ConnectionUID=WAP2 trans
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: WAP2 (Socket POST)
Result: fail
Response: -1
Length: -1
URL: socket://www.google.ca:80;deviceside=true;ConnectionUID=WAP2 trans
Log:

Connecting to socket://www.google.ca:80;deviceside=true;ConnectionUID=WAP2 trans
Opening connection..
Error: net.rim.device.internal.io.CriticalIOException: Critical tunnel failure
========END OF LOG========

Transport: WiFi (HTTP GET)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: WiFi coverage is not available

Transport: WiFi (Socket GET)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: WiFi coverage is not available

Transport: WiFi (HTTP POST)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: WiFi coverage is not available

Transport: WiFi (Socket POST)
Result: fail
Response: -1
Length: -1
URL: No url available
Log:

Skipped test: WiFi coverage is not available

Regular Contributor
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: Application not work without wifi connection

i again run network dignostic demo and avilable transport is

 

(device:8520,v5.0.0.1036,service provider vodaphone)

 

BIS - Yes

MDS - No

TCP Celluler - Yes

wifi - No

WAP - No

WAP2 - Yes

 

any replay ...............................................?

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

Re: Application not work without wifi connection

Use WAP2 - code to do so is in here:

 

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

 

Check your logic to make sure you are correctly detecting when it is available. 

 

 

Regular Contributor
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: Application not work without wifi connection

hii peter thanks for replay

 

i use code fron given link and update my code

 

and after i debug code and its gives error and ask for apn

 

after i enable apn and provide apn as per network provider give me

 

then its give server responce 404

 

i think so every time debuger goes in WEP2 connection

 

my bis plan is over but i want to run my application without blackberry plan

 

i dont know why its not run on wep2 connection please help me to implement like so run in every country...

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

Re: Application not work without wifi connection

I presume you mean WAP2 when you say wep2.

 

I have not looked in detail at the logic you use to decide what connection methods that you are going to support and try to set the appropriate connection string.  In fact I recommend that you discard this logic and look to ConnectionFactory to do the same thing for you. This provides the best (RIM supplied) logic to determine the correct connection suffix.

 

But there are cases where ConnectionFactory can not work, specifically where there are extra parameters required.  So ConnectionFactory will work for WiFi, BES, and WAP2. 

 

For Carrier connection, you have to specify the APN which is carrier specific, so ConnectionFactory can not do that for you.  If you want to use this method you will have to ask the User to input the APN values as the TCP Options on their phone.

 

With respect to BIS-B, this requires a special option be specified when using ConnectionFactory.  Unless you have this, do not ask ConnectionFactory to use BIS-B.

 

Anyway, I suggest you swap out your logic, swap in ConnectionFactory and see if that will help you. 

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: Application not work without wifi connection

I had faced same problem. This may help you.

public HttpConnection getConnectionForRequest(String url) 
    {
        
       
        int[] availableTransportTypes = {TransportInfo.TRANSPORT_TCP_WIFI,
                                         TransportInfo.TRANSPORT_BIS_B, 
                                         TransportInfo.TRANSPORT_WAP2,
                                         TransportInfo.TRANSPORT_TCP_CELLULAR, 
                                         TransportInfo.TRANSPORT_MDS, 
                                         TransportInfo.TRANSPORT_WAP};
        final ConnectionFactory connectionFactory = new ConnectionFactory();
        
       
        for (int i = 0; i < availableTransportTypes.length; i++) 
        {
            int transport = availableTransportTypes[i];
            if (!TransportInfo.isTransportTypeAvailable(transport) || !TransportInfo.hasSufficientCoverage(transport)) 
            {
                Arrays.removeAt(availableTransportTypes, i);
            }
        }
                
        connectionFactory.setPreferredTransportTypes(availableTransportTypes);
        connectionFactory.setAttemptsLimit(10);       
        connectionFactory.setRetryFactor(30000);
        
        final ConnectionDescriptor connectionDescriptor = connectionFactory.getConnection(url);
        HttpConnection connection = null;
        if (connectionDescriptor != null) 
        {
           
            
           Integer.toString(transportUsed));
            connection = (HttpConnection) connectionDescriptor.getConnection();
        }
        
        return connection;
    }

 

Regular Contributor
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: Application not work without wifi connection

thanks peter and jovinz

 

i thinks i have problem in httpconnectionfactory with multiple url parameter as peter says

 

so now i usr post url as below code

 

	public static void CheckConnection() 
	{
		HttpConnection hc=null;
		try 
		{
			//Wifi Connection
			if ( (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) && RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) 
			{ 
				ConstantData.postURL=";interface=wifi";                 
				return;
			}
			//for BES or MDS Connection
			if(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS))
			{
				boolean connectionFlag=false;
				String post_url;

				//for BES Connections
				post_url="";
				try 
				{
					hc = (HttpConnection) Connector.open("http://www.rim.com"+post_url,Connector.READ_WRITE);
					if(hc.getResponseCode()==HttpConnection.HTTP_OK)
					{
						connectionFlag=true;
						ConstantData.postURL=post_url;
						return;
					}
					if(hc!=null)
						hc.close();
				}
				catch (Exception e) 
				{
					System.out.println(e.toString());
					connectionFlag=false;
				}
				//for MDS Connection
				if(!connectionFlag)
				{
					try 
					{
						post_url = ";deviceside=false";
						hc = (HttpConnection) Connector.open("http://www.rim.com"+post_url);
						if(hc.getResponseCode()==HttpConnection.HTTP_OK)
						{
							ConstantData.postURL=post_url;
							return;
						}  
						if(hc!=null)
							hc.close();
					}
					catch (Exception e) 
					{
						System.out.println(e.toString());
					}
				}
			}
			//for BIS Connection
			if(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_BIS_B))
			{
				//BIS Connection
				String post_url = ";deviceside=false;ConnectionType=m**-pu***c";
				try 
				{
					hc = (HttpConnection) Connector.open("http://www.rim.com"+post_url);//Connector.READ_WRITE
					if(hc.getResponseCode()==HttpConnection.HTTP_OK)
					{       
						ConstantData.postURL=post_url;
						return;
					}  
					if(hc!=null)
						hc.close();
				}
				catch (Exception e) 
				{
					System.out.println(e.toString());
				}
			}
			//for WAP Connection
			if(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_DIRECT))
			{				//for WAP Connection
				String post_url = null;
				ServiceBook sb = ServiceBook.getSB();
				ServiceRecord[] records = sb.findRecordsByCid("WPTCP"); 
				String uid = null; 
				boolean connectionFlag=false;
				for(int i=0; i < records.length; i++) 
				{
					if (records[i].isValid() && !records[i].isDisabled()) 
					{
						if (records[i].getUid() != null && records[i].getUid().length() != 0) 
						{
							if ((records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
									(records[i].getUid().toLowerCase().indexOf("mms") == -1))
							{
								uid = records[i].getUid(); 
								break;
							}
						} 
					}
				}
				if (uid != null) 
				{
					post_url= ";deviceside=true;ConnectionUID=" + uid;
				}
				try 
				{
					hc = (HttpConnection) Connector.open("http://www.rim.com"+post_url);
					if(hc.getResponseCode()==HttpConnection.HTTP_OK)
					{
						connectionFlag=true;
						ConstantData.postURL=post_url;
						return;
					} 
					if(hc!=null)
						hc.close();
				}
				catch (Exception e) 
				{               System.out.println(e.toString());
				connectionFlag=false;
				}
				if(!connectionFlag)
				{
					post_url=";deviceside=true;apn=blackberry.net";
					try 
					{
						hc = (HttpConnection) Connector.open("http://www.rim.com"+post_url);
						if(hc.getResponseCode()==HttpConnection.HTTP_OK)
						{
							ConstantData.postURL=post_url;
							return;
						}  
						if(hc!=null)
							hc.close();
					}
					catch (Exception e) 
					{
						System.out.println(e.toString());
					}
				}}
		}
		catch (Exception e) 
		{

			e.printStackTrace();
		}
		finally
		{
			try 
			{
				if(hc!=null)
					hc.close();
			} catch (IOException e) {
				System.out.println(e.toString());
				e.printStackTrace();
			}
		}

	}

 

 

so now its working on WAP2,BIS and WIFi working fine

 

on first code in post also problem of TCP celluler priority is more then WAP2

so every time transport select TCP when BIS,WIFI not presend and need apn

 

anyway  again thanks peter and network dignostic tools demo is awasome..

New Contributor
Posts: 6
Registered: ‎03-02-2014
My Device: BB9900
My Carrier: sdfdsf

Re: Application not work without wifi connection

Hi all,

 

This is my code in blackberry os7. It is working fine in WIFI  for all the networks but in direct connection it is working only for few networks. what is problem here. is anybody help me.

 

I have given my code below. Thanks in advance

 

try {
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
System.out.println("WifI");
c = (HttpConnection) Connector
.open(urltotal + ";interface=wifi",
Connector.READ_WRITE, true);
} else {
int coverageStatus = CoverageInfo.getCoverageStatus();
ServiceRecord record = getWAP2ServiceRecord();
if (record != null
&& (coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {

connectionParameters = ";deviceside=true;ConnectionUID="
+ record.getUid();
} else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
// Have an MDS service book and network coverage
connectionParameters = ";deviceside=false";
} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage but no WAP 2.0 service book
// record
connectionParameters = ";deviceside=true";
}
c = (HttpConnection) Connector.open(urltotal
+ connectionParameters, Connector.READ_WRITE,
true);


}
// c = (HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.GET);
rc = c.getResponseCode();
System.out.println("Responce.........>>>>>>>>>" + rc);
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
is = c.openInputStream();

// Get the ContentType
String type = c.getType();
// processType(type);
byte[] responseData = new byte[10000];
int length = 0;

while (-1 != (length = is.read(responseData))) {
rawResponse.append(new String(responseData, 0, length));
}
} catch (Exception e) {
new Throwable(e.toString());
}

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

Re: Application not work without wifi connection

Welcome to the forums.

 

It is not usually advisable to continue a solved thread, instead I suggest you start your own Thread.

 

To so this look for the "New Message" button near the top of the page that you find all the Questions. 

 

While you are there, you will also see a Help Link.  I recommend having a quick look at that to understand how to use the forum.  Also you might like to have a look at all the 'sticky' Threads at the top of the list - these are usually left at the top because they contain useful information for all users. 

 

But before you ask the question in your own Thread, I suggest you document which networks you code works with and which it does not/  For the ones it works with, document the connection method it is using in these networks.  For the network it does not work, document the error or exception that you see when attempting to connect using that network. 

 

I think this will provide you with additional information that might enable you to resolve this problem for yourself.  If not, we need to understand this information to assist you. 

 

Good luck.