last day (15 days later) » 

12:19 PM
2
A: Oracle Apex get cookie from an ajax request

Koen LostrieThis is what I think is happening: The cookie is sent as part of the http request header of your apex application call. The rest call is another http request, unrelated to your apex http request and I don’t believe the header of that request includes the cookie. So in the database session that is...

 
The cookie definitely gets sent with the ajax request. I've already checked the cookies on both requests (network>request>cookies) and they are identical.
 
Could you setup a sample testcase in a dedicated workspace on apex.oracle.com ?
 
I don't have an apex/oracle account
 
That is an environment where you can request a workspace to try things out at no cost - not for production. You don't need an oracle account.
 
I requested a workspace and recreated the basic structure of the system. Here is the "non-apex apex application" apex.oracle.com/pls/apex/nzapptest/r/84308/files/static/v1/…
 
12:19 PM
when I execute this it shouldn't give me a cookie value - since this is initiated from a static html file there is no apex session and no cookie. You state "from a request that was originated with ajax from an apex page" in your question. The idea of a sample testcase is that you provide credentials so I have have a look. Can you create an additional user and share the credentials ? Then describe the exact testcase (or put that as text in an app region on the test app)
 
I just created a Minimal, Reproducible Example. Since there is no authentication, the function is reading the only cookie available at the time (JSESSIONID). p.s. I think the cookie gets added on the first ajax request so you probably have to press F5 for reliable results.
 
and login credentials for the workspace ?
I'm sorry man I have no idea what you mean. When I asked for a testcase I meant for you to give me the real test case so I can investigate as a developer (with a basic app and workspace credentials so I can reproduce). Instead you just give a link to a page. I can't debug that for you I'm sorry.
 
Ok, can you give me your email so I can create an account for you? It won't let me create an user without an email.
 
just put your own email in it (it's only needed for password recovery which is not needed in this case), create a user named "guest" or so and set the password to "NOT" change on first login. Provide me user/pwd and workspace name.
 
Workspace: NZAPPTEST Username: testtest Password: testtest
 
12:19 PM
Ok I'm in. But please provide me an exact testcase. What exactly are you doing - what are you expecting - with details (as I asked in one of my previous updates)
 
The staticapp application has an index.html file which calls the rest call test test GET, which runs select test() from dual. If you run select test() from dual from SQL workshop / SQL Commands it works fine.
 
Did some tests. Only the jsession cookie is seen - check the restful service apex.oracle.com/pls/apex/nzapptest/test/k . I suggest you do some more research on owa_cookie to see if you can read more cookies. The GET handler I created should get you going.
 
Thank you, but why doesn't the function work when it get's called from the rest service? Isn't the inside of the function call a pl/sql scope just like the handler you created?
 
I'm no longer in the app now and have no time to look into it anymore today. The value of the cookie (in owa_cookie) is not a varchar, it is a record (check documentation). Look at my code to see how it should be parsed. I believe that was causing the error. What you probably could do to solve the original issue is set a cookie yourself in the apex app containing the value of the APP_USER and read that cookie in the restful service.
 
Thank you for all your help, I would like to know why the collection query doesn't work but the PL/SQL works. Is there a way to get it working a collection query and a single select statement? Regardless I will accept the answer and award the bounty right before the bounty ends.
 
12:19 PM
collection query should work just as well. It's just a lot easier when developing to start with pl/sql.
 
What is wrong with the collection query I've already written?
 
It's working fine but only if there is a cookie it'll error out if there is no cookie set since no exceptions are caught.
 
I can't get it to work, I created the function cookie_func that just returns the value of the JSESSIONID cookie, the procedure cookie_proc that does the same thing but instead uses an output parameter and the cookie_proc_func function that returns the output of the procedure. I created 2 pl/sql handlers, 1 calling the function and 1 calling the procedure and 2 collection query handlers, 1 calling the plain function and the other calling procedure wrapper function. Both pl/sql blocks work without any exception handling and both collection queries throw the same exception.
 
What can you not get to work ? What is the exception ? Just put the code I posted in my answer in a procedure without and invoke the procedure from the handler
I meant "a procedure without arguments"
 
It's still the same exception I posted in the original question
https://apex.oracle.com/pls/apex/nzapptest/test/collection-func
https://apex.oracle.com/pls/apex/nzapptest/test/collection-proc
 
12:35 PM
Give me 5 mins - then I'll have a look
Which handler fails ?
 
`block-func` and `block-proc` are working
`collection-func` and `collection-proc` throw the exception
 
1:00 PM
Can't get it to work either. Underlying error is a ORA-06502: PL/SQL: numeric or value error. I'm assuming it has to do with the function being called. My advice is to not use a select. Just generate the json in the get handler source or generate it in a procedure and invoke the procedure in the get handler. You have a solution - I'm not going to put more time in it.
I'd appreciate if you accept my answer even if bounty has already expired.
 
1:19 PM
Fair enough, I'll accept tomorrow before the bounty ends. Accepted answers are less popular.
Do you think if I create another question asking how to make it work exclusively for collection queries it will get marked as a duplicate?
 

last day (15 days later) »