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
Contributor
Posts: 18
Registered: ‎04-05-2013
My Device: Z10

Re: BES10 Push Question

Exactly what I wanted to know. Thanks. Just to clarify, is there any other headers I'm going to need for BES besides the X-Wap-Application-Id? Such as the authorization header - http://docs.blackberry.com/en/developers/deliverables/51382/authorization_headers_1459831_11.jsp ? Thank you. 

Retired
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: BES10 Push Question

You would only need the authorization header if your specific BES PPG enforces a username and password whenever you send a push.

Contributor
Posts: 18
Registered: ‎04-05-2013
My Device: Z10

Re: BES10 Push Question

Thank you.

Contributor
Posts: 18
Registered: ‎04-05-2013
My Device: Z10

Re: BES10 Push Question

I am currently having a problem with my http post. I am writing this in C#. For some reason, when I try to post the multipart message to my BES server, it returns the HTML code of the page that I would see if I were to access the server through a browser. I checked my message and it seems valid, I'm not sure what's the problem. Any help would be appreciated.

 

This is my code:

 

bool success = true;

Stream requestStream = null;
Stream responseStream = null;
HttpWebResponse HttpWRes = null;
HttpWebRequest HttpWReq = null;

try
{
var httpURL = "a valid BES address";

try
{
HttpWReq = (HttpWebRequest)WebRequest.Create(httpURL);
HttpWReq.Method = ("POST");
Console.WriteLine("Established webrequest connection");
}
catch
{
Console.WriteLine("Failed to establish webrequest connection");
}

var boundary = "asdfasdfasdfasdf";
var pushid = "BB10Testid1"; //id that identifies individual push messages
var dmethod = "unconfirmed"; //delivery method
var devicepin = "XXXXXXXX"; //actual device pin or token
var appid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; id from the application manager on BES
var message = "TESTING";

try
{
HttpWReq.ContentType = "multipart/related; boundary=" + boundary + "; type=application/xml ";
HttpWReq.Headers.Add("X-Wap-Application-Id",appid); //identifies the app the push is meant for
Console.WriteLine("Added headers.");
}
catch
{
Console.WriteLine("Failed to add headers");
}

var data = "";

data = "--" + boundary+"\n";
data += "Content-Type: application/xml\n";
data += "<?xml version=\"1.0\"?>";
data += "<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\">";
data += "<pap><push-message push-id=\"" + pushid + "\"> <address address-value=\"" + devicepin + "\"/>";
data += "<quality-of-service delivery-method=\"" + dmethod + "\"/></push-message></pap>";
data += "\n--" + boundary;
data += "\nContent-Encoding:binary";
data += "\nContent-Type:text/plain\n";
data += "X-Wap-Application-Id: " + appid + "\n\n";
data += message;
data += "\n\n--" + boundary + "--";

 

 

byte[] bytes = null;

try
{
bytes = new ASCIIEncoding().GetBytes(data);
HttpWReq.ContentLength = bytes.Length;
Console.WriteLine("Encoded data to binary.");
Console.WriteLine(System.Text.Encoding.UTF8.GetString(bytes));
}
catch
{
Console.WriteLine("Failed to encode to binary.");
}

try
{
requestStream = HttpWReq.GetRequestStream();
}
catch
{
Console.WriteLine("Error creating request stream.");
}

try
{
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}
catch
{
Console.WriteLine("Error writing or closing stream.");
}

//get the response
HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();


if (HttpWRes == null)
{
success = false;
}

//Close the streams
try
{
HttpWRes.Close();
Console.WriteLine("Closed webresponse.");
}
catch
{
Console.WriteLine("Failed to close webresponse.");
}
//requestStream.Close();
}
catch (System.Exception)
{
success = false;
}

Console.WriteLine(success);
Console.ReadLine();
return success;

 

 

The message looks like this when sent to the server, I checked using Fiddler:

 

--asdfasdfasdfasdf
Content-Type: application/xml
<?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="BB10Testid1"> <address address-value="XXXXXXXX"/><quality-of-service delivery-method="unconfirmed"/></push-message></pap>
--asdfasdfasdfasdf
Content-Encoding:binary
Content-Type:text/plain
X-Wap-Application-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

TESTING

--asdfasdfasdfasdf--

 

