BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 02-21-2008, 06:14 AM   #1
PashaCosmos
New Member
 
Join Date: Jan 2008
Location: Ukraine, Kyiv
Model: 8100
PIN: N/A
Carrier: KyivStar
Posts: 2
Exclamation HttpConnection response problem

Please Login to Remove!

Hi All,

When I post an image to server and then try to get response(XML-file) from input stream I catch net.rim.device.api.io.ConnectionClosedException. I open connection in separate thread (not in Event Dispatcher thread). Also I use JDE 4.3.0 and try to run my app on Pearl(8100).

Here is my code:

Code:
HttpConnection httpConnection = null;
OutputStream outputStream = null;
InputStream inputStream = null;
try {
   httpConnection = (HttpConnection)Connector.open(url/* + ";deviceside=true"*/, Connector.READ_WRITE, true);
   httpConnection.setRequestProperty("Content-Type", "application/atom+xml; charset=utf-8");
   httpConnection.setRequestProperty("User-Agent", "MyApp 1.0 for BlackBerry");
   String xwsse = auth(userName, password);
   httpConnection.setRequestProperty("X-WSSE", xwsse);
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   /*
   here I generate and write XML-file(that content Base64 encoded image) to the baos. 
   */
   outputStream = httpConnection.openOutputStream();
   OutputStreamWriter osw = new OutputStreamWriter(outputStream, "UTF-8");
   String output = baos.toString();
   if(output != null)
   {
      osw.write(output, 0, output.length());  
   }

   int responseCode = httpConnection.getResponseCode();
   /*
   on device and on emulator response code = 201. Also image resource is created on the server and I can see it there.  
   */
   
   StringBuffer sb = new StringBuffer();
   inputStream = httpConnection.openInputStream();
   InputStreamReader isReader = new InputStreamReader(inputStream);
   char i;
   int j = 0;
   while( (j = isReader.read()) != -1)
   {
      i = (char)j;
      sb.append(i);
   }
   /*
   then I try to parse sb that consists response XML, and get server image's href    
   */
}catch(Throwable t)
{

}
finally{
   if(outputStream != null)
   {
      outputStream.close(); 
      outputStream = null;
   }
   if(inputStream != null)
   {
      inputStream.close(); 
      inputStream = null;
   }
   if(httpConnection!= null)
   {
      httpConnection.close(); 
      httpConnection= null;
   }
}

This code work properly on emulator, but when I try to read response from httpConnection on real device it throws ConnectionClosedException.

Please help me!!!

Regards, Pasha.
Offline  
Old 02-21-2008, 09:29 AM   #2
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default Some general solutions

First off, is your blackberry on a BES? If not, you're likely running into connection issues because you have not specified which service to use to create your connections. Your other choices are: BIS, Direct TCP, WAP.

If you don't know how to set up those types of connections, browse RIM's developer documention papers on the blackberry website.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Implement Whisker Switch  picture

Implement Whisker Switch

$50.00



Air Compressor Pressure Control Switch 4 Ports 95-125 PSI W/ 0-200 PSI Gauge 150 picture

Air Compressor Pressure Control Switch 4 Ports 95-125 PSI W/ 0-200 PSI Gauge 150

$48.46



JCB BACKHOE - GENUINE JCB IGNITION SWITCH AND 2 KEYS (PART# 701/80184 701/45500) picture

JCB BACKHOE - GENUINE JCB IGNITION SWITCH AND 2 KEYS (PART# 701/80184 701/45500)

$39.95



NS1-63-NA. EATON /Moeller breaker  MAIN SWITCH  63 AMPS picture

NS1-63-NA. EATON /Moeller breaker MAIN SWITCH 63 AMPS

$375.00



Dusk to Dwan/Day Night Sensor, Photoelectric Switch, Photo Cell Sensor 110-277V picture

Dusk to Dwan/Day Night Sensor, Photoelectric Switch, Photo Cell Sensor 110-277V

$49.28



ELECTRIC COOLING FAN GROUND-ING THERMO-STAT SWITCH RADIATOR TEMP-ERATURE SENSOR picture

ELECTRIC COOLING FAN GROUND-ING THERMO-STAT SWITCH RADIATOR TEMP-ERATURE SENSOR

$16.99







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.