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
joleaary
Posts: 2
Registered: ‎06-09-2011
My Device: Blackberry 9600
My Carrier: vodafone

Connecting to web service issue

[ Edited ]

Hi,

 

I have a simple app written the connects to web service (restful). The app works fine on the simulator however I'm having problems using it on a blackberry 9300.

 

I keep getting the error "java.io.ioexception: tunnel down" when the apps attempts to call the web service.

 

The service I am calling is a simple HTTP post and I'm trying to run this over WIFI (the WIFI connection is working fine for browsing the internet).

 

I'm using a connection string of "http://127.0.0.1:8080/test/restws;interface=wifi" with the IP address changed to the actual Ip address of the server I'm calling. I can call the restful web service on this server on my laptop browser fine.

 

 

 

The code Im using is similar to below  & works fine on the simulator. The only thing im changing between the simulator and the code on the phone is the connection string (using "interface=wifi" as oppose to "deviceside=true")    

 

Is this a code problem or is it a setting I need to change on the handset?

 

 

        StreamConnection s = (StreamConnection) Connector
		    .open(connectionString);
	    httpConn = (HttpConnection) s;
	    httpConn.setRequestMethod("POST");
	    httpConn.setRequestProperty("Content-Length", Integer.toString(postData.length()));

	    OutputStream output = httpConn.openOutputStream();
	    output.write(postData.getBytes());
	    output.flush();
	    output.close();
		
	    String response = httpConn.getResponseMessage();
	    int statusCode = httpConn.getResponseCode();
	    if (statusCode != HttpConnection.HTTP_OK) {
	    }

	    InputStream is = httpConn.openInputStream();
	    int ret = 0;
	    while ((ret = is.read(buf)) > 0) {
		os.write(buf, 0, ret);
	    }

	    result = new String(os.toByteArray());

 

Please use plain text.
Developer
peter_strange
Posts: 19,602
Registered: ‎07-14-2008
My Device: Not Specified

Re: Connecting to web service issue

I would make 100% sure that you are in fact using ";interface=wifi".  The exception you are seeing is typically caused when using or defaulting to ";deviceside=true" and the device not having APN values specified in the TCP options. 

Please use plain text.
Contributor
paramvirBB
Posts: 14
Registered: ‎10-20-2012
My Device: Torch 9800
My Carrier: airtel

Re: Connecting to web service issue

Hi Peter,

I am getting the very same problem. What is the solution to this proble, What connection string should I use on the real device?

Please use plain text.
Developer
peter_strange
Posts: 19,602
Registered: ‎07-14-2008
My Device: Not Specified

Re: Connecting to web service issue

Please use plain text.