net.rim.pushsdk.pap
Class PapServiceImpl

java.lang.Object
  extended by net.rim.pushsdk.pap.PapServiceImpl
All Implemented Interfaces:
PapService

public class PapServiceImpl
extends Object
implements PapService

Class implementing the PapService interface that defines push operations to send PAP 2.1/2.0 XML to a Push Proxy Gateway (PPG) and parse the PAP XML responses.

Dependencies that must be injected to properly initialize this object for use:
- httpClient
- pushSDKProperties

Author:
mdicesare

Constructor Summary
PapServiceImpl()
           
 
Method Summary
 CancelResponse cancel(String username, String password, CancelMessageControl cancelMessage)
          Sends a cancel request using the attributes in the cancelMessage.
 void onNotification(ResultNotification resultNotification, Map<String,String[]> notificationParameters)
          Implement this method in order to perform custom actions/business logic upon receiving a result notification.
 PushResponse push(String username, String password, String destination, PushMessageControl pushMessage, Content content)
          Sends a push request with the specified content using the specified attributes.
 ResultNotificationResponseControl receiveNotification(String notificationMessage, Map<String,String[]> requestParameters)
          Called when a raw result notification message is received from the PPG over HTTP (e.g.
 void setHttpClient(HttpClient httpClient)
          Support for dependency injection.
 void setPushSDKProperties(PushSDKProperties pushSDKProperties)
          Support for dependency injection.
 StatusQueryResponse statusQuery(String username, String password, StatusQueryMessageControl statusQueryMessage)
          Sends a status query request using the attributes in the statusQueryMessage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PapServiceImpl

public PapServiceImpl()
Method Detail

setHttpClient

public void setHttpClient(HttpClient httpClient)
Description copied from interface: PapService
Support for dependency injection. This will override the default HttpClient implementation.

Specified by:
setHttpClient in interface PapService
Parameters:
httpClient - the HTTP client

setPushSDKProperties

public void setPushSDKProperties(PushSDKProperties pushSDKProperties)
Description copied from interface: PapService
Support for dependency injection. This will override the default PushSDKProperties implementation.

Specified by:
setPushSDKProperties in interface PapService
Parameters:
pushSDKProperties - the push SDK properties

push

public PushResponse push(String username,
                         String password,
                         String destination,
                         PushMessageControl pushMessage,
                         Content content)
                  throws PushSDKException,
                         BadMessageException,
                         UnauthorizedException
Description copied from interface: PapService
Sends a push request with the specified content using the specified attributes.

Note: If content was specified, then this method will check if a Push-Message-ID header has been specified as part of the top-most Content. If it has not, a Push-Message-ID header will be automatically added with the push id. This may assist in implementing duplicate message detection on the device side and various other use cases.

Example to send a push to a public/BIS PPG:

 PushMessageControl pushMessageControl = new PushMessageControl(PPGType.PUBLIC_PUSH);
 <call other setters>...
 
Content content = new TextContent("My content to push");
PushResponse response = papService.push(pushApplicationId, password, pushApplicationId, pushMessageControl, content); if(response.getCode() == StatusCode.ACCEPTED) ...

Specified by:
push in interface PapService
Parameters:
username - the username of the Push Initiator (for a public (BIS) push, this would be the application id; for an enterprise (BES) push or an enterprise (BDS) push, this might be null if no credentials are required to initiate a push)
password - the password of the Push Initiator (for a public (BIS) push, this would be the application password; for an enterprise (BES) push or an enterprise (BDS) push, this might be null if no credentials are required to initiate a push)
destination - for a public (BIS) push, the application id to push the content to, in other words this would be equivalent to the username parameter; for an enterprise (BES) push, the application port to push the content to; for an enterprise (BDS) push it is the application id that can be either the BDS automatically generated application package identifier or a provider chosen arbitrary application id or port for legacy purposes. Note: In order to use a provider chosen application id you must set an MDS property in rimpublic.property file of "push.application.validation=false".
pushMessage - the push message control attributes needed to construct the PAP request
content - the content of the push message
Returns:
the PAP response from the PPG for the push request
Throws:
PushSDKException - if the message could not be sent for various other reasons (e.g. a malformed PPG URL, if the PAP XML response returned by the PPG could not be parsed by this SDK, etc.)
BadMessageException - if the PPG returned a badmessage-response (i.e. the PPG could not understand/parse the PAP XML sent by the SDK)
UnauthorizedException - the push did not succeed due to authorization failure at the PPG

cancel

public CancelResponse cancel(String username,
                             String password,
                             CancelMessageControl cancelMessage)
                      throws PushSDKException,
                             BadMessageException,
                             UnauthorizedException
Description copied from interface: PapService
Sends a cancel request using the attributes in the cancelMessage. Cancel allows you to request to stop delivery of a previously submitted push request. The PPG usually delivers the message very quickly so cancel is only effective when the push message is being held by the PPG and before the expiry time of the message has arrived (e.g. when the push is sent to a device that is out of coverage the PPG will hold on to the push message until the device comes back into coverage or the expiry time passes). Cancel is only supported for applications with a service level of Push Plus for public/BIS PPG and is included for enterprise/BES/BDS.

Example to send a cancel to a public/BIS PPG:

 CancelMessageControl cancelMessageControl = new CancelMessageControl(PPGType.PUBLIC_PUSH);
 <call other setters>...
 
CancelResponse response = papService.cancel(pushApplicationId, password, cancelMessageControl);

Specified by:
cancel in interface PapService
Parameters:
username - the username of the Push Initiator (for a public (BIS) push, this would be the application id; for an enterprise (BES) push or an enterprise (BDS) push, this might be null)
password - the password of the Push Initiator (for a public (BIS) push, this would be the application password; for an enterprise (BES) push or an enterprise (BDS) push, this might be null)
cancelMessage - the cancel message attributes needed to construct the PAP request
Returns:
the PAP response from the cancel request
Throws:
PushSDKException - if the cancel could not be sent for various other reasons (e.g. a malformed PPG URL, the PAP XML response returned by the PPG could not be parsed by this SDK, etc.)
BadMessageException - if the PPG returned a badmessage-response (i.e. the PPG could not understand/parse the PAP XML sent by this SDK)
UnauthorizedException - the cancel did not succeed due to authorization failure at the PPG

statusQuery

public StatusQueryResponse statusQuery(String username,
                                       String password,
                                       StatusQueryMessageControl statusQueryMessage)
                                throws PushSDKException,
                                       BadMessageException,
                                       UnauthorizedException
Description copied from interface: PapService
Sends a status query request using the attributes in the statusQueryMessage. Status Query allows you to find out the current status of the push request. Status query is only supported for applications with a service level of Push Plus for public/PPG and is included for enterprise/BES/BDS.

Example to send a status query to a public/BIS PPG:

 StatusQueryMessageControl statusQueryMessageControl = new StatusQueryMessageControl(PPGType.PUBLIC_PUSH);
 <call other setters>...
 
StatusQueryResponse response = papService.statusQuery(pushApplicationId, password, statusQueryMessageControl);

Specified by:
statusQuery in interface PapService
Parameters:
username - the username of the Push Initiator (for a public (BIS) push, this would be the application id; for an enterprise (BES) push or an enterprise (BDS) push, this might be null)
password - the password of the Push Initiator (for a public (BIS) push, this would be the application password; for an enterprise (BES) push or an enterprise (BDS) push, this might be null)
statusQueryMessage - the status query message attributes needed to construct the PAP request
Returns:
the PAP response from the status query request
Throws:
PushSDKException - if the PAP XML response returned by the PPG could not be parsed by this SDK
BadMessageException - if the PPG returned a badmessage-response (i.e. the PPG could not understand/parse the PAP XML sent by this SDK)
UnauthorizedException - the status query did not succeed due to authorization failure at the PPG

onNotification

public void onNotification(ResultNotification resultNotification,
                           Map<String,String[]> notificationParameters)
                    throws PushSDKException
Description copied from interface: PapService
Implement this method in order to perform custom actions/business logic upon receiving a result notification.
The default implementation of PapServiceImpl with this SDK is a no-op implementation. You may want to extend the default implementation PapServiceImpl and implement your own processing like updating the status of the push request in a persist store

Specified by:
onNotification in interface PapService
Parameters:
resultNotification - the result notification sent by the PPG
notificationParameters - request parameters from the result notification sent by the PPG
Throws:
PushSDKException - if the result notification cannot be processed

receiveNotification

public ResultNotificationResponseControl receiveNotification(String notificationMessage,
                                                             Map<String,String[]> requestParameters)
Description copied from interface: PapService
Called when a raw result notification message is received from the PPG over HTTP (e.g. by a servlet).
The default implementation will unmarshal the result notification and validate its fields, construct the result notification response, and call the onNotification method with the result notification request.

Specified by:
receiveNotification in interface PapService
Parameters:
notificationMessage - PAP result notification XML message as a UTF-8 string
requestParameters - Request parameters from the result notification sent by the PPG
Returns:
result notification response to be sent to the PPG


Send feedback

Copyright © 2013 BlackBerry. All rights reserved.