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
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer
Accepted Solution

java.io.intrrupted Exception Local Connection timed out exception on device.

[ Edited ]

Hi friends,

 

when i am tring to connect to my server using Bis plan on device.

 

i am getting this java.io.intrrupted Exception local Connection timed out exception. it's working fine on simulator.

 

this is my code for connecting to the server. please anyone can help me to find the solution for this Exception.

 

ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connectDes = connFact.getConnection(url);
				httpConnection = (HttpConnection) connectDes.getConnection();
				String type = "application/x-www-form-urlencoded";
				String agent = "Mozilla/4.0";
				httpConnection.setRequestMethod(HttpConnection.POST);
				httpConnection.setRequestProperty("Content-Type", "UTF-8");
				httpConnection.setRequestProperty("User-Agent", agent);
				httpConnection.setRequestProperty("Content-Type", type);
				httpConnection.setRequestProperty(
						HttpProtocolConstants.HEADER_CONNECTION, "Keep-Alive");
				outputStream = httpConnection.openOutputStream();
				outputStream.write(postData.getBytes());
				outputStream.flush();

				inputStream = httpConnection.openInputStream();
			if (httpConnection.getResponseCode() == 200) {
				StringBuffer responseBuffer = new StringBuffer();
				int c = 0;
				while (((c = inputStream.read()) != '\n') && (c != -1)) {
					responseBuffer.append((char) c);
				}
				String response = responseBuffer.toString();
				gotResponse = true;
				System.out.println("response is:" + response);
				responseJsonObject = new JSONObject(response);
			} 

 

 Thanks in advance.

 

bh1r1th.

Please use plain text.
Developer
simon_hain
Posts: 16,001
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: java.io.intrrupted Exception Local Connection timed out exception on device.

do you try to keep a connection alive on the device? this won't work, after some time all connections are closed.

if you need a server to notify the device you'll have to use push or another notification method.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: java.io.intrrupted Exception Local Connection timed out exception on device.

can u please what should i have to do remove that parameter from my connection is that enought.

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

Re: java.io.intrrupted Exception Local Connection timed out exception on device.

There are other oddities in your parameters too:

 

String type = "application/x-www-form-urlencoded";

String agent = "Mozilla/4.0";
httpConnection.setRequestMethod(HttpConnection.POST);
httpConnection.setRequestProperty("Content-Type", "UTF-8");
httpConnection.setRequestProperty("User-Agent", agent);
httpConnection.setRequestProperty("Content-Type", type);

Why do you set the agent?  Why do you set the Content-Type twice.  Why don't you set the Content length?

 

These are actually all important.  When you are doing this via the Simulator, there are no real gateways involved.  When you start doing things on device, there are.  You have not restricted the connection to an specific method, so you don't know which are involved in this specific request.

 

One thing you can try is to stop all connections except for WiFi, and see if it works then.  if it does, then I strongly suspect there is a gateway issue, and you will need to set these headers correctly.  You should has the Connection factory what connection method it has chosen for your connection. 

Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: java.io.intrrupted Exception Local Connection timed out exception on device.

Thanks for the replay peter,

Yes I am tried with wifi it's working fine. And when I use bis it won't works.
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: java.io.intrrupted Exception Local Connection timed out exception on device.

You might like to check your server logs to see if the request ever gets through.  I suspect not. 

 

Try sending a very simple request through - just a simple GET, with no header parameters.  FInd out what connection type you are using. 

 

You might like to specify the transports that you will allow, see documentation for Connection Factory.

 

You could also download the Network Diagnostics and find out what connections actually work from your phone using that.  You will find it here:

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

Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: java.io.intrrupted Exception Local Connection timed out exception on device.

K peter I will check those things and get back to u
Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: java.io.intrrupted Exception Local Connection timed out exception on device.

hi peter,

 

i am getting new exception like java.io.IOException: Failed to transmit

 

how to solve this issue can u please help me to fix this issue.

 

 

Regards,

 

bh1r1th.

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

Re: java.io.intrrupted Exception Local Connection timed out exception on device.

I don't have a good answer here, I am not sure what failed to transmit means.  I would however look at the connection method you are trying to use.  For example if you have chosen WAP and there is no WAP access on the phone, perhaps you will get this message.

 

What did the Network Diagnostic test turn up?

Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: java.io.intrrupted Exception Local Connection timed out exception on device.

Hi Peter,

 

Thanks for the replay.

 

please take a look at this link.

 

http://supportforums.blackberry.com/t5/Java-Development/How-to-solve-java-io-IOException-Failed-to-t...

 

and it's working on my phone but one of user is compalaining. i am not tested that Network Diagnostics on his phone but i am using those classes

 

TransportDetective transport = new TransportDetective();
                URLFactory urlFactory = new URLFactory(url);

 

to make a connection and i am checking the connection also.

 

 

Please use plain text.