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

Java Development

Reply
Highlighted
Contributor
Posts: 21
Registered: ‎03-28-2012
My Device: BlackBerry 9810
My Carrier: Airtel
Accepted Solution

BIS Push registration failing from client app

Hi All

 

 

I am trying to implement the BIS push service in client app.

 

I have got Port number, appId, BPAS URL & using that i m trying to register using the below code

 

public boolean  registerBpas() {

        Logger.info("MyScreen.registerBpas()");
        /**
         * As the connection suffix is fixed I just use a Thread to call the connection code
         *
         **/

    //    boolean isValue = false;
       
                try {
                    Logger.info("--------- step 1");
                    String conparam = getConnParam();
                    Logger.info("-------------> conparam : "+conparam);
                    final String registerUrl = formRegisterRequest(BPAS_URL, APP_ID, null) + conparam/*Conn.getConnectionParameters()*/;
                    Logger.info("\n\n\n msg registerBPAS URL is:  "+ registerUrl);
                    HttpConnection httpConnection = (HttpConnection) Connector.open(registerUrl);
                    InputStream is = httpConnection.openInputStream();
                    String response = new String(IOUtilities.streamToBytes(is));
                    Logger.info("\n\n\n\n\n\n msg RESPOSE CODE :    " + response);
                    close(httpConnection, is, null);
                    String nextUrl = formRegisterRequest(BPAS_URL, APP_ID, response) + conparam/*Conn.getConnectionParameters()*/;
                    Logger.info("\n\n\n\n\n\n msg nextUrl :    " + nextUrl);
                    HttpConnection nextHttpConnection = (HttpConnection) Connector.open(nextUrl);
                    InputStream nextInputStream = nextHttpConnection.openInputStream();
                    response = new String(IOUtilities.streamToBytes(nextInputStream));
                    Logger.info("\n\n\n\n\n\n msg RESPOSE CODE 1:    " + response);
                    close(nextHttpConnection, is, null);
                    if (REGISTER_SUCCESSFUL.equals(response) || USER_ALREADY_SUBSCRIBED.equals(response)) {
                        Logger.info("msg Registered successfully for BIS push");
                        
                        return true;
                    } else {
                        Logger.info("msg BPAS rejected registration");
                       // isValue = false;
                        return false;
                    }
                } catch (final IOException e) {

                    Logger.info("msg IOException on register() " + e + " " + e.getMessage());
                    //isValue = false;
                    return false;
                }
                
                //return isValue;
            }
       
    

    public static void close(Connection conn, InputStream is, OutputStream os) {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            }
        }
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (IOException e) {
            }
        }
    }

    public static void errorDialog(final String message)
    {
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
            public void run()
            {
                Dialog.alert(message);
            }
        });
    }

    private static String formRegisterRequest(String bpasUrl, String appId, String token) {
        StringBuffer sb = new StringBuffer(bpasUrl);
        sb.append("/mss/PD_subReg?");
        sb.append("serviceid=").append(appId);
        sb.append("&osversion=").append(DeviceInfo.getSoftwareVersion());
        sb.append("&model=").append(DeviceInfo.getDeviceName());
        if (token != null && token.length() > 0) {
            sb.append("&").append(token);
        }
        return sb.toString();
    }
    
    
    
    public static String getConnParam(){
        String connectionParameters = "";
        if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
        // Connected to a WiFi access point
        connectionParameters = ";deviceside=true;interface=wifi";
        } else {
        int coverageStatus = CoverageInfo.getCoverageStatus();
        ServiceRecord record = getWAP2ServiceRecord();
        if (record != null
        && (coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
        CoverageInfo.COVERAGE_DIRECT) {
        // Have network coverage and a WAP 2.0 service book record
        connectionParameters = ";deviceside=true;ConnectionUID="
        + record.getUid();
        } else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) ==
        CoverageInfo.COVERAGE_MDS) {
        // Have an MDS service book and network coverage
        connectionParameters = ";deviceside=false";
        } else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
        CoverageInfo.COVERAGE_DIRECT) {
        // Have network coverage but no WAP 2.0 service book record
        connectionParameters = ";deviceside=true";
        }

    }
        return connectionParameters;
    }
        private static  ServiceRecord getWAP2ServiceRecord() {
            ServiceBook sb = ServiceBook.getSB();
            ServiceRecord[] records = sb.getRecords();
            for(int i = 0; i < records.length; i++) {
            String cid = records[i].getCid().toLowerCase();
            String uid = records[i].getUid().toLowerCase();

            if (cid.indexOf("wptcp") != -1 &&
            uid.indexOf("wifi") == -1 &&
            uid.indexOf("mms") == -1) {
            return records[i];
            }
            }
            return null;
            }

 

 

 

But i m getting the below error    

 

 

Timeout occurred while processing the operation.

 

Please see the log from the device below

 

 

INFO: File Created successfully
INFO: MyScreen.registerBpas()
INFO: --------- step 1
INFO: -------------> conparam : ;deviceside=true;ConnectionUID=WAP2 trans
INFO:


 msg registerBPAS URL is:  http://pushapi.eval.blackberry.com/mss/PD_subReg?serviceid=2350-7la145e5r36mi1n42M6037M9600e95a1155&... trans
INFO:





 msg RESPOSE CODE :    

Timeout occurred while processing the operation.

        
INFO:





 msg nextUrl :    http://pushapi.eval.blackberry.com/mss/PD_subReg?serviceid=2350-7la145e5r36mi1n42M6037M9600e95a1155&...

Timeout occurred while processing the operation.

        ;deviceside=true;ConnectionUID=WAP2 trans
INFO:





 msg RESPOSE CODE 1:    

Received a malformed request.

        
INFO: msg BPAS rejected registration
INFO: ----------isSub : false


 

 

 

 

Contributor
Posts: 21
Registered: ‎03-28-2012
My Device: BlackBerry 9810
My Carrier: Airtel

Re: BIS Push registration failing from client app

Hi Simon

 

I am using the sample BIS push code provided by you, I have given the details & error that i am getting during this implementation.

 

 

Can you please help me out, as it is a very urgent requirement for my client..........

 

 

Thanks

Hidayath

Developer
Posts: 16,838
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BIS Push registration failing from client app

to register for BIS push you have to use a BIS connection, there is no use for your getConnParam method.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 21
Registered: ‎03-28-2012
My Device: BlackBerry 9810
My Carrier: Airtel

Re: BIS Push registration failing from client app

Hi Simon

 

BIS connection you mean connection suffix ?

 

private static final String CONNECTION_SUFFIX = ";deviceside=false;ConnectionType=seekrit string";

 

 

Can I able to test this on simulator ?

 

Could you please explain how can i Implement push notification End to End (from client to server) i mean procedure.

Developer
Posts: 16,838
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BIS Push registration failing from client app

yes, i mean the seekrit string.
you cannot test BIS on the simulator, only on the real device.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 21
Registered: ‎03-28-2012
My Device: BlackBerry 9810
My Carrier: Airtel

Re: BIS Push registration failing from client app

[ Edited ]

Hi Simon

 

Its working....... Register & de register is working.........

 

Thank you very much for your reply....

 

Actually in Connection Suffix I used [removed inappropriate content]

 

There must be Hyphen (-) between mds & public, its not allowing me to type that text as it is in this forum.

 

And tested in device.....

 

This connection suffix is for BIS implementation & now I am able to Register & Deregister my app for Push.

 

But still I need to test the receiving  push message part, once my server implemenation is done.

 

Once again thanks a lot.............

 

Thank You

Hidayath