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

BlackBerry Push Development

Reply
New Contributor
blueEyes1986
Posts: 5
Registered: ‎06-05-2013
My Device: Quark 6230
Accepted Solution

Exception in Push Notification BIS

Hi,

I am new to BlackBerry app development. I have written a Java class for Push Notification using PushSDKProperties.

My Class is given below...

 

public

class PushServer {

privatestatic String password = "password";

privatestatic String targetURL = "targetURL";

privatestaticfinal String APP_ID = "app_id";

privatestatic PushSDKProperties getProperties() {

 

PushSDKProperties pushSDKProperties =

new PushSDKPropertiesImpl();

pushSDKProperties.setPpgAddress(

targetURL);

pushSDKProperties.setUsingPublicPush(

true);

pushSDKProperties.setHttpIsPersistent(

false);

pushSDKProperties.setHttpConnectionTimeout(60000);

pushSDKProperties.setHttpReadTimeout(120000);

pushSDKProperties.setUsingXmlParserDtdValidation(

false);

System.

out.println(pushSDKProperties);

return pushSDKProperties;

}

publicstatic Date futureDate(int days){

long futureDateMS = System.currentTimeMillis() + ((long)days) *24*60*60*1000;

Date futureDate =

new Date();

futureDate.setTime(futureDateMS);

return futureDate;

}

publicstaticvoid main(String[] args) {

try {

IdGenerator idGenerator =

new IdGeneratorImpl();

List<String> addresses =

new ArrayList<String>();

Date deliverBeforeTimestamp = futureDate(90);

// addresses.add("push_all");

addresses.add(

"correct_address");

addresses.add(

"Incorrect_address");

PushMessageControl pushMessageControl =

new PushMessageControl(idGenerator, APP_ID, addresses);

pushMessageControl.setDeliverBeforeTimestamp(deliverBeforeTimestamp);

Content content =

new TextContent("Hello World");

PapService papService =

new PapServiceImpl();

PushSDKProperties pushSDKProperties = getProperties();

HttpClientImpl client =

new HttpClientImpl();

client.setPushSDKProperties(pushSDKProperties);

papService.setHttpClient(client);

papService.setPushSDKProperties(pushSDKProperties);

System.

out.println("1. "+papService);

System.

out.println("2. "+pushMessageControl);

System.

out.println("3. Upto this No exception");

System.

out.println("4. "+pushSDKProperties.getPpgAddress());

 

String pushId1 = pushMessageControl.getPushId();

 

PushResponse response = papService.push(

APP_ID, password, APP_ID, pushMessageControl, content);

 

System.

out.println(response.getDescription());

System.

out.println(response.getResult());

System.

out.println(response.getPushId());

System.

out.println(response.getCode());

 

 

 

}

catch (UnauthorizedException e) {

e.getCause();

}

catch (PushSDKException e) {

e.getCause();

}

catch (BadMessageException e) {

e.getCause();

}

catch (Exception e) {

e.printStackTrace();

e.getCause();

}

}

 

}

 

 

My code is working fine for a Single Address (Correct Address / Valid Device) and my Device is getting the Notification Message.

My Problem is with Sending Notification to Multiple Devices. If I give more than One Address and one of the addresses is wrong / Incorrect / Address belongs to the device is switched off,  then its throwing me the BadMessageException- Response Code 2000 Invalid / Missing Attribute....

My Question is how can I make my code work irrespective of the correct or incorrect addresses, I mean how can I get the individual response code for each Address / Device.
I want Success message for the Correct Address and Invalid error code / message for the Invalid / Incorrect Address.

What do I need to do ? Any code changes or anything ?

Please help.

Thanks in advance...

 

Please use plain text.
BlackBerry Development Advisor (Retired)
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Exception in Push Notification BIS

Hi,

 

No, you should not being get back a BadMessageException for multiple addresses.

What kind of "incorrect address" are you specifying?

And, how is it incorrect?  It should still be a valid PIN.

 

Matt

Please use plain text.
New Contributor
blueEyes1986
Posts: 5
Registered: ‎06-05-2013
My Device: Quark 6230

Re: Exception in Push Notification BIS

Actually when I am adding an incorrect PIN in the address list, I am getting the exception...for only correct PIN its working fine...So the combination of a correct PIN and an Incorrect PIN, it is throwing the BadMessageException

Please use plain text.
New Contributor
blueEyes1986
Posts: 5
Registered: ‎06-05-2013
My Device: Quark 6230

Re: Exception in Push Notification BIS

By saying incorrect PIN I want to tell that any arbitrary PIN which is not valid...

Please use plain text.
New Contributor
blueEyes1986
Posts: 5
Registered: ‎06-05-2013
My Device: Quark 6230

Re: Exception in Push Notification BIS

Hi Matt,

 

Thanks for your reply...I have one more question...

If I give 3 correct addresses then how to get the individual response code for each of them?

is it possible? If So then How?

 

Thanks

Please use plain text.
BlackBerry Development Advisor (Retired)
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Exception in Push Notification BIS

Even if it's an arbitrary PIN that is 8 digits then you should not be getting BadMessageException back.

 

The general assumption for push is that you do a fire-and-forget.  You send the push to the given set of addresses and it will reliably send it to a BlackBerry device (if that device has your application running and has registered to receive pushes) without you needing to check up on the final delivery status.

 

On your end, you would need to maintain a list of PINs that have successfully registered to receive pushes for your application so that you know which devices you can send pushes to.

 

Matt

Please use plain text.
New Contributor
blueEyes1986
Posts: 5
Registered: ‎06-05-2013
My Device: Quark 6230

Re: Exception in Push Notification BIS

Hi Matt

 

Thanks a lot...I have got my answers from your reply.

Thank you again...:smileyhappy:

 

Joy

Please use plain text.