05-18-2012 09:49 AM
Hi All
I am trying to implement the BIS push service in client app.
I have got Port number, appId, BPAS URL & using that i m trying to register using the below code
public boolean registerBpas() {
Logger.info("MyScreen.registerBpas()");
/**
* As the connection suffix is fixed I just use a Thread to call the connection code
*
**/
// boolean isValue = false;
try {
Logger.info("--------- step 1");
String conparam = getConnParam();
Logger.info("-------------> conparam : "+conparam);
final String registerUrl = formRegisterRequest(BPAS_URL, APP_ID, null) + conparam/*Conn.getConnectionParameters()*/;
Logger.info("\n\n\n msg registerBPAS URL is: "+ registerUrl);
HttpConnection httpConnection = (HttpConnection) Connector.open(registerUrl);
InputStream is = httpConnection.openInputStream();
String response = new String(IOUtilities.streamToBytes(is));
Logger.info("\n\n\n\n\n\n msg RESPOSE CODE : " + response);
close(httpConnection, is, null);
String nextUrl = formRegisterRequest(BPAS_URL, APP_ID, response) + conparam/*Conn.getConnectionParameters()*/;
Logger.info("\n\n\n\n\n\n msg nextUrl : " + nextUrl);
HttpConnection nextHttpConnection = (HttpConnection) Connector.open(nextUrl);
InputStream nextInputStream = nextHttpConnection.openInputStream();
response = new String(IOUtilities.streamToBytes(nextInputStream))
Logger.info("\n\n\n\n\n\n msg RESPOSE CODE 1: " + response);
close(nextHttpConnection, is, null);
if (REGISTER_SUCCESSFUL.equals(response) || USER_ALREADY_SUBSCRIBED.equals(response)) {
Logger.info("msg Registered successfully for BIS push");
return true;
} else {
Logger.info("msg BPAS rejected registration");
// isValue = false;
return false;
}
} catch (final IOException e) {
Logger.info("msg IOException on register() " + e + " " + e.getMessage());
//isValue = false;
return false;
}
//return isValue;
}
public static void close(Connection conn, InputStream is, OutputStream os) {
if (os != null) {
try {
os.close();
} catch (IOException e) {
}
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
if (conn != null) {
try {
conn.close();
} catch (IOException e) {
}
}
}
public static void errorDialog(final String message)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert(message);
}
});
}
private static String formRegisterRequest(String bpasUrl, String appId, String token) {
StringBuffer sb = new StringBuffer(bpasUrl);
sb.append("/mss/PD_subReg?");
sb.append("serviceid=").append(appId);
sb.append("&osversion=").append(DeviceInfo.getSoft
sb.append("&model=").append(DeviceInfo.getDeviceNa
if (token != null && token.length() > 0) {
sb.append("&").append(token);
}
return sb.toString();
}
public static String getConnParam(){
String connectionParameters = "";
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
// Connected to a WiFi access point
connectionParameters = ";deviceside=true;interface=wifi";
} else {
int coverageStatus = CoverageInfo.getCoverageStatus();
ServiceRecord record = getWAP2ServiceRecord();
if (record != null
&& (coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage and a WAP 2.0 service book record
connectionParameters = ";deviceside=true;ConnectionUID="
+ record.getUid();
} else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) ==
CoverageInfo.COVERAGE_MDS) {
// Have an MDS service book and network coverage
connectionParameters = ";deviceside=false";
} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage but no WAP 2.0 service book record
connectionParameters = ";deviceside=true";
}
}
return connectionParameters;
}
private static ServiceRecord getWAP2ServiceRecord() {
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.getRecords();
for(int i = 0; i < records.length; i++) {
String cid = records[i].getCid().toLowerCase();
String uid = records[i].getUid().toLowerCase();
if (cid.indexOf("wptcp") != -1 &&
uid.indexOf("wifi") == -1 &&
uid.indexOf("mms") == -1) {
return records[i];
}
}
return null;
}
But i m getting the below error
Timeout occurred while processing the operation.
Please see the log from the device below
INFO: File Created successfully
INFO: MyScreen.registerBpas()
INFO: --------- step 1
INFO: -------------> conparam : ;deviceside=true;ConnectionUID=WAP2 trans
INFO:
msg registerBPAS URL is: http://pushapi.eval.blackberry.com/mss/PD_subReg?s
INFO:
msg RESPOSE CODE :
Timeout occurred while processing the operation.
INFO:
msg nextUrl : http://pushapi.eval.blackberry.com/mss/PD_subReg?s
Timeout occurred while processing the operation.
;deviceside=true;ConnectionUID=WAP2 trans
INFO:
msg RESPOSE CODE 1:
Received a malformed request.
INFO: msg BPAS rejected registration
INFO: ----------isSub : false
Solved! Go to Solution.
05-22-2012 01:39 AM
Hi Simon
I am using the sample BIS push code provided by you, I have given the details & error that i am getting during this implementation.
Can you please help me out, as it is a very urgent requirement for my client..........
Thanks
Hidayath
05-22-2012 04:12 AM
05-22-2012 05:27 AM
Hi Simon
BIS connection you mean connection suffix ?
private static final String CONNECTION_SUFFIX = ";deviceside=false;ConnectionType=seekrit string";
Can I able to test this on simulator ?
Could you please explain how can i Implement push notification End to End (from client to server) i mean procedure.
05-22-2012 07:10 AM
05-22-2012
07:57 AM
- last edited on
05-26-2012
07:45 PM
by
dany_s
Hi Simon
Its working....... Register & de register is working.........
Thank you very much for your reply....
Actually in Connection Suffix I used [removed inappropriate content]
There must be Hyphen (-) between mds & public, its not allowing me to type that text as it is in this forum.
And tested in device.....
This connection suffix is for BIS implementation & now I am able to Register & Deregister my app for Push.
But still I need to test the receiving push message part, once my server implemenation is done.
Once again thanks a lot.............
Thank You
Hidayath