Re: use tclwebtest from AOLserver?

Tilmann Singer <[email protected]> Sun, 28 Sep 2003 18:37:42 +0000
Newsgroups gmane.comp.web.tclwebtest
Message-ID <[email protected]>
* Andrew Piskorski <atp-Iii/6jn3a/[email protected]> [20030927 15:36]:
> I see some brief comments in the lastest lib/tclwebtest.tcl about
> using tclwebtest from AOLserver, so clearly people are doing it.  But
> can you give me a bit more background on how you're using it?
> 
> E.g., are you loading the procs into AOLserver or exec'ing tclsh?  Are
> you strictly using the tcllib http stuff with tclwebtest, or have you
> patched it to use AOLservers, ns_httpget, etc. - perhaps even
> nsopenssl's ns_https* commands as well?

I just wrote a small openacs package for my personal convenience that
acts as webinterface to tclwebtest, which uses a very evil hack to
make the tclwebtest procs available within aolserver: it calls
'source' fot the tclwebtest libraries every time before they are
needed. Actually it was planned to only source if necessary, saving
some time when it has been sourced for the current thread already. I
attached that proc that does that below. No idea why the on-demand
sourcing is deactivated (see the delete namespace call after TODO).

Ideally I would like to make it available via package require, but
that doesn't work with the older aolserver versions (at least not
3.3ad13). It's propably an option with aolserver 4.


hope that helps, til




ad_proc -public twt_source_tclwebtest_if_necessary {
} {
    Sources the tclwebtest library into the current thread, using 
    the namespace ::tclwebtest. This also sources the included version
    of the tcl http package, under ::tclwebtest::http
} {

    if { [namespace current] != "::" } {
        error "expected to be called in global namespace, but called
        from [namespace current] instead"
    }

    # TODO
    catch {namespace delete ::tclwebtest}

    if { [namespace children "::" "::tclwebtest"] != "::tclwebtest" }
    {

        ns_log notice "sourcing tclwebtest libraries for this thread"

        namespace eval ::tclwebtest:: {

            # Source the required http.tcl package, which is included
            # in the aolserver distribution.

            # Several things have to be "fixed" here before the
            # package can be sourced though.
            set http_package_file [open "[ns_info
            # home]/lib/tcl8.3/http2.3/http.tcl"]
            set http_package [read $http_package_file]
            close $http_package_file
            
            # the fileevents run in the global namespace, but we
            # sourced http under ::tclwebtest::http, so change the
            # callbacks accordingly.
            regsub -all -line {^(\s*fileevent.*)(http::)}
            # $http_package {\1[::tclwebtest::http_namespace]::}
            # http_package

            # fix the Host: header bug
            #TODO

            eval $http_package

        }
        
        # source the tclwebtest libraries
        source "[acs_package_root_dir tclwebtest]/tcl/tclwebtest.tcl"

    } else {
        ns_log notice "not sourcing tclwebtest because ::tclwebtest
        namespace already exists"
    }
}





-- 
http://tsinger.com


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf