01-17-2013 07:21 AM
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_pushReq uest");
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.validateAppFo rPush(PushServiceImpl.java:634)
at net.rim.pushsdk.push.PushServiceImpl.validatePush( PushServiceImpl.java:648)
at net.rim.pushsdk.push.PushServiceImpl.push(PushServ iceImpl.java:196)
at com.etisalat.mobilenotification.BlackBerryNotifier .sendNotificationWithPushService(BlackBerryNotifie r.java:197)
at com.etisalat.mobilenotification.BlackBerryNotifier .push(BlackBerryNotifier.java:74)
Please, what provide me with the feedback
Thanks
01-17-2013 09:20 AM
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://<cp id>.pushapi.eval.blackberry.com/mss/PD_pushRequest ");
pushSDKProperties.setHttpIsPersistent(true);
pushSDKProperties.setHttpConnectionTimeout(60000);
pushSDKProperties.setHttpReadTimeout(120000);
char[] specialChars = { '&', '"', ':', '<' };
pushSDKProperties.setParserSpecialCharacters(speci alChars);
pushSDKProperties.setDtdDeclarationPublic("<!DOCTY PE 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(pushSDKPro perties);
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/subcatego
01-17-2013 11:53 AM
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
01-17-2013 12:04 PM
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.
01-20-2013 04:41 AM
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