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
romyo0o
Posts: 5
Registered: ‎01-17-2013
My Device: bold

How to use PushService to push notification | NullPointerException

Hello,

 

i'm new in blackberry notification development and i want to send a notification and get back a result with status

 

and I'm using PushService  as below:

 

IdGenerator idGenerator = new IdGeneratorImpl();
    
    Content content = new TextContent("test");
    
    PushService pushService = new PushServiceImpl();
    
     PushSDKProperties pushSDKProperties = new PushSDKPropertiesImpl();
    
    pushSDKProperties.setPublicPpgAddress("https://pushapi.eval.blackberry.com/mss/PD_pushRequest");
    
    pushSDKProperties.setHttpIsPersistent(true);
    
    pushSDKProperties.setHttpConnectionTimeout(60000);
    
    pushSDKProperties.setHttpReadTimeout(120000); PushParameters pushParameters = new PushParameters(id.toString(), bbBins, content); pushParameters.setApplicationReliable(true); pushService.setPushSDKProperties(pushSDKProperties); pushService.setPushIdGenerator(idGenerator); // TODO check below line pushService.setPapService(new PapServiceImpl()); pushService.push(pushParameters);

///////////////////////////////////////////////////////////////

 

 

 

 

it throws null pointer exception

 

Caused by: java.lang.NullPointerException
    at net.rim.pushsdk.push.PushServiceImpl.validateAppForPush(PushServiceImpl.java:634)
    at net.rim.pushsdk.push.PushServiceImpl.validatePush(PushServiceImpl.java:648)
    at net.rim.pushsdk.push.PushServiceImpl.push(PushServiceImpl.java:196)
    at com.etisalat.mobilenotification.BlackBerryNotifier.sendNotificationWithPushService(BlackBerryNotifier.java:197)
    at com.etisalat.mobilenotification.BlackBerryNotifier.push(BlackBerryNotifier.java:74)

 

Please, what provide me with the feedback

 

Thanks

Regular Contributor
mdicesare
Posts: 78
Registered: ‎04-28-2010
My Device: BlackBerry 10 Dev Alpha

Re: How to use PushService to push notification | NullPointerException

From the sample code you posted you are using the high-level APIs of the Push Service SDK (as opposed to the low-level APIs). When you use the high-level APIs you must use the Spring Framework to setup your beans rather than trying to instantiate all the objects yourself as your trying to do. As well we use Spring to apply aspect oriented behaviours such as transaction management. It will be very difficult for you to setup all the objects and their dependencies properly as is the case with the error you are getting. Essentially your PushService object is missing a required dependent object that needs to be injected – PushApplicationService. In fact  the PushService object itself requires all these dependent objects be set (and each of those objects may have their own dependent object that needs to be set).

 * - subscriptionService

 * - pushApplicationService

 * - pushRequestService

 * - pushRequestDetailService

 * - papService

 * - pushSDKProperties

 * - pushIdGenerator

 * - pushCountService

 * - pushStatsService

 

So again, if you are using the high-level APIs use Spring Framework to setup your objects. You can use the BeanLocator* classes to retrieve the beans from the Spring Context as convenience (rather than creating the objects yourself using the ‘new’ operator).

 

If you don’t want to use the Spring Framework and you don’t need the functionality of the high-level APIs then consider using the low-level APIs instead (note: you can use the low-level APIs with Spring too if you want). An example of using the low-level APIs without Spring; you must still setup all the objects correctly:

 

DefaultPropertyStore store = new DefaultPropertyStore();
store.setTimeToLive(60000);

PushSDKPropertiesImpl pushSDKProperties = new PushSDKPropertiesImpl();
pushSDKProperties.setPublicPpgAddress("https://<cpid>.pushapi.eval.blackberry.com/mss/PD_pushRequest");
pushSDKProperties.setHttpIsPersistent(true);
pushSDKProperties.setHttpConnectionTimeout(60000);
pushSDKProperties.setHttpReadTimeout(120000);
char[] specialChars = { '&', '"', ':', '<' };
pushSDKProperties.setParserSpecialCharacters(specialChars);
pushSDKProperties.setDtdDeclarationPublic("<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\">");
pushSDKProperties.setPropertyStore(store);

