Tuesday, February 22, 2011

BlackBerry BIS-B SOAP returns issue

I've currently been very stressed out with the problem that I just found when using BIS-B connection while getting SOAP message return over Http connection. Somehow those return messages appear to be encrypted or using unknown encoding while using BIS-B but not when using direct TCP or Wifi connection. 
So what is the problem anyway?? 

For an example, let say the server returns "<body>This is a body message</body>" but when using BIS-B it returns "&Auml;&Oslash;Body&Auml;&Oslash;This is body message&Auml;&Oslash;body&Auml;&Oslash;"
Not only that, the messages also altered and has been added with some string like "RIM-X AAaaaAaaaaaaaAGBGASDa/JASFyJFKDSKLDSF" that I didn't know what the heck is it means.

At first, I just check on the server side to make sure that there was no encryption process or encoding changes what so ever during connection and yes, there weren't any. Then I try to ask directly to RIM about this issue and still not getting the right answer that I've been looking for. They suggest me to look on the Basic Authentication process but I think it is not the problem. Here is the code that I showed to RIM:


HttpConnection midpConnection = (HttpConnection) Connector.open(url);

// Add some basic authentication
StringBuffer buf = new StringBuffer(username); buf.append(':').append(password); byte[] raw = buf.toString().getBytes(); buf.setLength(0); buf.append("Basic "); org.kobjects.base64.Base64.encode(raw, 0, raw.length, buf); midpConnection.setRequestProperty("Authorization", buf.toString());

midpConnection.setRequestProperty("SOAPAction", soapAction);
midpConnection.setRequestProperty("Content-Type", "text/xml");
midpConnection.setRequestProperty("Content-Length", "" + requestData.length);
midpConnection.setRequestProperty("User-Agent", "BlackBerry-MyApp");
midpConnection.setRequestMethod(HttpConnection.POST);
os = midpConnection.openOutputStream();
os.write(requestData, 0, requestData.length);
os.close();
requestData = null;

int status = midpConnection.getResponseCode();
if (status != HttpConnection.HTTP_OK) {
final int statusx = status;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("Connection Error: " + statusx);
}
});
} else {
String contentType = midpConnection.getHeaderField("Content-type");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream responseData = midpConnection.openInputStream();
byte[] buffer = new byte[10000];
int bytesRead = responseData.read(buffer);
while(bytesRead > 0) {
baos.write(buffer, 0, bytesRead);
bytesRead = responseData.read(buffer);
}

String strResponse = new String(baos.toByteArray());
baos.close();
}
After nearly give up with this but then my colleague suddenly pointed me to this http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/Support_-_HTTP_transmits_incorrectly_when_User-Agent_includes__BlackBerry_.html?nodeid=1367249&vernum=0