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
New Contributor
thabang_molefe_99
Posts: 3
Registered: ‎08-02-2012
My Device: Curve 8520
Accepted Solution

Push Server: Eval to Production Error

I have sample PHP code that worked for initiating PUSH messages to device until I was given approval to move from Eval to Production by RIM. I've only updated the PPG URL and authentication details as supplied by RIM but now i get an xml parser error "Invalid Document End"

 

   <?php  
   if ($_POST) {
      //CPID (Content Provider ID) = 189
      $appid = '189-xxxxxxxxxxxxxxxxxxxx';
      //Password provided by RIM
      $password = 'xxxxxxxxxx';
       
       //Deliver before timestamp
       $deliverbefore = gmdate('Y-m-d\TH:i:s\Z', strtotime('+5 minutes'));
   
       $addresstosendto[] = $_REQUEST['bbpin'];      //push only to a specific pin
   
       $addresses = '';
       foreach ($addresstosendto as $value) {
           $addresses .= '<address address-value="' . $value . '"/>';
       }
   
       // create a new cURL resource
       $err = false;
       $ch = curl_init();
       $messageid = microtime(true);    
   
       $message = $_POST['message'];
         
       $data = '--mPsbVQo0a68eIL3OAxnm'. "\r\n" .
      'Content-Type: text/plain; charset=UTF-8' . "\r\n\r\n" .
      '<?xml version="1.0"?>
      <!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd">
      <pap>
      <push-message push-id="' . $messageid . '" deliver-before-timestamp="' . $deliverbefore . '" source-reference="' . $appid . '">'
      . $addresses .
      '<quality-of-service delivery-method="unconfirmed"/>
      </push-message>
      </pap>' . "\r\n" .
       '--mPsbVQo0a68eIL3OAxnm' . "\r\n" .
      'Content-Type: text/plain' . "\r\n" .
      'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
       stripslashes($message) . "\r\n" .
       '--mPsbVQo0a68eIL3OAxnm--' . "\n\r";  
       
       //curl_setopt($ch, CURLOPT_URL, "https://cp189.pushapi.na.blackberry.com/mss/PD_pushRequests");    //PPG URL
       curl_setopt($ch, CURLOPT_URL, "http://cp189.pushapi.na.blackberry.com/mss/PD_pushRequests");    //PPG URL
       
       curl_setopt($ch, CURLOPT_HEADER, false);
       curl_setopt($ch, CURLOPT_USERAGENT, "SAA push application");
       curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
       curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
       curl_setopt($ch, CURLOPT_USERPWD, $appid . ':' . $password);
       curl_setopt($ch, CURLOPT_POST, 1);
       curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/related; boundary=mPsbVQo0a68eIL3OAxnm; type=application/xml", "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", "Connection: keep-alive"));
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   
       // grab URL and pass it to the browser
       $xmldata = curl_exec($ch);
   
       // close cURL resource, and free up system resources
       curl_close($ch);
   
       //Start parsing response into XML data that we can read and output
       $p = xml_parser_create();
       xml_parse_into_struct($p, $xmldata, $vals);
       $errorcode = xml_get_error_code($p);
       if ($errorcode > 0) {
           $err = true;
       }
       xml_parser_free($p);
   
       echo 'Our PUSH-ID: ' . $messageid . "<br \>\n";
       if (!$err && $vals[1]['tag'] == 'PUSH-RESPONSE') {
           echo 'PUSH-ID: ' . $vals[1]['attributes']['PUSH-ID'] . "<br \>\n";
           echo 'REPLY-TIME: ' . $vals[1]['attributes']['REPLY-TIME'] . "<br \>\n";
           echo 'Response CODE: ' . $vals[2]['attributes']['CODE'] . "<br \>\n";
           echo 'Response DESC: ' . $vals[2]['attributes']['DESC'] . "<br \> \n";
       } elseif ($err) {
           echo '<p>An XML parser error has occured</p>' . "\n";
           echo '<pre>' . xml_error_string($errorcode) ."</pre>\n";
           echo '<p>Response</p>' . "\n";
           echo '<pre>' . $xmldata . '</pre>' . "\n";
       } else {
           echo '<p>An error has occured</p>' . "\n";
           echo 'Error CODE: ' . $vals[1]['attributes']['CODE'] . "<br \>\n";
           echo 'Error DESC: ' . $vals[1]['attributes']['DESC'] . "<br \>\n";
           echo '<pre>' . $xmldata . '</pre>' . "\n";
           var_dump($xmldata);
       }
   } else {
       showhtml();
   }
   
   function showhtml() {
       ?>
   <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>" accept-charset="UTF-8" enctype="application/x-www-form-urlencoded">
   <p>BB PIN</p>
   <input type="text" name="bbpin" size="15" value="" />
   <br />
   <br />
   <p>Message to push:</p>
   <textarea name="message" rows="5" cols="80"></textarea>
   <p></p><input type="submit" value="Push Data"></p>
   </form>
   <?php
   }
   ?>

 

and here is the response I get:

 

Our PUSH-ID: 1343931504.2822<br \>
<p>An XML parser error has occured</p>
<pre>Invalid document end</pre>

 

Any help will be greatly appreciated.

Retired
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: Push Server: Eval to Production Error

It looks like you are using HTTP instead of HTTPS though HTTPS is required for the push initiator. What happens when you use HTTPS?

Garett
@garettBeuk
--
Goodbye everybody!
New Contributor
thabang_molefe_99
Posts: 3
Registered: ‎08-02-2012
My Device: Curve 8520

Re: Push Server: Eval to Production Error

Hi Garett,

 

When I use HTTPS the error changes to:

 

"PD_pushRequests command is not currently in service!"

 

 

I've tried:

https://cp189.pushapi.na.blackberry.com/mss/PD_pushRequests

https://cp189.pushapi.na.blackberry.com

https://pushapi.na.blackberry.com/mss/PD_pushRequests

http://cp189.pushapi.na.blackberry.com/mss/PD_pushRequests

 

thanks in advance

Retired
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: Push Server: Eval to Production Error

Ah, that may be the issue, you added an 's' to the end of the URL, it should be:

https://cpXXX.pushapi.na.blackberry.com/mss/PD_pushRequest

 

Rather than:

https://cpXXX.pushapi.na.blackberry.com/mss/PD_pushRequests

 

Give that a try and let me know if it changes anything.

Garett
@garettBeuk
--
Goodbye everybody!
New Contributor
thabang_molefe_99
Posts: 3
Registered: ‎08-02-2012
My Device: Curve 8520

Re: Push Server: Eval to Production Error

Hi Garett,

 

It seems that was the issue, thanks a million