06-27-2011 09:53 PM
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);
06-27-2011 09:56 PM
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);
06-27-2011 10:01 PM
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);
07-05-2011 12:15 PM
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);
10-02-2011 08:54 AM
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
05-23-2012 02:28 PM
hi, what jar i have to add. because i have a message
IdGenerator cannot be resolved to a type
05-23-2012 11:49 PM - edited 05-24-2012 02:19 AM
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
06-12-2012 09:49 AM
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
06-12-2012 10:11 AM
06-12-2012 10:20 AM - edited 06-12-2012 10:45 AM
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![]()
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());
}