Bb push sapra


Published on

Published by Althea Elfleda Tolentino McGregor, BlackBerry Dev Alpha, January 2012, Licensed Vendor for BlackBerry World App and Development, Social Media, Digital Content by BlackBerry Laws, Copyrights, Authorship, Commercial Rights and Compliance , Health & Safety Compliance, IP Laws Pioneer for Data Encryption, Global Entrepreneur, Global Sales and Social Media Networking, Global Vending, Attributed Use for all Global Resellers of BlackBerry Products and Services, Digital Content, Patent, Global Promotion for BlackBerry Apps Development and the Foundation for a Raving Tigers BlackBerry Business Solutions as per stipulations and agreements on policies and rights over use , print and distribution to re-distribution over corporations of Global Merchandising of Communication Devices that pioneers data encryption and Social Hubs as attributions to the hallmarks of BlackBerry Dev Alpha C into the market release version of the BlackBerry Z10 and BlackBerry Q10 as separate and treated as one unit of manufactured programming,from its concept to approval which must meet Blackberry standard for its release and hacked for its vulnerability on CrackBerry exclusive to both "Gods" and Demons" of this world of the Fruit-wares, called BlackBerry and these could be coded as well. Z10 and Q10. Written by: Althea Elfleda Tolentino McGregor, Blackberry Dev Alpha A to C, 2012 to present and 10% only addicted, for the love of GOD! No mercy until I get my millions and a private jet, a school or an intellectual law institution or many. I am the Pioneer of WORK IN MOTION FOR my Raving Tigers Business Solutions which is for micro/macro economic developments and dependent on consumerism as well as the provision of scholarships to increase revenues for BlackBerry in the deliverance of its goal for mobilisation of these technologies, as an integral part of the backbone of every struggling small business owners who only needs one device, a BlackBerry. © 2013 Research In Motion Limited, 295 Phillip St., Waterloo, Ontario, Canada, N2L 3W8. All rights reserved. BlackBerry®, RIM®, Research In Motion® and related trademarks, names and logos are the property of RIM and are registered and/or used in the U.S. and countries around the world.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Bb push sapra

  1. 1. BlackBerry Push Infrastructure at Work: Introduction to the BlackBerry Push API Pratik Sapra Application Development Specialist
  2. 2. BlackBerry Push Infrastructure at Work: Introduction to the BlackBerry Push API • Overview • Architecture • Implementation • Security & Reliability • Requesting Access
  3. 3. Why use Push? • The data is on the device when the user needs it • Data is delivered as soon as it is available • Application is always actively listening for data arrival • User can be immediately notified of new data • Audio alert, vibration, blinking LED, pop-up dialog, icon change, banner notification • The user experience is that it just happened • appearance of zero latency
  4. 4. Push Vs Poke-Pull • Push • Allows the delivery of content to a device without the device having to request it • The data is sent to a port on the device where an application is listening for it • Push is generally server based/mediated • Push Initiator • The Push Initiator submits a request to the Hosted Data Push Service • Contains delivery instructions and the payload – Delivery instructions describe where and how the data is to be sent – The payload may be any type of data • Poke-and-Pull • Poke: a notification and URL are pushed to a device • Pull: the device fetches the content at the URL • Less efficient than true push
  5. 5. BlackBerry Push API • Compare to Polling • Client periodically asks a server if an event of interest has occurred • Inefficient – increases OTA costs and traffic • there may be many polling attempts to fetch a single event • Delays in getting data due to polling latency (interval) • Depending on polling interval, received data may be outdated • Wastes battery life checking whether an event of interest has occurred • Generates extra server traffic and load for your application • 1,000,000 devices x 12 polls/hr x 24 hours = 288,000,000 requests per day • Doesn’t scale
  6. 6. BlackBerry Push API • Provides a transport infrastructure for Server to Device pushed data • Primary focus on consumer applications • Alerts • Replace polling to improve performance & reduce costs • Poke-Pull model • Event driven systems • Near real-time notifications • Can be used for enterprise deployments • Cross company applications • Enterprises without a BlackBerry Enterprise Server
  7. 7. Benefits • Provides information immediately • Optimizes network efficiency • Preserves the battery life • Reduces complexity for developers • Improves developer margins
  8. 8. Architecture • Pushes are initiated on the Server • Server side application is required • Server to Server interface for the Push Initiator • BlackBerry Infrastructure is the middleware • Sends data to a specified port on the Device • Client side Java application required to receive the push • Uses PAP 2.2 Standard push protocols • OMA-WAP-TS-PAP-V2_2-20071002-C • Requests are HTTP XML requests • Supported requests: • Submit Push • Cancel Push • Query for Status • Response: • Result notification
  9. 9. Components Three major components: • The server-side push service • A client-side application • BlackBerry Infrastructure
  10. 10. Push Workflow Mobile Client Push Request Response BlackBerry Infrastructure 1 2 3 4 5 6 Push Push Initiator 1. Server sends PAP Push which contains a list of specified devices 2. BlackBerry Infrastructure sends response to Server and queues request 3. BlackBerry Infrastructure pushes data to specified devices 4. Each device sends ACK to BlackBerry Infrastructure 5. BlackBerry Infrastructure sends notification to Server 6. Server sends Read notification to BlackBerry Infrastructure
  11. 11. About the Push • Push sent to user’s PIN • Maximum payload is 8 KB • Types of Push: • Point to Point (Single PIN) • Multicast (List of PINs) • Broadcast (All PINs by application) • BlackBerry Infrastructure will attempt to deliver the message until expiry time • Automatic retries if device is out of coverage • Expiry time can be configured to a maximum of 8 hours
  12. 12. Sample Push Request --PMasdfglkjhqwert Content-Type: application/xml <?xml version="1.0"?> <!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" ""> <pap> <push-message push-id="999999999" source-reference="AAAAAAAAAAAA" deliver-before-timestamp="2008-09-31T13:30:00Z" ppg-notify-requested-to="notify_url_path"> <address address-value="PIN00001"/> <address address-value="PIN00002"/> <address address-value="PIN00003"/> <quality-of-service delivery-method="confirmed"/> </push-message> </pap> --PMasdfglkjhqwert Content-Encoding: binary Content-Type: text/html Text or binary content to be delivered to BlackBerry device goes here. --PMasdfglkjhqwert--
  13. 13. Sample Code: Push Request (1 of 2) HttpURLConnection mdsConn = null; InputStream ins = null; OutputStream outs = null; String errorCode = null; try { URL mdsUrl = new URL(BLACKBERRY_INFRASTRUCTURE_URL); mdsConn = (HttpURLConnection) mdsUrl.openConnection(); String boundary = ""; boundary = "asdlfkjiurwghasf"; mdsConn.setRequestProperty("Content-Type", "multipart/related; type="application/xml";boundary=" + boundary); String auth = "Basic " + new BASE64Encoder().encode((_psid + ":" + _password).getBytes()); mdsConn.setRequestProperty("Authorization", auth); mdsConn.setRequestMethod("POST"); mdsConn.setAllowUserInteraction(false); mdsConn.setDoInput(true); mdsConn.setDoOutput(true); /* … Continued on next slide … */
  14. 14. Sample Code: Push Request (2 of 2) String papPush = “…”; //push message outs = mdsConn.getOutputStream(); copyStreams(new ByteArrayInputStream(output.getBytes()), outs); mdsConn.connect(); ins = mdsConn.getInputStream(); ByteArrayOutputStream response = new ByteArrayOutputStream(); copyStreams(ins, response); int httpCode = mdsConn.getResponseCode(); if( httpCode != HttpURLConnection.HTTP_ACCEPTED && httpCode != HttpURLConnection.HTTP_OK ) { //Push failed } else { //HTTP Connection successful //Parse the response notification message to confirm successful push (not shown here) } } catch(Exception ex) { errorCode = ex.getClass().getName(); } finally { /* close input and output streams and close the connection */ }
  15. 15. Sample Cancel Request • Any queued pushes can be cancelled • Previously pushed content cannot be recalled • Result notification sent from BlackBerry Infrastructure – Confirms for which devices the pushes were and were not cancelled • Uses WAP PAP <cancel-message> element
  16. 16. Sample Cancel Request Content-Type: application/xml <?xml version="1.0"?> <!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" ""> <pap> <cancel-message push-id="999999999"> <address address-value="PIN00001"/> <address address-value="PIN00002"/> <address address-value="PIN00003"/> </cancel-message> </pap>
  17. 17. Status Request • Query for the status of a submitted request • Status is maintained for 24 hours • If multiple recipients • response will contain a status for all of them • Status is a snapshot • i.e. reflective only of the current moment in time • Uses WAP PAP <statusquery-message> element
  18. 18. Sample Status Request Content-Type: application/xml <?xml version="1.0"?> <!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" ""> <pap> <statusquery-message push-id="999999999"> </statusquery-message> </pap>
  19. 19. Response Notifications • Sent to the Server URL if specified, none otherwise • Be prepared to handle these – there will be many of them – Quality of Service Levels • Application – Message reached the application • Transport – Message reached the device • None – Fire and forget
  20. 20. Listening for Push • User installs mobile application • On first run, mobile application registers with BlackBerry Infrastructure – Creates HTTPS connection to Infrastructure URL • Headers identify PIN and PSID • BlackBerry Infrastructure validates the mobile application • BlackBerry Infrastructure returns pass/fail to mobile application
  21. 21. Sample Code: Listening for Push StreamConnection stream; InputStream ins; MDSPushInputStream pushInputStream; //use the port assigned to your application StreamConnectionNotifier notifier = (StreamConnectionNotifier)"http://:110"); while( !_stop ) { stream = _notifier.acceptAndOpen(); //blocking operation input = stream.openInputStream(); pushInputStream = new MDSPushInputStream((HttpServerConnection) stream, input); DataBuffer buffer = new DataBuffer(); byte[] data = new byte[ 256 ]; int chunk = 0; while( -1 != (chunk = ) { buffer.write(data, 0, chunk); } /* … process the data on the DataBuffer ... */ // Signal that we have finished reading. pushInputStream.accept(); }
  22. 22. Security • BlackBerry Infrastructure Authentication • Push Initiator is authenticated to the BlackBerry Infrastructure • Push Initiator can only push to its mobile application • 1:1 relationship between Push Initiator and mobile application • Push Initiator can only push to devices registered for their application • Each push request is authenticated to BlackBerry Infrastructure • Unique listening port for each application • BlackBerry Infrastructure does not encrypt data • Expects that payload data will already be encrypted by Push Initiator • Content Provider Authentication • Mobile application should be authenticated to the Push Initiator
  23. 23. Reliability • Choose the appropriate QoS for your application • There are tradeoffs for performance and battery life • Be sure to handle all request failures in your application • Result notifications • Your server app must be prepared to handle these, if you request them • Server outages - RIM infrastructure will retry deliveries … for a while • Always provide an unsubscribe option in your device application • Highest reliability can be achieved by application acknowledgement direct to your server
  24. 24. Requesting Access • Register at • Sample code provided on registration approval • Content Provider tests the push service • Given access to the evaluation infrastructure • Research In Motion validates the Content Provider’s client and server-side applications • Ensuring development guidelines are met • Service is moved into production • Once all requirements are met • Only available to ISV Alliance Partners • To become an ISV Alliance partner visit • Contact for service costs
  25. 25. Thank You Pratik Sapra – Application Development Specialist