This discussion is archived
5 Replies Latest reply: Feb 27, 2013 5:15 AM by 910960 RSS

Check current session validity on on-demand process

910960 Newbie
Currently Being Moderated
Hi,
I'm experiencing a problem. My application has got a main page and a pop-up window.

What I would like is to check on the pop-up window that the session is still valid. I'm using an on-demand process for that as follows:
DECLARE
v_val BOOLEAN;
v_return VARCHAR2(1) := 'N';
v_session NUMBER;
BEGIN
v_val := apex_custom_auth.is_session_valid;

IF v_val THEN
v_return := 'Y';
ELSE
v_return := 'N';
END IF;

apex_util.set_session_state('P100_SESSION_VALID', v_session);
apex_util.json_from_items('P100_SESSION_VALID');
END;

I've got a timer on the pop-up window that checks every 30 seconds and runs this on-demand process. It works fine most of the times but every now and then it returns undefined.

<script>
function timeout_trigger() {
var get = new htmldb_Get(null, $v('pFlowId'), 'APPLICATION_PROCESS=IsSessionValid', $v('pFlowStepId'));
gReturn = get.get();

if (gReturn)
get = null;
else{
//
window.close();
}

// evaluate every 30 secons
setInterval('timeout_trigger()', 30000);
</script>

The problem is that gReturn is undefined every now and then and the window closes while the session is still active.

I would appreciate any comments or suggestions.

Many thanks
  • 1. Re: Check current session validity on on-demand process
    jariola Guru
    Currently Being Moderated
    Hi,

    What is your APEX version?
    Can you reproduce this issue on apex.oracle.com?


    I do not quite understand your on demand process. You set item value
    apex_util.set_session_state('P100_SESSION_VALID', v_session); 
    If I check correctly your on demand process code, variable v_session is always NULL.
    If there is point set null value for item, you could just simply do
    apex_util.set_session_state('P100_SESSION_VALID');
    Why you return JSON from item P100_SESSION_VALID using apex_util.json_from_items, if you set this item value always NULL?
    If I did again check correctly, you are not actually use JSON object what on demand process returns.
    You could just use below code for on demand process
    BEGIN
      apex_util.set_session_state('P100_SESSION_VALID');
      IF apex_custom_auth.is_session_valid THEN
        htp.p('YES');
      END IF;
    END;
    Regards,
    Jari
    -----
    My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
    Twitter: http://www.twitter.com/jariolai
  • 2. Re: Check current session validity on on-demand process
    910960 Newbie
    Currently Being Moderated
    Hi Jari,
    Many thanks for your quick response.

    My Apex version is 3.2.

    You are absolutely right about the v_session. Apologies, I've been doing so many tests that I copied some wrong code.

    I'm not particularly interested in the session id value all I just want to now is if it is valid or now. It it isn't I want to close the pop-up window. So you're right, I could forget about the JSON.

    I've tried for a while your suggestion:
    BEGIN
    IF NOT apex_custom_auth.is_session_valid THEN
    htp.p('NO');
    ELSE
    htp.p('yes');
    END IF;
    END;

    And this is an extract of what I get from the browser:
    -------------------------------------------------------
         
    200 OK
              62ms     
    HeadersPost

    POST http:///wwv_flow.show
         
    200 OK
              39ms     
    HeadersPost

    POST http://xxxxxx/wwv_flow.show
         
    200 OK
              41ms     
    HeadersPost

    POST http://xxxxxx/wwv_flow.show
         
    200 OK
              46ms     
    HeadersPostResponseHTML

    yes
    ------------------------------------------------------

    For unknown reasons when apex_custom_auth.is_session_valid is FALSE, no value is printed. Then the value printed is YES.

    Any ideas why this could happen? Many thanks again.

    Many thanks

    Edited by: user1303238 on 25-Feb-2013 08:12
  • 3. Re: Check current session validity on on-demand process
    VC Guru
    Currently Being Moderated
    Add an exception block and print the error to see if there is any error, and also better to use htp.prn because htp.p adds a new line character at the end
     BEGIN
       IF NOT apex_custom_auth.is_session_valid THEN
           htp.prn('NO');
       ELSE
           htp.prn('yes');
       END IF;
     EXCEPTION WHEN OTHERS THEN
      htp.prn(SQLERRM);
     END;
  • 4. Re: Check current session validity on on-demand process
    910960 Newbie
    Currently Being Moderated
    Hello,

    Could this odd behaviour be a browser or even a network issue? We are still on IE7.

    I'm saying this because I've been running it all morning in Firefox and it does seem to handle it well.
    I've come back to the json so I can display the item value on the page and see its changes. My code is as follows:

    ---------------------------------------------------------------------------------
    BEGIN
    IF NOT apex_custom_auth.is_session_valid THEN
    apex_util.set_session_state('P100_SESSION_VALID', 'NO');
    apex_util.json_from_items('P100_SESSION_VALID');
    htp.prn('NO');
    ELSE
    apex_util.set_session_state('P100_SESSION_VALID', 'YES');
    apex_util.json_from_items('P100_SESSION_VALID');
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    apex_util.set_session_state('P100_SESSION_VALID', SQLERRM);
    apex_util.json_from_items('P100_SESSION_VALID');
    END;

    ---------------------------------------------------------------------------------
    <script>
    function timeout_trigger() {
    try{
    var get = new htmldb_Get(null, $v('pFlowId'), 'APPLICATION_PROCESS=IsSessionValid', $v('pFlowStepId'));
    gReturn = get.get();
    if (gReturn) {
    var myObject = $u_eval('(' + gReturn + ')');
    json_SetItems(gReturn);
    }
    else
    alert('somethings wrong');
    get = null;
    }
    catch(e){
    alert(e);
    }
    } // end of timeout_trigger

    ---------------------------------------------------------------------------------

    The thing is that firefox seems only displays the alert "Something is wrong" if I log out from the main window. I have left it running for a few hours now.

    With IE7 every 5 or 10 mins, randomly, I get the alert, which means that gReturn is undefined. Also the displayed item P100_SESSION_VALID does not change its valule from YES to anything else.
    Also when running the app with the developer's toolbar and click on "Session" I would expect to be directed to the log in page but I am not which seems to indicate that the session is still valid.
    PL/SQL and javascript exceptions are handled but not thrown as far as I can see. What could it be preventing/stopping the process from doing what is supposed to do?

    Am I doing anything wrong? All I want to do is identify if the main session is still valid so I can close the pop-up window.

    Many thanks for your help. Your suggestions are welcome.

    Regards

    Edited by: user1303238 on 26-Feb-2013 05:45
  • 5. Re: Check current session validity on on-demand process
    910960 Newbie
    Currently Being Moderated
    Hello,
    Any comments or suggestions are most welcome.

    Many thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points