function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
American DataAmerican Data 

Checking to see if session is still available.

Can anyone recommend a way to check if a session is still available?  I know there are ways to set the expiration period, however, I'd like my program to be aware of the session state so it can request a new one if it has timed out.

Currently I've wrapped the SoapBindingStub in a Singleton.  On every call to getInstance() of my singleton, I can check the status of the session before returning the SoapBindingStub.  This way, I can request a new stub if it has expired.

I can't seem to locate a means to check for session state in the API documentation.  I know it is kind of a hack, but would checking the value of SoapBindingStub.getUserInfo() tell me anything?  i.e., if the session is expired would this return null or throw an exception I could catch and then create a new instance of the SoapBindingStub.

Any suggestions on how to do so a more appropriate way?

Thanks again in advance.

Regards,

SuperfellSuperfell
you could call getUserInfo or getServerTimestamp, however this doesn't help, as you still have a race condition, the session might expire between this check call and the subsequent real call. You could subclass the generated proxy and check for the invalid session exception after each method call and relogin, re-make the request as needed.
American DataAmerican Data

Simon,

Good point.

Fortunately the SoapBindingObject is seldomly used in this application (just used to query SF every now and then). So, when I get access to a SoapBindingObject I'll only be making one call to it.... and then getting the instance through my singleton to make a future call.  i.e., the singleton getInstance() method can do the check each time..

Of course this is a limitation if I need to execute more operations on the SoapBindingObject.  It could timeout at any time.

Thanks.

SuperfellSuperfell
but it can still timeout between your check in the singleton, and it being used.
American DataAmerican Data
True.