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
Highlighted
Developer
Posts: 193
Registered: ‎04-27-2009
My Device: Not Specified
Accepted Solution

net.rim.device.api.io.ConnectionClosedException: Connection closed

Hi,

I am getting "net.rim.device.api.io.ConnectionClosedException: Connection closed" exception while trying to get response code in the following code snippet . what will the possible reason of this exception:-

HttpConnection connection=(HttpConnection)Connector.open(url);
		System.out.println("Post-----------------------1");
		connection.setRequestMethod(HttpConnection.POST);
		System.out.println("Post-----------------------2");
		connection.setRequestProperty("Content-Type",aRequest.getContentType());
		System.out.println("Post-----------------------3");
		Hashtable header=aRequest.getHeader();
		if(header!=null)
		{
			Enumeration enumeration =header.keys();
			while(enumeration.hasMoreElements())
			{
				String headerStr=(String)enumeration.nextElement();
				String headerValue=(String)header.get(headerStr);
				//System.out.println("header:"+headerStr+"headerval::"+headerValue);
				connection.setRequestProperty(headerStr,headerValue);
			}
		}
		System.out.println("Post-----------------------4");
		OutputStream postRequestOutputStream=connection.openOutputStream();
		System.out.println("Post-----------------------4#########");
		postRequestOutputStream.write(aRequest.getPostData());
		System.out.println("Post-----------------------4%%%%%%%");
		postRequestOutputStream.close();
		System.out.println("Post-----------------------5");
		System.out.println("RES CODE:"+connection.getResponseCode());
		InputStream is=connection.openInputStream();
		

 

BlackBerry Development Advisor
Posts: 15,753
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: net.rim.device.api.io.ConnectionClosedException: Connection closed

What BlackBerry Smartphone model and BlackBerry device software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.  What route are you making your network connection over?

 

Different ways to make an HTTP or socket connection

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

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 193
Registered: ‎04-27-2009
My Device: Not Specified

Re: net.rim.device.api.io.ConnectionClosedException: Connection closed

I am using BlackBerry Smartphone model 8900 and BlackBerry device software version 4.6.1.231.I am using WIFI for making network connection.

BlackBerry Development Advisor
Posts: 15,753
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: net.rim.device.api.io.ConnectionClosedException: Connection closed

Does this occur for any destination server or just a particular one?  Are you able to connect to the same location using the Hotspot Browser?  To change your default browser go to Options, Advanced Options, Browser.

 

Have you tested with multiple Wi-Fi networks?  If so, does the exception occur on all of them?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 9
Registered: ‎09-29-2009
My Device: Not Specified

Re: net.rim.device.api.io.ConnectionClosedException: Connection closed

Did you ever get a resolution to this issue?

 

I'm getting the same error on a Blackberry 8330 on Verizon network.  I have several developers in Vietnam, who are not experiencing this problem at all.  Perhaps it is something to do with the carrier.

 

The exception we get is:

 

net.rim.device.api.io.ConnectionClosedException: Connection closed

 

It seems to only happen when posting a lot of content to a web service.  Downloads work fine always - Upload fails with this error.

 

Any help would be greatly appreciated.

Developer
Posts: 78
Registered: ‎12-03-2009
My Device: Not Specified

Re: net.rim.device.api.io.ConnectionClosedException: Connection closed

Try to open the InputStream before getResponseCode().

regards

--
Feel free to press the kudos button on the left side to thank the user that helped you.
Please mark posts as solved if you found a solution.
New Developer
Posts: 9
Registered: ‎09-29-2009
My Device: Not Specified

Re: net.rim.device.api.io.ConnectionClosedException: Connection closed

Klerisson,

 

I can't tell you how great you are!!!!!  This has been a 2 month issue for us, and your response just saved us probably weeks of continued investigation and head banging.  Thank you so much - your advice worked like a charm.

 

Ben