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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Developer
Posts: 34
Registered: ‎05-17-2010
My Device: 9700 bold
My Carrier: Rogers

Re: Push API sample code needed

Hi Everyone,


I am having problems with server side application. Just getting the sample app to run

On tomcat 6.0 when I start the server I get error such as this.


I want to use my own Enterprise server. so app id I just made up.

the error is shown in red.


Can someone help me out please or send me the configuration file.

I am following the instruction on getting started guide.





May 19, 2010 3:44:40 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'registerListeners' defined in class path resource [sample-app-context.xml]: Could not resolve placeholder 'sampleapp.appid'
 at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:268)
 at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
 at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:553)
 at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:527)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:362)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
 at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:830)
 at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:719)
 at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
 at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
 at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
 at org.apache.catalina.core.StandardService.start(StandardService.java:516)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
May 19, 2010 3:44:40 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
May 19, 2010 3:44:40 PM org.apache.catalina.core.ApplicationContext log
INFO: Shutting down log4j

Posts: 21
Registered: ‎04-29-2010
My Device: Bold
My Carrier: 3

Re: Push API sample code needed

Hi Pramila,


You need to regsiter for blackberry push and they shall provide you crendetials for the app. You need to replace sample.appid with the application id provided by BB.


Please follow the documentation for blackberry push if there is any doubt.




New Developer
Posts: 34
Registered: ‎05-17-2010
My Device: 9700 bold
My Carrier: Rogers

Re: Push API sample code needed

Thanks for the reply.


but my problem is my network cannot be accessed from outside.

And here we have an blackberry Enterprise server.

the documentation says that I can either register with BB or use y own enterprise server.

So I am just creating an ID myself and I want to test it .


But when I start the tomcat I get the ERROR message.


Has any one used Enterprise server before ?





Posts: 47
Registered: ‎11-11-2009
My Device: Not Specified

Re: Push API sample code needed

Hi Bullety,


Have you figured out how to do the subscription? I'm doing it at c# too. Smiley Happy

Regular Contributor
Posts: 78
Registered: ‎04-28-2010
My Device: BlackBerry 10 Dev Alpha
My Carrier: Rogers

Re: Push API sample code needed

pramilathakur, if I understand what you are trying to do is using BES to push and you are making up your own application id, correct? Since you are deploying to your own application server make sure you edit the webapps/sample-app/WEB-INF/classes/sample-app-context.xml. Repalce the token 'sampleapp.appid' with the application id you made up as well as replace the application.id token/properties in the sample-app.properties.



New Contributor
Posts: 4
Registered: ‎04-22-2010
My Device: 8900

Re: Push API sample code needed

Hi all,


i try to create push using j2se based on Idonen n Bullety posting. but always get error 400, anybody can help me please..


