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
victorhugo
Posts: 8
Registered: ‎07-23-2013
My Device: Dev Alpha B
My Carrier: BB
Accepted Solution

Problem with SEND Push Notification!

I porting .apk to .bar (apk2bar), and need to send push messages to device (Dev Alpha B)

but i can´t localize Boundary code and the sender result error.


This my PHP server sender:

 

public function sendNotificationBlackBerry($registatoin_tokens, $message) {
$appid = '4038-8si785997a3eir572168c5f821291rl8a84';
$password = 'Ja50N4Hu1d';
$boundary = "mPsbVQo0a68eIL3OAxnm";
$appport = "33664";
$deliverbefore = gmdate('Y-m-d\TH:i:s\Z', strtotime('+2 minutes'));

//An array of address must be in PIN format or "push_all"
$addresses = '';
foreach ($registatoin_tokens as $value) {
$addresses .= '<address address-value=' . $value . '/>';
}
// create a new cURL resource
$ch = curl_init();
$messageid = microtime(true);

$data = '--' . $boundary . "\r\n" .
'<?xml version="1.0" charset="UTF-8"?>
<!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 . '" source-reference="' . $appid . '" deliver-before-timestamp="' . $deliverbefore . '">'
. $addresses .
'<quality-of-service delivery-method="confirmed"/>
</push-message>
</pap>' . "\r\n" .
'--' . $boundary . "\r\n" .
'Content-Type: text/plain' . "\r\n" .
'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
stripslashes($message) . "\r\n" .
'--' . $boundary . '--' . "\n\r";

// set URL and other appropriate options
// curl_setopt($ch, CURLOPT_URL, "https://pushapi.eval.blackberry.com/mss/PD_pushRequest"); //Erro code 2000 The request is invalid.
curl_setopt($ch, CURLOPT_URL, "https://cpXXXX.pushapi.eval.blackberry.com/mss/PD_pushRequest"); // Error CODE: 2000
// curl_setopt($ch, CURLOPT_URL, "https://pushapi.eval.blackberry.com"); // Invalid document end
// curl_setopt($ch, CURLOPT_URL, "https://cpXXXX.pushapi.eval.blackberry.com"); //Invalid document end

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_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/related; boundary=" . $boundary . "; type=application/xml", "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", "Connection: keep-alive"));

// grab URL and pass it to the browser
$xmldata = curl_exec($ch);
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);
}
// -----------------------------

 

return $xmldata;
}

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Problem with SEND Push Notification!

Can you please post the resultant XML created by the below code as well as the headers used?

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
New Contributor
victorhugo
Posts: 8
Registered: ‎07-23-2013
My Device: Dev Alpha B
My Carrier: BB

Re: Problem with SEND Push Notification!

XML result 

 

--gmjrCBPq8wUYOLb 
<?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="1374773517.3402" 
source-reference="4038-8si785997a3eir572168c5f821291rl8a84" 
deliver-before-timestamp="2013-07-25T17:36:57Z"  >  
<address address-value="2A868200"/>  
<quality-of-service  delivery-method="confirmed"/> 
</push-message>  
</pap> 
--gmjrCBPq8wUYOLb 
Content-Type: text/html 
Hello World
--gmjrCBPq8wUYOLb--

 

and the Headers: 

 

"Content-Type: multipart/related; boundary="gmjrCBPq8wUYOLb"; type=application/xml", "Connection: keep-alive"

 

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Problem with SEND Push Notification!

Try changing the delivery-method to unconfirmed and setting the deliver before timestamp to further in the future.

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
New Contributor
victorhugo
Posts: 8
Registered: ‎07-23-2013
My Device: Dev Alpha B
My Carrier: BB

Re: Problem with SEND Push Notification!

Applying changes occurred other error ...

 

Error CODE: 2000
Error DESC: Invalid Content Header - My_Message 

 

My_Message  is the message I tried to send.

 

and the XML now: 

 

--JcX58MAjkOhziP7 
<?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="1374777994.8438" 
source-reference="4038-8si785997a3eir572168c5f821291rl8a84" 
deliver-before-timestamp="2013-08-10T23:59:00Z"  >  
<address address-value="2A868200"/>  
<quality-of-service  delivery-method="unconfirmed"/> 
</push-message>  
</pap> 
--JcX58MAjkOhziP7 
Content-Type: text/html 
My_Message
--JcX58MAjkOhziP7--

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Problem with SEND Push Notification!

Are you placing "My_Header" in the HTTP Header somewhere?

 

Could you remove this section from the header:

"Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", "Connection: keep-alive"

 

I don't believe it's necessary.

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
New Contributor
victorhugo
Posts: 8
Registered: ‎07-23-2013
My Device: Dev Alpha B
My Carrier: BB

Re: Problem with SEND Push Notification!

The only place I set the header is in the PHP: 

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/related; boundary=" . $boundary . "; type=application/xml"));

 

Look the error 

Error CODE: 2000
Error DESC: Invalid Content Header - My_Message 

 

My_message is the text I try send the push message 

 

(...)
</pap> --JcX58MAjkOhziP7 Content-Type: text/html My_Message --JcX58MAjkOhziP7--

 

 

My_message equivalent "Text or binary content to be pushed to BlackBerry device goes here." in the section code sample

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Problem with SEND Push Notification!

Try adding an empty line between the "Content-Type: text/html" line and your actual payload data. It looks like the system is expecting all headers to be listed in succession, then a space then the payload.

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
New Contributor
victorhugo
Posts: 8
Registered: ‎07-23-2013
My Device: Dev Alpha B
My Carrier: BB

Re: Problem with SEND Push Notification!

Solved!

 

My XML is: 

 

(...)
</pap> --JcX58MAjkOhziP7 Content-Type: text/html My_Message --JcX58MAjkOhziP7--

but the correct is 

 

(...)
</pap> --JcX58MAjkOhziP7 Content-Type: text/html
My_Message
--JcX58MAjkOhziP7--

 

See the spaces around the My_Message

 

It is necessary have spaces !!!! Now works !

 

 

THANKS!

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Problem with SEND Push Notification!

Fantastic! 

 

Please be sure to mark this thread as solved :smileyhappy:

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.