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 Developer
pramilathakur
Posts: 34
Registered: ‎05-17-2010
My Device: 9700 bold

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.

 

thanks,

--Pramila

 

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

Contributor
makeurownrules
Posts: 21
Registered: ‎04-29-2010
My Device: Bold

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.

 

Cheers,

Kapil

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

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 ?

 

Thanks,

 

 

Developer
Febiyan
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. :smileyhappy:

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

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
iamrichy
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";:mansad:
        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("");
        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\">");
        dataToSend.append("<pap>");
        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("</push-message>");
        dataToSend.append("</pap>");
        dataToSend.append("--" + BOUNDARY);
        dataToSend.append("Content-Type: text/plain");
        dataToSend.append("Push-Message-ID: " + myPushId);
        dataToSend.append("\r\n");
        dataToSend.append(msg);
        dataToSend.append("--" + BOUNDARY + "--");
        dataToSend.append("");
        printer(dataToSend.toString());
        printer("-------------------------------------------------------------------");
        String authInfo = userName + ":" + userPW;
        authInfo = Base64.encode(authInfo.getBytes());
        authInfo = "Basic "+authInfo;
        printer(authInfo);
        URL url;
        HttpURLConnection connection = null;
        try {
          //Create connection
          url = new URL(targetURL);
          connection = (HttpURLConnection)url.openConnection();
          connection.setRequestMethod("POST");
          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());
          connection.setDoInput(true);
          connection.setDoOutput(true);
          
          //Send request
          DataOutputStream wr = new DataOutputStream (
                      connection.getOutputStream ());
          wr.writeBytes (dataToSend.toString());
          wr.flush ();
          wr.close ();

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

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

New Contributor
iamrichy
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 :smileyhappy: now i can use my j2se server for push....

Developer
Febiyan
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? :smileyhappy:

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

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
JGao12345678
Posts: 46
Registered: ‎07-05-2010
My Device: 9630

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("");
            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\">");
            dataToSend.AppendLine("<pap>");
            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("</push-message>");
            dataToSend.AppendLine("</pap>");
            dataToSend.AppendLine("--" + BOUNDARY);
            dataToSend.AppendLine("Content-Type: text/plain");
            dataToSend.AppendLine("Push-Message-ID: " + myPushId);
            dataToSend.AppendLine("");
            dataToSend.AppendLine(msg);
            dataToSend.AppendLine("--" + BOUNDARY + "--");
            dataToSend.AppendLine("");
            string strSendData = dataToSend.ToString();
            Stream requestStream = null;
            string pushResult = "";
            try
            {    
                requestStream = HttpWReq.GetRequestStream();
            }
            catch (Exception ex)
            {    
                pushResult = "Push failed! " + ex.ToString();
            }
            byte[] outStr = new ASCIIEncoding().GetBytes(dataToSend.ToString());
            requestStream.Write(outStr, 0, outStr.Length);
            requestStream.Close();
            try
            {    
                HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();
            }
            catch (Exception ex)
            {    
                //push failed
            }
            if (HttpWRes != null)
            {    
                HttpWRes.Close();
            }        

 

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?