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
Developer
massimo_olive
Posts: 235
Registered: ‎11-08-2010
My Device: Not Specified

Push SDK using low level APIs

To send a push to BIS push server....

 

IdGenerator idGenerator = new IdGeneratorImpl();

 

List<String> addresses = new ArrayList<String>();

addresses.add("<fill in PIN>");

 

Content content = new TextContent("push message to send");

 

PushMessageControl pushMessageControl = new PushMessageControl(true, idGenerator,

appId, addresses);

pushMessageControl.setDeliverBeforeTimeStamp(new Date((60 * 60 * 8));

 

PapService papService = PapBeanLocator.get PapService ();

PushResponse response = papService.push(appId, password, appId, pushMessageControl, content);



Developer
massimo_olive
Posts: 235
Registered: ‎11-08-2010
My Device: Not Specified

Re: Push SDK using low level APIs

Push to a BES server...

 

IdGenerator idGenerator = new IdGeneratorImpl();

 

List<String> addresses = new ArrayList<String>();

addresses.add("<fill in PIN>");

 

PushMessageControl pushMessageControl = new PushMessageControl(false, idGenerator,

appId, addresses);

pushMessageControl.setDeliverBeforeTimeStamp(new Date((60 * 60 * 8));

 

Content content = new TextContent("push message to send");

 

PapService papService = PapBeanLocator.getPapService();

 

PushResponse response = papService.push(null, null, port, pushMessageControl, content);



Developer
massimo_olive
Posts: 235
Registered: ‎11-08-2010
My Device: Not Specified

Re: Push SDK using low level APIs

Query the status of a specific device at the BIS push server....

 

Set<String> address = new HashSet<String>();

address.add("<fill in PIN">);

 

SubscriptionQuerySerivce queryService = QueryBeanLocator.getSubscriptionQueryService();

subscriptionQueryResponse = queryService.querySubscriptionStatus(appId, password, address);



 

Query for all active devices at the BIS push server....

SubscriptionQuerySerivce queryService = QueryBeanLocator.getSubscriptionQueryService();

subscriptionQueryResponse = queryService.querySubscriptionStaus(appId, password, SubQueryRequestStatus.ACTIVE);

 

Contributor
efung
Posts: 11
Registered: ‎05-06-2010
My Device: Bold 9700

Re: Push SDK using low level APIs

These are great examples! Just wanted to point out that the use of classes such as QueryBeanLocator or PapBeanLocator will force a dependence on Spring in your application or utility.

 

If you don't want to use Spring, you could instantiate the service implementation directly, e.g.

 

    SubscriptionQueryService service = new SubscriptionQueryServiceImpl()

    PushSDKProperties properties = new PushSDKPropertiesImpl();

    HttpClientImpl client = new HttpClientImpl();

    client.setPushSDKProperties( properties );

    service.setHttpClient( client );

    service.setPushSDKProperties(properties);

 

 

Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: Push SDK using low level APIs

 

This is a complete basic sample in java that has no dependency on spring, yo can run it from the commandline, nice for testing.

 

public class TestPush3 {
    private static String password = "<password provided by RIM>";   

    private static String targetURL = "<push URL>";

    private static final String APP_ID = "<Your Applicaiton ID from RIM>";

 

   public static void main(String[] args) throws PushSDKException, BadMessageException, UnauthorizedException {

 

   IdGenerator idGenerator = new IdGeneratorImpl();List<String> addresses = new ArrayList<String>();

   //addresses.add("push_all");

   addresses.add("<PIN of the phone>");

   PushMessageControl pushMessageControl = new PushMessageControl(idGenerator,APP_ID, addresses);

   Content content = new TextContent("This is my push message to send - cnd 6 - PIN");

   PapService papService = new PapServiceImpl();

   PushSDKProperties properties = getProperties();

   HttpClientImpl client = new HttpClientImpl();

   client.setPushSDKProperties( properties );

   papService.setHttpClient( client );

   papService.setPushSDKProperties(properties);

   PushResponse response = papService.push(APP_ID, password, APP_ID, pushMessageControl, content);

   System.out.println(response.getDescription());

}


private static PushSDKProperties getProperties() {

PushSDKProperties p = new PushSDKPropertiesImpl();p.setPpgAddress(targetURL);

p.setUsingPublicPush(true);

p.setHttpIsPersistent(false);

p.setHttpConnectionTimeout(60000);

p.setHttpReadTimeout(120000);

p.setUsingXmlParserDtdValidation(true);

return p;

}

 

Chris

Regular Visitor
kanzari
Posts: 1
Registered: ‎04-17-2012
My Device: 9800

Re: Push SDK using low level APIs

hi, what jar i have to add. because i have a message 

IdGenerator cannot be resolved to a type 

 

Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: Push SDK using low level APIs

[ Edited ]

acknowledgement-1.0.0.5.jar

commons-pushsdk-1.0.0.5.jar

pap-1.0.0.5.jar

push-1.0.0.5.jar

push-app-mgmt-1.0.0.5.jar

subscription-1.0.0.5.jar

commons-codec-1.5.jar

New Contributor
valera
Posts: 8
Registered: ‎03-30-2010
My Device: BlackBerry Stor 9530

Re: Push SDK using low level APIs

I'm executing the code you provided, except for I replaced deprecated methods with proper ones. Now my method getProperties() looks like following:

 

private static PushSDKProperties getProperties() {
PushSDKProperties p = new PushSDKPropertiesImpl();
p.setPublicPpgAddress("https://pushapi.eval.blackberry.com");
 p.setHttpIsPersistent(false);
p.setHttpConnectionTimeout(60000);
p.setHttpReadTimeout(120000);
return p;
}

 

And I'm getting

net.rim.pushsdk.commons.PushSDKException: Bad HTTP response returned: HttpResponse ( net.rim.pushsdk.commons.http.HttpResponse@116ab4e    statusCode = 400    content =     contentType = null     )

 

Thanks in advance

Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: Push SDK using low level APIs

At a quick look, it seems that public push has not been set to true. Also check you test account has not expired, that will give you a 400 error also.

New Contributor
valera
Posts: 8
Registered: ‎03-30-2010
My Device: BlackBerry Stor 9530

Re: Push SDK using low level APIs

[ Edited ]

Thanks a lot for such quick response!

But I set public push to "true". I do it both in constructor 

PushMessageControl pushMessageControl = new PushMessageControl(true,
idGenerator, APP_ID);

and in PushSDK.properties:smileyhappy:

 

And my test account is still valid..

 

Here is my main method

 

public static void main(String[] args) throws PushSDKException,
			BadMessageException, UnauthorizedException {

		IdGenerator idGenerator = new IdGeneratorImpl();
		List<String> addresses = new ArrayList<String>();
		addresses.add("27f45fc5");
		PushMessageControl pushMessageControl = new PushMessageControl(true,
				idGenerator, APP_ID);
		pushMessageControl.setAddressList(addresses);
		
		Content content = new TextContent(
				"This is my push message to send - cnd 6 - PIN");
		PapService papService = new PapServiceImpl();
		PushSDKProperties properties = getProperties();
		HttpClientImpl client = new HttpClientImpl();
		client.setPushSDKProperties(properties);
		papService.setHttpClient(client);
		papService.setPushSDKProperties(properties);
		PushResponse response = papService.push(APP_ID, PASSWORD, APP_ID,
				pushMessageControl, content);
		System.out.println(response.getDescription());
	}