0

I want to know if a connection is valid, this is an example of what I'm trying to do:

    EnterpriseConnection connection = new MyEnterpriseConnection();
    System.out.println("first " + connection.getUserInfo());
    connection.logout();
    if(connection == null){
    connection = new MyEnterpriseConnection();
    }
    System.out.println("second"  + connection.getUserInfo());

The first System.out is printed but the second is not because is not getting in the if condition, my question is: what is the condition i should use to validate if a connection is logged out to create a new one. I was looking for a method like isValid() or something like that in the EnterpriseConnection class but it isn't

4
  • Is it correct that you are trying to check if the credentials you have are correct as constructing an EnterpriseConnection does a login rather than trying to check if an already created connection is still alive? If it is the former, surrounding just new EnterpriseConnection().getUserInfo() in a try/catch should do that. If it is the latter you need to keep a reference to that connection and use that connection.getUserInfo() in a try/catch.
    – Keith C
    Commented Sep 12, 2014 at 8:18
  • Ok this will work, but surrounding this in a try/catch statement it will use an API call, I want to save API calls as possible. That's why I'm trying to do this with a conditional if validating if connection is alive comparing with null but is not working. Any other suggest? Commented Sep 12, 2014 at 16:50
  • OK; you should add that constraint to your question. But I think the session timeout logic is all server-side and there is no notification back to the client (AFAIK) when the session has expired.
    – Keith C
    Commented Sep 12, 2014 at 17:19
  • thank you, I think you're right, i'll use your suggest about de getUserInfo() in a try/catch Commented Sep 12, 2014 at 22:13

0

You must log in to answer this question.

Browse other questions tagged .