Post buffer lost
Hi Everyone,
I am working on an enterprise application and I have the following problem.
I have a thread called dispatcher which will send the request to the server and process the response and pass it to the main thread to display on the screen. My problem is that, 1 out of 15 times of my 'Post Request', my Post parameters gets lost and the server returns an error. This happens in motorola iden 866 phones. I tried on Sun WTK 2.2 and I did not get any error. I did not get a chance to try on other phones as of now.
I did some work around by ,
Adding the Post parameters on the header and I can see them in the log files of my server when this error occurs.
Adding the content length but no effect.
The strange thing is that there is no particular sequence to reproduce the error. It happens irregularly. Also to let you know that this is tested only on motorola IDEN 866 phones till now. The Sun WTK 2.2 emulator which is on windows xp does not show this error.
Any help is really appreciated as this is bugging me for a month now.
Thank you all,
Pradeep.
Message was edited by:
deep_k
Message was edited by:
deep_k
[1212 byte] By [
deep_ka] at [2007-11-27 4:33:21]

# 2
/********************************************************************************
Open the connection
*********************************************************************************/
postBuffer = null;
String reqBuffer;
// request uri is of the form https://xyz.com?abc=1
int index = requestURI.toString().indexOf('?');
if (index != -1) {
//
// we have form variables
// - the post buffer is everything after '?'
// - remove everything after '?' and append session id for request buffer
//
postBuffer = requestURI.toString().substring(index + 1);
requestURI.setLength(index);
}
reqBuffer = requestURI.toString();
fiwConnection = (HttpConnection) Connector.open(reqBuffer);
if (fiwConnection == null)
return null;
fiwConnection.setRequestMethod(HttpConnection.POST);
fiwConnection.setRequestProperty("user-agent",UIConstants.USER_AGENT);
if(postBuffer != null && postBuffer.length() > 0)
fiwConnection.setRequestProperty("user-data", postBuffer);
fiwConnection.setRequestProperty("x-up-uplink",UIConstants.NETWORK);
fiwConnection.setRequestProperty("Accept","*/*");
if(deviceIdCookie != null && deviceIdCookie.length() > 0){
fiwConnection.setRequestProperty("cookie",deviceIdCookie);
}
/********************************************************************
Write post buffer data into Output Stream of fiw connection
*********************************************************************/
if (postBuffer != null) {
data=postBuffer.getBytes();
//
// tell the server that the form variables are urlencoded in the post buffer
//
fiwConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
//
// create the post buffer
//
_os = fiwConnection.openOutputStream();
_os.write(data);
_os.close();
_os=null;
} else {
Log.log("POST buffer is empty");
}
/**************************************************************************
Get the Response from the server
***************************************************************************/
if ((responseCode=fiwConnection.getResponseCode()) == HttpConnection.HTTP_OK) {
_is = fiwConnection.openInputStream();
int responseLen = (int) fiwConnection.getLength();
if (responseLen != -1) {
response = new byte[responseLen];
_is.read(response);
} else {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
byte buffer[] = new byte[BUF_LEN];
int len = 0;
while ((len = _is.read(buffer)) != -1) {
byteStream.write(buffer, 0, len);}
}
response = byteStream.toByteArray();
}
_is.close();
_is=null;
}