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
Contributor
Posts: 48
Registered: ‎06-30-2010
My Device: 9000
My Carrier: Non

java.io.IOException in http connection

Hi,

 

Here is my code, sometimes it throwing JavaIOException and e.getMessage() throws null. Here i'm trying to send XML file to the server. I want to know the reason for this issue.


public int HttpConnection(Vector inParam)
{
Request requestObject = null;
int responsecode = 0;
DataOutputStream os = null;
try
{
String URL = instance.getServerURL() + getConnectionString();
StringBuffer response = new StringBuffer();
log("MobileNetwork :: " + AppState.mobileNetwork);
log("Wifi :: " + AppState.wifi);
log("URL in HttpConnection :: " + URL);
HttpConnection _httpConnection = null;
try
{
_httpConnection = (HttpConnection) Connector.open(URL);
_httpConnection.setRequestMethod(HttpConnection.POST);
_httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
_httpConnection.setRequestProperty("User-Agent", "BlackBerry/3.2.1");
_httpConnection.setRequestProperty("Content-Language", "en-US");

_httpConnection.setRequestProperty("Connection", "close");
os = (DataOutputStream) _httpConnection.openDataOutputStream();
requestObject = (Request) inParam.elementAt(0);
requestObject.getXML(os);
log("getXML");
os.flush();
responsecode = _httpConnection.getResponseCode();
log("Response code in HTTP :: " + responsecode);

if (responsecode == HttpConnection.HTTP_OK)
{
log("inside HTTP_OK");
InputStream inputStream = _httpConnection.openInputStream();
int ch;

while ((ch = inputStream.read()) != -1)
{
response.append((char) ch);
}

log(" Response from second URL ----->>>>>>>>>>>... " + response.toString());
instance.updateParam(response.toString());

}
os.close();
_httpConnection.close();
return responsecode;
}
catch (Exception e)
{
log("Exception in Http com :: " + e.getMessage());
log("" + e);
e.printStackTrace();
}
}
catch (Exception ex)
{
}
return responsecode;
}

 

 

Thanks,

Dhivya

Highlighted
Developer
Posts: 78
Registered: ‎05-17-2012
My Device: 9900 - OS 7.0 Torch device
My Carrier: Reliance

Re: java.io.IOException in http connection

Hi

 

Here might be a connection problem. why don't  you use the HttpConnectionFactory class instead of simple HttpConnection. I think, If there are much xml text, build and stread is giving problem to get connected.