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
Sunit
Posts: 7
Registered: ‎02-16-2009
My Device: Not Specified

Maintain Session/Cookie in my J2ME blackBerry App

i am developing a blackberry app in J2ME, which is pointing to web service written in dot net.

 

we have session state enabled in the webservice in dotnet.

 

i developed an application which for BB which was consuming this webservice and everything seemed to work fine ( ie even session seemed to work) while i used to run the application from the JDE device simulator.

 

but once i ported the same on the device, the BB app was not able to maintain the session from device

 

i am using ksoap to consume the web service from my BB app. cannot use jsr172 or other methods as most of the target devices are on JDE 4.2

 

can anybody plz help me on how to fix the issue.

 

i think there is issue in creation of cookies on device, but not sure. does anybody have any idea.

 

Please use plain text.
Administrator
MSohm
Posts: 14,429
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Maintain Session/Cookie in my J2ME blackBerry App

Am I correct to assume you were using the MDS Simulator with the BlackBerry Simulator?  If so, it is likely that the MDS Simulator was handling the session cookie for you.  If your application connects through a BlackBerry Enterprise Server you should see similar behaviour.  If it is not, it would be up to your application to handle the session cookie.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
Sunit
Posts: 7
Registered: ‎02-16-2009
My Device: Not Specified

Re: Maintain Session/Cookie in my J2ME blackberry App

[ Edited ]

Hi Mark,

 

Thanks for checking on this

 

The application is a J2ME one developed in JDE 4.2 and am using the JDE Simulator ( not sure if it runs on MDS in the background)

so ,
would an unsigned app developed in JDE, connecting to a dotnet webservice using kSOAP2 and having no BES in the environment need to have added coding for handling session(though the simulator does not require this to maintain session)?

 

what change is required in such an app to handle session?

 

Thanks

Sunit

Message Edited by Sunit on 02-19-2009 04:24 AM
Please use plain text.
Administrator
MSohm
Posts: 14,429
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Maintain Session/Cookie in my J2ME blackberry App

If you are not using a BlackBerry Enterprise Server it is definetly up to the application to handle the session cookies.  I don't know if this is something KSOAP2 handles automatically or if this is something you'll need to handle within your application by scanning for cookies in the HTTP headers and sending the same cookies in the response.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
Sunit
Posts: 7
Registered: ‎02-16-2009
My Device: Not Specified

Re: Maintain Session/Cookie in my J2ME blackberry App

Hi Mark

 

Sorry once again bothering you.

 

As I mentioned in my post earlier, the session is being maintained if I am running the application in Simulator, 

Session is not being maintained while the app is being run from device.

 

This is irrespective of whether I am using ksoap or custom code using HttpConnection to invoke the Webservice.

 

So I don't think there should be anything that needs to be handled in ksoap or programatically.

 

Do you think this has got something to do with the signing of an application

 

Thanks

Sunit

Please use plain text.
New Developer
virbahadur
Posts: 20
Registered: ‎09-24-2008
My Device: 9000, 8310, 8520, 9700, 9800, 9500

Re: Maintain Session/Cookie in my J2ME blackberry App

When you run the application on simulator, the MDS simulator automatically handles the cookies. So first of all you need to disable this in MDS simulator config file.  Browse to the config directory

Program Files\Research In Motion\BlackBerry Email and MDS Services Simulators #.#.#\MDS\config

 

Open rimpublic.property in  text editor.

 

Under the [HTTP HANDLER] section, change  the following:

 

application.handler.http.CookieSupport = [value]. By default it is true. Change it to false.

 

After this you need to extract the cookie from the connection

 

for (int i = 0;(key = _con.getHeaderFieldKey(i)) != null; i++)
    {
        if (key.equalsIgnoreCase("set-cookie"))
        {
            String cookie = _con.getHeaderField(key);
            // perform further cookie management

            // extract Cookie name and its value from the cookie string
        } //if
    } //for 

 

In the subsequent requests you will need to set cookie in connection

 

_con.setRequestProperty("Cookie","cookieName=value");

 

Please use plain text.
Developer
PhilipPearl
Posts: 62
Registered: ‎05-29-2009
My Device: Not Specified

Re: Maintain Session/Cookie in my J2ME blackberry App

Very interesting.  When I turned off cookie handling on the simulated MDS it also turned off automatic handling of redirects.  Does anyone know if the MDS equivalent in BIS-B also handles cookies and redirects for you?  And if so is there any way to signal to it within the HTTP request so it doesn't interfere?

 

Phil

Please use plain text.
New Developer
jacytan
Posts: 88
Registered: ‎11-04-2008
My Device: Not Specified

Re: Maintain Session/Cookie in my J2ME blackberry App

Hi,

 

I have the same problem as Sunit, but my application uses JSR 172.

Do you know how to maintain sessions using JSR 172?

 

I need help badly! :smileysad: 

Please use plain text.
New Developer
virbahadur
Posts: 20
Registered: ‎09-24-2008
My Device: 9000, 8310, 8520, 9700, 9800, 9500

Re: Maintain Session/Cookie in my J2ME blackberry App

Can you please give a brief description of your problem? If possible please paste a sample code of what you r using.
Please use plain text.
New Developer
jacytan
Posts: 88
Registered: ‎11-04-2008
My Device: Not Specified

Re: Maintain Session/Cookie in my J2ME blackberry App

My assignment is to consume a .NET web service using JSR 172. The web service has session management which the cookies are stored in a CookieContainer (don't know much about .NET). Now, when i consume the Log-in service, the server returns a SessionID with which i will have to pass to the other methods to authenticate the operations that i will use. (Note: The SessionID mentioned here is not the intrinsic SessionID of the cookies.) When i try to use the Log-out service, passing the SessionID, i get receive an error message from the webservice.

 

A developer of the web service thought that the problem could be due to the sessions in the server. That after the Log-in call, when i call Log-out service, the server doesnt recognize my client application anymore.

 

So what i did, i set the MAINTAIN_SESSION_PROPERTY of my stub to true. But still the problem persists.

 

Do you have any idea what is wrong?

Please use plain text.