Any help would be appreciated. Thanks!

Retired
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: BES10 Push Question

A couple of things that I noticed from your PAP push request:

1. Your DTD is the public/BIS one, not the one for enterprise.  The one you want is this:

<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN" "http://www.wapforum.org/DTD/pap_2.0.dtd" [<?wap-pap-ver supported-versions="2.0"?>]>

2. Also, I would recommend putting a deliver before timestamp (the date you wish the push to be delivered before) as well.  It would look something like this:

<push-message push-id='some_push_id' deliver-before-timestamp='2013-03-13T10:19:55Z'>

The "Z" at the end means the time should be treated as GMT.

3. Are you sure you're sending your post to the right URL?  For enterprise, the URL for pushes ends in /pap.

 

I'm not sure if you're restricted to using C#, but we do have a Push Service SDK that you could use to send pushes but it's only available in Java presently.

 

Thanks,

 

Matt

Contributor
Posts: 18
Registered: ‎04-05-2013
My Device: Z10

Re: BES10 Push Question

Ok, thanks for the tips. For the Enterprise URL, I know the server URL registers a push when I send a push using the old BB5+ way(non-pap). So do i simply add /pap to the end of the URL to make it work for BB10? 

Retired
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: BES10 Push Question

What does your current server URL look like exactly?  (Hiding your exact server / IP address, etc.)

Contributor
Posts: 18
Registered: ‎04-05-2013
My Device: Z10

Re: BES10 Push Question

http://servername:4 digit port number

 

so e.g. http://abcdefg:1234/

Retired
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: BES10 Push Question

Yep, adding /pap to the end of that URL should work.

Contributor
Posts: 18
Registered: ‎04-05-2013
My Device: Z10

Re: BES10 Push Question

Thanks. I got it working up to a certain degree. What I'm encountering now is a problem with the boundary. When i have the header :

HttpWReq.ContentType = "multipart/related; type=\"application/xml\"; boundary=" + boundary;

The server returns a HTTP 500 error saying that the stream ended unexpetedly. 

If I dont include the boundary part of the header, I get the following error:

<badmessage-response bad-message-fragment="--asdfasdfasdfasdf Content-Type: application/xml; charset=UTF-8
&lt;?xml version=&quot;1.0&quot;?&gt;&lt;!DOCTYPE pap P" code="2000"/>

.

 

This is my pap message:

var data = "";

data = "--" + boundary+"\n";
data += "Content-Type: application/xml; charset=UTF-8\n\n";
data += "<?xml version=\"1.0\"?>";
data += "<!DOCTYPE pap PUBLIC \" -//WAPFORUM//DTD PAP 2.0//EN\" \"http://www.wapforum.org/DTD/pap_2.0.dtd\" [<?wap-pap-ver supported-versions=\"2.0\"?>]>";
data += "<pap><push-message push-id=\"" + pushid + "\" deliver-before-timestamp=\"" + timestamp + "\">";
data += "<address address-value=\"" + devicepin + "\"/>";
data += "<quality-of-service delivery-method=\"" + dmethod + "\"/></push-message></pap>";
data += "\n--" + boundary;
data += "\nContent-Encoding:binary";
data += "\nContent-Type:text/plain\n\n";
//data += "X-Wap-Application-Id: " + appid + "\n\n";
data += message;
data += "\n--" + boundary + "--"; 

 

These are the two headers I have :

HttpWReq.ContentType = "multipart/related; type=\"application/xml\"; boundary=" + boundary;
HttpWReq.Headers.Add("X-Wap-Application-Id",appid);

 

The built message looks like:

 

--asdfasdfasdfasdf
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0"?><!DOCTYPE pap PUBLIC " -//WAPFORUM//DTD PAP 2.0//EN" "http://www.wapforum.org/DTD/pap_2.0.dtd" [<?wap-pap-ver supported-versions="2.1"?>]><pap><push-message push-id="BB10Testid1" deliver-before-timestamp="2013-04-15T10:19:55Z"><address address-value="XXXXXXXX"/><quality-of-service delivery-method="unconfirmed"/></push-message></pap>
--asdfasdfasdfasdf
Content-Encoding:binary
Content-Type:text/plain

 

TESTING
--asdfasdfasdfasdf--