Hi All,
I have written a small BB application to access a HTTP URL. I am using the regular HTTPConnection class for this (Code Attached). This is the behavior observed.
1. My application works fine with a simulator using MDS.
2. My Provider does not provide access to a BES server. However, my phone had a valid APN and Gateway IP in the WAPTransport[WAP]. Hence I modified my application to pick up this information and establish a connection over GPRS. In this case the connection establishment did work.
My question is as follows:
I also tried to run my application on a BB in another network. On this phone there is no entry with the name WAPTransport[WAP] in the Service Book. In this case my application fails (gives an exception on the line marked with RED). But other applications such as the browser continue to work. Where do these applications get the APN/Gateway IP from?
Appreciate any help in this regard,
Thanks in Advance,
Prasad
Code:
public class ReadHttpFile extends Thread {
HttpConnection httpConnection = null;
InputStream inputStream = null;
int responseCode;
public boolean isInvalidFile=false;
String url;
StringBuffer URLString;
ReadHttpFile(String URL){
url = URL;
URLString = new StringBuffer();
URLString.append(url);
try{
ServiceBook serviceBook = ServiceBook.getSB();
ServiceRecord[] records =
serviceBook.findRecordsByCid("WAP");
for(int i = 0; i < records.length; i++){
if(records[i].getName().equalsIgnoreCase("WAP
Transport")){
URLString.append(";WAPGatewayIP=");
String networkAddress =
records[i].getNetworkAddress();
URLString.append(networkAddress.substring(0,networkA
ddress.indexOf(':')));
URLString.append(";WAPGatewayAPN=");
URLString.append(records[i].getAPN());
url = URLString.toString();
}
}
}catch(Exception e){
System.out.println("Exception : "+e.toString());
}
}
public void run() {
try{
ReadData(url);
}catch(IOException ie){
System.out.println("IOException : "+ie);
}catch(Exception e){
System.out.println("Exception : "+e);
}
}
public void ReadData(String url) throws IOException{
try {
httpConnection =
(HttpConnection)Connector.open(url,Connector.READ);
if(httpConnection != null){
httpConnection.setRequestMethod(HttpConnection.P
OST);
httpConnection.setRequestProperty("Content-Langu
age", "en-US");
httpConnection.setRequestProperty("Content-Type"
, "text/xml; charset=utf-8");
responseCode = httpConnection.getResponseCode();
if (responseCode != HttpConnection.HTTP_OK) {
System.out.println("Http connection :
Failed");
}else{
System.out.println ("Http connection : OK
");
inputStream =
httpConnection.openInputStream();
StringBuffer sb = new StringBuffer();
int ch;
while ((ch = inputStream.read()) != -1) {
sb.append((char) ch);
}
System.out.println("XML "+ sb .toString());
}
}else{
System.out.println("Connection object : Null ");
}
}catch(IOException ioe){
System.out.println("Exception : "+ ioe.toString());
}catch(Exception e){
System.out.println("Exception : "+ e.toString());
} finally {
if (inputStream != null)
inputStream.close();
if (httpConnection != null)
httpConnection.close();
}
}
}