Forum OpenACS Development: Re: Tcl Web Services Toolkit: TWiST

Collapse
Posted by Claudio Pasolini on
Hi Tom,

I installed and tried the the sample 'mywebservice' script and it works as expected, even if during aolserver startup the log file reports this error:

[17/Feb/2007:11:18:41][4470.3083290288][-main-] Notice: TWS:---->[ns_info config] = '/usr/local/aolserver_45_r0/base.tcl'
[17/Feb/2007:11:18:41][4470.3083290288][-main-] Error: TWS:no such set:
    while executing
"ns_set size $modules"
    (in namespace eval "::wsdl::server" script line 14)
    invoked from within
"namespace eval ::wsdl::server {
    variable hostHeaderNames
    foreach option {address hostname name server servers config} {
	log Notice "---->\[ns..."
    (file "/usr/local/aolserver_45_r0/servers/server1/modules/tcl/twsdl/packages/wsdl/tcl/wsdl-server-init.tcl" line 7)
    invoked from within
"::source /usr/local/aolserver_45_r0/servers/server1/modules/tcl/twsdl/packages/wsdl/tcl/wsdl-server-init.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel ::source "$file""
    (procedure "::tws::sourceFile" line 4)
    invoked from within
"::tws::sourceFile [file normalize [file join [file dirname [info script]] "wsdl-server-init.tcl"]]"
    (file "/usr/local/aolserver_45_r0/servers/server1/modules/tcl/twsdl/packages/wsdl/tcl/wsdl-init.tcl" line 11)
    invoked from within
"::source /usr/local/aolserver_45_r0/servers/server1/modules/tcl/twsdl/packages/wsdl/tcl/wsdl-init.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel ::source "$file""
    (procedure "::tws::sourceFile" line 4)
    invoked from within
"::tws::sourceFile [::tws::util::package::directory [file join $packageName tcl ${packageName}-init.tcl]]"
    (procedure "init" line 4)
    invoked from within
"init $package" PACKAGE wsdl
[17/Feb/2007:11:18:41][4470.3083290288][-main-] Notice: TWS:Package xml: Initializing...

I followed your instructions regarding a pure aolserver configuration and now I wish to configure OpenACS: is it enough to symlink the twsdl packages under the www directory of the OpenACS service?

TIA,
Claudio

Collapse
Posted by Tom Jackson on
Claudio,

Yes, it works as expected even with that error on startup. I developed this on 4.5, but when I tested it on an older AOLserver, I got the same problem. (but it looks like yours is also 4.5?) This will affect the startup of tWSDL services (since no calls to ns_register_proc), so I'll need to address it at some point to figure out why the error shows up.

TWiST works because it uses the default process to return a page in pageroot.

tWSDL has a series of packages in a structure similar to but independent from OpenACS. Installation into OpenACS should be exactly the same as regular AOLserver. Some packages have a www directory, and to use the files, just symlink them where you want (from parent directory):

ln -s /path/to/and/including/package/www mydir

But note that only the www files go under pageroot, all the others are library files.

One thing I haven't discussed is ideas on where to put the TWiST configuration files, but short and simple, you can keep them with the API that you are exposing in a separate file, using whatever name you thing is best, but making sure that it doesn't get sourced at startup. Then create a directory structure under pageroot to reflect the overall hierarchy of your web services. Each directory then gets a symlink from the TWiST config file to an index.tcl file in that directory. That way, you get everything in one place. If you have directory browsing setup, then it will work like

http://junom.com/ws/

Subdirectories will have separate services and no annoying tcl file in the service URL.

Also, for those interested, the same TWiST script will probably work inside an adp file.

Collapse
Posted by Tom Jackson on
On second thought, the startup error might be due to the (I'm totally guessing) fact that you are not using virtual servers? My config might assume that you are, and since I always use them, I never saw the error...until I tried it on an AOLserver installed without virtual servers...I'll have to check on that, but it might explain the problem.

Another note for older AOLservers: tDOM is loaded using ns_ictl in tWSDL. This will need to be changed to the method recommended by tDOM. Also, you might already have tDOM loaded for AOLserver. In that case you should not load the tWSDL tdom package. You can do this by editing the config file:

twsdl/packages/tws/tcl/tws-local-conf.tcl

Remove 'tdom' from the ::tws::packages list.

Another hint: the procedures and data structures for tWSDL and TWiST are generated on startup or after visiting a service page. To inspect the code, you should use the inspect package. Link in the www directory so you can browse the exact procs and vars, but also note that this is per thread configuration. For TWiST, visit the service then immediately visit the inspect browser. Otherwise AOLserver will eventually exit the thread and the data will not there (for TWiST).

BTW, most of the tWSDL and TWiST API works in a command line mode using nstclsh (even tclsh!) and sourcing the twsdl/init.tcl file. If you then run the <ws>* api, you will see what variables are not set due to not being in a conn. You can set these one by one and re-run the failed API (usually <ws>namespace) and eventually get the service configured. This highlights the fact that AOLserver is a thin, but important, layer over tWSDL and TWiST. If you replace this thin layer, you can run either of these inside any other server.

One idea I am considering is to do something like this:

proc ws { args } { return "<ws>"}

[ws]namespace ...

[ws]proc ...

[ws]return ...

Then the developer can replace the ws proc above to return different things, such as ::myCustomMods::ws_, or whatever text you want. The above code runs the standard API.

The above decoration is somewhat like what is used for C#, and with args it might offer some additional setup. For instance, the namespace of the commands might hold additional hints as to what defaults to apply to the service (like the targetNamespace, etc.)

This is also an interesting way to do a 'soft import' of a command, since in Tcl command import is almost useless except as a convenience to specify a command name (variable remain in the original namespace).

Collapse
Posted by Claudio Pasolini on
I'm using AOLserver 4.5 with the stock OpenACS config.file and so tDOM is already loaded. I didn't notice negative side effects, but anyway I'll remove if from tws-local-conf.tcl.

Thank you very much for the other tips!

Creating a Web Service has never been so easy: this is really SOAP for the masses!