here is my code:

        String pin = "xxxxxxx"; // or actual pin of device
        String applicationID = "xxx-xxxxxxxxxxxxxxx";Man Sad
        String BOUNDARY = "mPsbVQo0a68eIL3OAxnm";
        String msg = "test push from j2se"; // the message to send
        String userName = "xxx-xxxxxxxxxxxxxxx";
        String userPW = "xxxxxxxxxx";
        String targetURL = "https://pushapi.eval.blackberry.com/mss/PD_pushRequest";
        StringBuffer dataToSend = new StringBuffer();
        dataToSend.append("--" + BOUNDARY);
        dataToSend.append("Content-Type: application/xml; charset=UTF-8");
        dataToSend.append("<?xml version=\"1.0\"?>");
        dataToSend.append("<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\">");
        String myPushId = Main.getRandomPushID();
        dataToSend.append("<push-message push-id=\"" + myPushId + "\" source-reference=\"" + applicationID + "\">");
        dataToSend.append("<address address-value=\"" + pin + "\"/>");
        dataToSend.append("<quality-of-service delivery-method=\"unconfirmed\"/>");
        dataToSend.append("--" + BOUNDARY);
        dataToSend.append("Content-Type: text/plain");
        dataToSend.append("Push-Message-ID: " + myPushId);
        dataToSend.append("--" + BOUNDARY + "--");
        String authInfo = userName + ":" + userPW;
        authInfo = Base64.encode(authInfo.getBytes());
        authInfo = "Basic "+authInfo;
        URL url;
        HttpURLConnection connection = null;
        try {
          //Create connection
          url = new URL(targetURL);
          connection = (HttpURLConnection)url.openConnection();
          connection.setRequestProperty("Content-Type", "multipart/related; boundary="+BOUNDARY+"; type=application/xml");
          connection.setRequestProperty("User-Agent", "BlackBerry Push Service SDK/1.0");
          connection.setRequestProperty("Authorization", authInfo);
          connection.setRequestProperty("Host", targetURL);
          connection.setRequestProperty("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2");
          connection.setRequestProperty("Connection", "keep-alive");
          connection.setRequestProperty("Content-Length", ""+dataToSend.length());
          //Send request
          DataOutputStream wr = new DataOutputStream (
                      connection.getOutputStream ());
          wr.writeBytes (dataToSend.toString());
          wr.flush ();
          wr.close ();

          String response = connection.getResponseMessage();
          return response;

        } catch (Exception e) {
          return null;
        } finally {
          if(connection != null) {

New Contributor
Posts: 4
Registered: ‎04-22-2010
My Device: 8900

Re: Push API sample code needed

i already solve my problem using another approach than this code Smiley Happy now i can use my j2se server for push....

Posts: 47
Registered: ‎11-11-2009
My Device: Not Specified

Re: Push API sample code needed

can you help others by putting your code here? Smiley Happy

New Developer
Posts: 46
Registered: ‎07-05-2010
My Device: 9630
My Carrier: Telus

Re: Push API sample code needed

Hi idonen,


I used your code to do a test. I got an error as "The remote server returned an error: (403) Forbidden.".

Who know what reason that cause this problem?

New Developer
Posts: 46
Registered: ‎07-05-2010
My Device: 9630
My Carrier: Telus

Re: Push API sample code needed

Now, I want to develop a server side push program using C#.


Here is my code that I copy from this web site.

            HttpWebResponse HttpWRes = null;
            HttpWebRequest HttpWReq = null;
            string pin = "2100000A";    // "push_all"; // or actual pin of device
            string applicationID = "xxx-xxxxxxxxxxxxxxxx";
            string BOUNDARY="mPsbVQo0a68eIL3OAxnm";
            string msg = "testing"; // the message to send
            string userName = "xxxxx";
            string userPW = "xxxxx";
            string url = "https://pushapi.eval.blackberry.com/mss/PD_pushRequest";
            HttpWReq = (HttpWebRequest)WebRequest.Create(url);
            HttpWReq.Method = ("POST");
            HttpWReq.Accept = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
            HttpWReq.Credentials = new NetworkCredential(userName, userPW);
            HttpWReq.PreAuthenticate = true;
            HttpWReq.ContentType = "multipart/related; boundary=" + BOUNDARY + "; type=application/xml";
            StringBuilder dataToSend = new StringBuilder();
            dataToSend.AppendLine("--" + BOUNDARY);
            dataToSend.AppendLine("Content-Type: application/xml; charset=UTF-8");
            dataToSend.AppendLine("<?xml version=\"1.0\"?>");
            dataToSend.AppendLine("<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\">");
            string myPushId = DateTime.Now.ToFileTime().ToString();
            dataToSend.AppendLine("<push-message push-id=\"" + myPushId + "\" source-reference=\"" + applicationID + "\">");
            dataToSend.AppendLine("<address address-value=\"" + pin + "\"/>");
            dataToSend.AppendLine("<quality-of-service delivery-method=\"unconfirmed\"/>");
            dataToSend.AppendLine("--" + BOUNDARY);
            dataToSend.AppendLine("Content-Type: text/plain");
            dataToSend.AppendLine("Push-Message-ID: " + myPushId);
            dataToSend.AppendLine("--" + BOUNDARY + "--");
            string strSendData = dataToSend.ToString();
            Stream requestStream = null;
            string pushResult = "";
                requestStream = HttpWReq.GetRequestStream();
            catch (Exception ex)
                pushResult = "Push failed! " + ex.ToString();
            byte[] outStr = new ASCIIEncoding().GetBytes(dataToSend.ToString());
            requestStream.Write(outStr, 0, outStr.Length);
                HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();
            catch (Exception ex)
                //push failed
            if (HttpWRes != null)


I got the error message "The remote server returned an error: (403) Forbidden." when I call GetResponse(). Do you know what reason cause this problem?