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
New Developer
matw
Posts: 3
Registered: ‎09-10-2009

Custom BrowserFieldConfig for Cookies?

Hi there,

 

there is a known issue SDR336322 which describes a problem with setting cookies in a net.rim.device.api.browser.field2.BrowserField

(Details here: http://docs.blackberry.com/en/developers/deliverables/8546/Known_issues_491056_11.jsp)

 

I expierence this problem when setting two cookies on my test-site - only one cookies gets set per request, so I would have to load the page twice to have both cookies set.

The provided workaround assumes to "not use the default net.rim.device.api.browser.field2.BrowserFieldConfig"

So what should I do instead? Subclassing BrowserFieldConfig of course doesn't solve the problem.

 

Is there any clue when this will be fixed? Any (official/not official) information about when to expect the release of 5.0?

 

Thanks in advance,

Matthias

Please use plain text.
New Contributor
Nikolaos610
Posts: 9
Registered: ‎01-07-2010

Re: Custom BrowserFieldConfig for Cookies?

matw,

 

Did you managed to find any solution on that?

 

Thanks

 

Nikos

Please use plain text.
New Contributor
Nikolaos610
Posts: 9
Registered: ‎01-07-2010

Re: Custom BrowserFieldConfig for Cookies?

Hello Blackberians

 

i finally managed to find a solution by my own, those are the steps that i followed

 

(1) The cookie (http header actually) that my internal browser should set was like

SERVER RESPONSE

Set-Cookie: JSESSIONID=FA3687789B2AE5D3A0E89B1DE7EA0173; Path=/mypath; Secure; HttpOnly

BROWSER REQUEST (i should send)

Cookie: JSESSIONID=FA3687789B2AE5D3A0E89B1DE7EA0173

 

(2) i set a global var in my main class like

private String myCookie = "";

 

(3)Set Protocol Controller (there i can set cookies for the requests)

         _bf2 = new BrowserField(_bfConfig);

        _controller = new ProtocolController(_bf2) {
            public void handleNavigationRequest(final BrowserFieldRequest request) throws Exception {
                try {
                    HttpHeaders myHttpHeaders = request.getHeaders();
                    for(int mm=0; mm<myHttpHeaders.size(); ++mm){
                        String mykey   = myHttpHeaders.getPropertyKey(mm);
                        String myvalue = myHttpHeaders.getPropertyValue(mm);
                        System.out.println("------>"+mykey+"="+myvalue);
                    }
                    if(myCookie != null && !myCookie.equalsIgnoreCase("")){
                        myHttpHeaders.addProperty("Cookie",myCookie);
                        System.out.println("------>added the "+"Cookie"+"="+myCookie);
                    }
                    BrowserFieldRequest mybfr = new BrowserFieldRequest(request.getURL(), request.getPostData(), myHttpHeaders);
                    super.handleNavigationRequest(mybfr);
                } catch (Throwable e) { ; }
            }
        };
        _bfConfig.setProperty(BrowserFieldConfig.CONTROLLER, _controller);

 

(4) create a class Mybdebug that extends BrowserFieldDebugger like

    class Mybdebug extends BrowserFieldDebugger {
        public void notifyHttpTraffic(HttpConnection connection, Hashtable requestHeaders){
            try{
                for(int j=0; j<10; ++j){
                    String myHeader = connection.getHeaderFieldKey(j);
                    String myValue  = connection.getHeaderField(j);
                    System.out.println("------>bdebug "+myHeader+"="+myValue);
                    if(myHeader.equalsIgnoreCase("Set-Cookie")){
                        myCookie = myValue;
                        if(myCookie == null && !myCookie.equalsIgnoreCase("")){
                            System.out.println("------>MY COOKIE is NULL!!! myCookie="+myCookie);
                        }
                        else{
                            if(myCookie.indexOf("; Path")>0){
                                myCookie = myCookie.substring(0,myCookie.indexOf("; Path"));
                            }
                        }
                    }
                }
                System.out.println("------>myCookie="+myCookie);
            }catch(Exception e){
                System.out.println("------>bdebug(1) Exception");
            }
        }
    };

 

(5) Add the bdebug object to your  BrowserField like

        Mybdebug bdebug = new Mybdebug();
        _bf2.setDebugger(bdebug);

 

 

Hope that this helps

 

 

Thank you

 

Nikolaos

Please use plain text.
Contributor
dcdel
Posts: 13
Registered: ‎06-18-2009

Re: Custom BrowserFieldConfig for Cookies?

Hi,

 

its been seen that attaching a debugger to the production application is not a good idea as it slows down your application very much, and can even lead to hanged application.

 

I am also handling the cookies by self, by two means i.e.

 

1 by implementing the Cookie manager and setting it in to the BrowserFieldConfig object.

2 by adding those cookie back in to the connection in the above same implemented class.

3 as mentioned above in the response step (3).

4 a fourth place could be which need to be verified if the browserfield calls the cookie manager set cookie method on the cookie recieved in the HTTPS redircetion (AUTH cookie). i wasnt able to confirm that but the above steps works for me.

 

 

Please let me know if it doesnt work.

 

 

Please use plain text.