Jeff,
Thanks for that bit of help. As far as I can tell everything seems to
work correctly. I setup a slightly different test to demonstrate the
behavior.
Register filters in the private library:
proc ::test_adp_abort {arg why} {
switch -exact -- $arg {
file {
ns_return 200 text/plain [ns_adp_parse -file test.adp]
}
info {
ns_adp_exception adp_state
ns_return 200 text/plain "ns_adp_exception_state = $adp_state"
}
}
return filter_return
}
ns_register_filter preauth GET /adp-file ::test_adp_abort file
ns_register_filter preauth GET /adp-info ::test_adp_abort info
Place test.adp in the pageroot:
<%
ns_return 200 text/plain hi
ns_adp_abort
ns_log Notice "After abort, I shouldn't be running"
%>
Visit urls in a particular order:
1. use ns_adp_parse -file to load test.adp
http://localhost:8000/adp-file
(browser returns "hi")
Error log shows an error:
Error: Tcl exception:
while executing
"ns_adp_abort"
invoked from within
"ns_adp_parse -file test.adp"
("file" arm line 2)
invoked from within
"switch -exact -- $arg {
file {
ns_return 200 text/plain [ns_adp_parse -file test.adp]
}
info {
ns_adp_exception adp_state
ns_..."
(procedure "::test_adp_abort" line 3)
invoked from within
"::test_adp_abort file preauth"
-----------
2. Now check the adp status
http://localhost:8000/adp-info
(browser returns "ns_adp_exception_state = abort")
Nothing in the error logs
3. Revisit adp-file
http://localhost:8000/adp-file
(browser returns server error)
Error log has:
Error: Tcl exception:
while executing
"ns_adp_parse -file test.adp"
("file" arm line 2)
invoked from within
"switch -exact -- $arg {
file {
ns_return 200 text/plain [ns_adp_parse -file test.adp]
}
info {
ns_adp_exception adp_state
ns_..."
(procedure "::test_adp_abort" line 3)
invoked from within
"::test_adp_abort file preauth"
Notice that now ns_adp_parse is returning the error, not the call to
ns_adp_abort.
4. Directly access test.adp:
http://localhost:8000/test.adp
(server returns "hi")
5. Revisit adp-info
http://localhost:8000/adp-info
(server returns "ns_adp_exception_state = ok")
*** Analysis ***
Working exactly like Jeff said. One thing to notice is that direct
access of the test.adp file resets the state.
Why does this happen? Using ns_adp_abort inside a tcl context, or using
it outside of an adp context. Even ns_adp_parse is outside of the adp
context, there is no toplevel handler.
The basic problem is trying to reuse a directly accessed adp as input to
ns_adp_parse. This doesn't work in general, although you might find some
cases where it does work.
tom jackson
On Tue, 2009-07-07 at 13:08 -0700, Jeff Rogers wrote:
> Jeff Rogers wrote:
>
> > proc decode_url { why } {
> > set page [ns_adp_parse -file /www/website/template.adp]
> > ns_return 200 "text/html" "$page"
> > ns_adp_exception state
> > ns_log notice "adp exception state is $state"
> > catch {ns_adp_return}
> > return filter_return
> > }
>
> Whoops, this won't work. The ns_adp_return will let the adp interpreter
> run *after* the next eval, but the next time just exits. (an additional
> piece of debugging code was hiding this from me initially)
>
> I think a better approach (lacking "ns_adp_ctl reset") is
>
> proc decode_url { why } {
> set page [ns_adp_parse -file /www/website/template.adp]
> ns_return 200 "text/html" "$page"
> ns_adp_exception state
> ns_log notice "adp exception state is $state"
>
> # reset the adp state
> set dn [open /dev/null w]
> ns_adp_ctl chan $dn
> catch { ns_adp_ctl chan "" }
> close $dn
>
> return filter_return
> }
>
> Of course, I had to dig around in the code a bit to figure out how to
> call NsAdpReset, but on the plus side the AOLserver code is much more
> pleasant to dig around in than many other programs.
>
> -J
>
>
> --
> AOLserver - http://www.aolserver.com/
>
> To Remove yourself from this list, simply send an email to
> <[email protected]> with the
> body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject:
> field of your email blank.
>
--
AOLserver - http://www.aolserver.com/
To Remove yourself from this list, simply send an email to
<[email protected]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject:
field of your email blank.