HttpClientImpl client = new HttpClientImpl();
client.setPushSDKProperties(pushSDKProperties);

PapService papService = new PapServiceImpl();
papService.setHttpClient(client);
papService.setPushSDKProperties(pushSDKProperties);

List<String> addresses = new ArrayList<String>();
addresses.add(<pin>);

PushMessageControl pushMessageControl = new PushMessageControl(true, new IdGeneratorImpl(), <push app id>, addresses);
pushMessageControl.setPushSDKProperties(pushSDKProperties);

Content papContent = new TextContent("My content");

try {
   PushResponse response = papService.push(<push app id>, <push app password>, <push app id>, pushMessageControl, papContent);
    System.out.println(response);
    System.out.println("Response code: " + response.getCode());
} catch(PushSDKException e) {
    e.printStackTrace();
} catch(BadMessageException e) {
    e.printStackTrace();
} catch(UnauthorizedException e) {
    e.printStackTrace();
}

 

To understand the conceptual dfiference between high-level and low-level API options of the Push Service SDK check out the Development Guide at this link:

http://docs.blackberry.com/en/developers/subcategories/?userType=21&category=Push+Service

 

New Contributor
romyo0o
Posts: 5
Registered: ‎01-17-2013
My Device: bold

Re: How to use PushService to push notification | NullPointerException

Thanks mdicesare for your support,

 

But I see that low level push method returns PushResponse

 

and inside this reponse i can access list of results

 

        ResponseResult results = response.getResult();
        results.getCode();

I can access only the result code.

How could I know the subscriber id for each result ,

 

will it be secuenced as the list of the addresses passed to

PushMessageControl pushMessageControl = new PushMessageControl(true, new IdGeneratorImpl(), <push app id>, addresses);

??

 

Thanks

Regular Contributor
mdicesare
Posts: 78
Registered: ‎04-28-2010
My Device: BlackBerry 10 Dev Alpha

Re: How to use PushService to push notification | NullPointerException

No, the response you get from a push submission, regardless of low level or high level only tells you whether the RIM push servers accepted the push or not (i.e. it was a valid request that can be further processed). The rest of the push processing is done asynchronously by the RIM push server. You can only find out the result of the push for each subscriber/address if you are using the Push Plus service level in which case you can issue a status query request or request result notification/acknowledgement for your push message.

 

 

New Contributor
romyo0o
Posts: 5
Registered: ‎01-17-2013
My Device: bold

Re: How to use PushService to push notification | NullPointerException

Yes,I know that the response tells me if the RIM push servers accepted my request or not.

That's what i need

 

but the question: is the list of the results related to the list of subscribers at the same sequence?

 

For example

if I send list of two subscribers and push method returns to me list of two results,

the first result code tells me that server accepts the request

the second result code tells me there's an error

 

so the first result will be related to the first subscriber,

and the seconf result will be related to the second subscriber?

 

Thanks

New Developer
BDigital
Posts: 16
Registered: ‎04-22-2014
My Device: BlackBerry Z10

Re: How to use PushService to push notification | NullPointerException

I have used this example in a JBoss app and getting following exception. Seems like some resource file is missing but cant figure out its name and location where the SDK is searching for it.

 

Any ideas?

New Developer
BDigital
Posts: 16
Registered: ‎04-22-2014
My Device: BlackBerry Z10

Re: How to use PushService to push notification | NullPointerException

 

exception message is :

 

 java.util.MissingResourceException: Can't find bundle for base name PushSDK, locale en_US

 

 

The problem seems to be similar to as in  this forum post but the solution is confusing as he says that "I installed Push SDK under Program Files/BBS, after i unistalled it and tried different directory the error dissapeare."

 

In my case I have placed all provided libraries and property files on my classpath.