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
Developer
Posts: 226
Registered: ‎10-01-2011
My Device: Passport

Re: Push SDK using low level APIs

Your target URL is not correct, it should be:

 

https://pushapi.eval.blackberry.com/mss/PD_pushRequest

 

Refer to your account notification from RIM.

 

Chris

 

New Contributor
Posts: 9
Registered: ‎06-12-2012
My Device: 8900
My Carrier: azercell

Re: Push SDK using low level APIs

Hi

I'm executing the code you provided to and I'm getting

 

        java.lang.NullPointerException
        at net.rim.pushsdk.commons.http.HttpClientImpl.readIncomingMessage(HttpClientImpl.java:291)
        at net.rim.pushsdk.commons.http.HttpClientImpl.transmitPOST(HttpClientImpl.java:94)
        at net.rim.pushsdk.pap.PapServiceImpl.sendToPpg(PapServiceImpl.java:407)
        at net.rim.pushsdk.pap.PapServiceImpl.pushToPpg(PapServiceImpl.java:387)
        at net.rim.pushsdk.pap.PapServiceImpl.push(PapServiceImpl.java:152)
Developer
Posts: 226
Registered: ‎10-01-2011
My Device: Passport

Re: Push SDK using low level APIs

Catch the exception and print the error. Looks like an issue with the return message.
New Contributor
Posts: 9
Registered: ‎06-12-2012
My Device: 8900
My Carrier: azercell

Re: Push SDK using low level APIs

I already catch this exception in this line:

 

PushResponse response = papService.push(appId, password, appId, pushMessageControl, content);
Developer
Posts: 226
Registered: ‎10-01-2011
My Device: Passport

Re: Push SDK using low level APIs

I tested the code changes you showed and it works fine except ur url was wrong. What else have u chaned?
New Contributor
Posts: 9
Registered: ‎06-12-2012
My Device: 8900
My Carrier: azercell

Re: Push SDK using low level APIs

Here is my code:

 

try{

            List pins = new ArrayList();
            pins.add("555341979");

            IdGenerator idGenerator = new IdGeneratorImpl();
            PushMessageControl pushMessageControl = new PushMessageControl(true, idGenerator, appId);
            pushMessageControl.setAddressList(pins);
            //pushMessageControl.setUsingPublicPush(true);
            Content content = new TextContent("push text");

            PapService papService = new PapServiceImpl();
            PushSDKProperties properties = getBBProperties();

            HttpClientImpl client = new HttpClientImpl();
            client.setPushSDKProperties(properties);
            papService.setHttpClient(client);
            papService.setPushSDKProperties(properties);

            try{

                PushResponse response = papService.push(appId, password, appId, pushMessageControl, content);
                System.out.println("response : "+response.getDescription());

            }catch(NullPointerException ex){
                ex.printStackTrace();
            }


        } catch (Exception e) {
           e.printStackTrace();
        }
    }

    private static PushSDKProperties getBBProperties() {
        PushSDKProperties p = new PushSDKPropertiesImpl();

        p.setPublicPpgAddress("https://pushapi.eval.blackberry.com");
        p.setHttpIsPersistent(false);
        p.setHttpConnectionTimeout(60000);
        p.setHttpReadTimeout(120000);
        return p;
    }
Developer
Posts: 226
Registered: ‎10-01-2011
My Device: Passport

Re: Push SDK using low level APIs

You're still pushing to the pgp base URL not the push URL. This is your code corrected and it pushes perfectly (JSE 1.6) .  Substitute your App ID and password.  

 

 

package com.trm.bb;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

import net.rim.pushsdk.commons.*;
import net.rim.pushsdk.commons.content.Content;
import net.rim.pushsdk.commons.content.TextContent;
import net.rim.pushsdk.commons.http.HttpClientImpl;
import net.rim.pushsdk.pap.MessageState;
import net.rim.pushsdk.pap.PapService;
import net.rim.pushsdk.pap.control.PushMessageControl;
import net.rim.pushsdk.pap.unmarshal.BadMessageException;
import net.rim.pushsdk.pap.unmarshal.PushResponse;

 

public class Test2 {

private static String password = "xxxxxx";
private static String targetURL = "https://pushapi.eval.blackberry.com/mss/PD_pushRequest";
private static final String APP_ID = "xxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";



public static void main(String[] args) throws PushSDKException, BadMessageException, UnauthorizedException {

try{
List<String> pins = new ArrayList<String>();
pins.add("555341979");
IdGenerator idGenerator = new IdGeneratorImpl();
PushMessageControl pushMessageControl = new PushMessageControl(idGenerator, APP_ID, pins);
Content content = new TextContent("push text");
PapService papService = new net.rim.pushsdk.pap.PapServiceImpl();
PushSDKProperties properties = getProperties();
HttpClientImpl client = new HttpClientImpl();
client.setPushSDKProperties(properties);
papService.setHttpClient(client);
papService.setPushSDKProperties(properties);

try{

PushResponse response = papService.push(APP_ID, password, APP_ID, pushMessageControl, content);
System.out.println("response : "+response.getDescription());

}catch(NullPointerException ex){
ex.printStackTrace();
}


} catch (Exception e) {
e.printStackTrace();
}
}

private static PushSDKProperties getProperties() {
PushSDKProperties p = new PushSDKPropertiesImpl();
p.setPpgAddress(targetURL);
p.setUsingPublicPush(true);
p.setHttpIsPersistent(false);
p.setHttpConnectionTimeout(60000);
p.setHttpReadTimeout(120000);
p.setUsingXmlParserDtdValidation(false);
return p;
}

}

 

 

New Contributor
Posts: 9
Registered: ‎06-12-2012
My Device: 8900
My Carrier: azercell

Re: Push SDK using low level APIs

if i write this code, i'm getting:

 

BadMessageException ( net.rim.pushsdk.pap.unmarshal.BadMessageException: 
    badMessageResponse = BadMessageResponse ( PapMessage ( net.rim.pushsdk.pap.unmarshal.BadMessageResponse@3781efb9    pushId = null     )    code = 2000    description = Invalid or missing attribute address-value    badMessageFragment = Invalid or missing attribute address-value     )     )
        at net.rim.pushsdk.pap.unmarshal.PapMessageUnmarshaller.parseBadMessageResponse(PapMessageUnmarshaller.java:242)
        at net.rim.pushsdk.pap.unmarshal.PapMessageUnmarshaller.unmarshal(PapMessageUnmarshaller.java:187)
        at net.rim.pushsdk.pap.PapServiceImpl.push(PapServiceImpl.java:156)
Developer
Posts: 226
Registered: ‎10-01-2011
My Device: Passport

Re: Push SDK using low level APIs

What jre are you using?
New Contributor
Posts: 9
Registered: ‎06-12-2012
My Device: 8900
My Carrier: azercell

Re: Push SDK using low level APIs

1.6