Version 69 of Rivet

Updated 2012-10-10 09:37:54 by oehhar

http://tcl.apache.org/rivet/Rivetlogo_small.png

Apache Rivet is the next generation of mod_dtcl and NeoWebScript, combined: "like PHP, but with Tcl." More info appears at http://tcl.apache.org/rivet/

Was this made by the same people as NWS and mod_dtcl, or is it a separate team of developers? -FW

Current developers on Rivet are Massimo Manghi and Harald Oehlmann, Karl Lehenbauer and sometimes David Welton. Damon Courtney, Brad Morrison, Pat Thoyts and Andy Doerr have all contributed in the past.

There is a Windows binary version for Apache (not Apache2) here: http://www.apache.mirrors.versehost.com/tcl/rivet/binary/


mxmanghi - 26-Jun-2012: Rivet 2.0.5 released


Try THP as an alternative. A webserver neutral way to embed Tcl code. --CAU


Can we have some testimonials by Rivet users? (sorry, i'm new to servers in general)

  1. how do you connect to a db, tcl db extensions?
  2. is an apache instance with rivet and tomcat possible? encouraged?
  3. mod_rewrite in the midst of all this, or is that only available on top of a tomcat instance?
  4. are importing libraries like tcllib a piece of cake after rivets installed?

i want to run a dual java/tcl environment...


davidw - I think these questions are more appropriate for the newsgroup or the rivet mailing list, but I'll give it a shot:

1) You use regular Tcl database extensions. Rivet is pretty much standard Tcl, making a lot of the code you write for it reusable on or off the web.

2) I've never mixed Apache and Tomcat. I don't really care for Java for these sorts of things unless you have a *big* infrastructure, and that's not something I've dealt with a lot.

3) mod_rewrite is an Apache thing and it works just fine with Rivet. In fact, it's encouraged if you want to do things like have one rivet script respond to a whole virtual directory tree. So /foo/bar/ /foo/baz/ /foo/bee/bop and so forth are all mapped to foo.tcl?bar foo.tcl?baz foo?bee+bop and so forth.

4) tcllib and other libs are a piece of cake:-)


About Rivet's mailing list, [L1 ] says: "This list is archived here: [L2 ]". But leads to an error: "Required parameter 'listId' or 'listName' is missing or invalid".

JJR: The mailing list archives for the tcl apache projects can be found at [L3 ] .


Rivet "lets you program in not only mixed HTML/Tcl, but also pure Tcl, which is good for separating content and presentation."


RLH: Are there any Rivet tutorials mucking about?

Massimo Manghi: Rivet manuals have examples for both configuration and programming. Rivet extends Tcl with a small set of new commands dedicated to web programming and therefore having a good Tcl manual can be useful, depending on the familiarity of the developer with the language.


davidw: Not yet, but Rivet is very similar to plain old Tcl, and the differences are covered in the documentation.

As far as programming style, if you are doing something simple... just go ahead and mix your HTML and Tcl code. If it's a more complex app, separate things out into .tcl files that act as the logic and use .rvt files simply as templates.

Or write the mailing list for more specific questions...

RLH: I am looking for something similiar to HTML::Template [L4 ] from the Perl side of the house. I like the clean separation of code and HTML. : )


That perl template stuff just adds funny tags, which are not standard HTML. If you want to separate code and templates, do your processing in a .tcl file, then do "parse foo.rvt", and in the .rvt file, put statements like <? puts $foo ?> <? puts $bar?> where you need variable values. Or if you really wanted to do something fancy, you could call the parse.rvt in its own namespace/interpreter/whatever from the .tcl file, and create procs that are aliases to your variables, so all you have to do is <?foo?> <?bar?> in order to get output. I suppose a standardized way of doing this would be nice, but it is pretty easy... experiment and tell us (on the list, please) what you end up liking!

RLH: You are correct about the funny tags, I meant more of a "standard way of doing this..." as you said. I will go with your suggestions. I am far from good enough to create the "standard way" though. : )


RLH 2006-02-07: Are there any hosting companies that support Rivet?

Roy Keene 2008-10-06: Any Rivet application can be turned into an HTTP/CGI application. And with Starpacks the entire thing can be completely self-contained in one file.


APW 2007-01-20: if you have problems installing Tcl and Rivet on Windows follow the link.


Roy Keene 2008-10-05: Rivet can also be implemented transparently using CGI. This has the advantage of using "suEXEC" and working well with all versions of Apache. More information can be found on the Rivet/CGI page ([L5 ])

Roy Keene 2009-03-20: Rivet/CGI ([L6 ]) now supports converting a Rivet application into a Starkit (which can be turned into a Starpack)


PWQ 2011-09-27: See Rivet - OpenBsd 4.9 for installation notes on OpenBSD.


2012-07-07: Massimo Manghi gave a speach on EuroTCL . The slides gave a good overview of current Rivet capabilities.


  Apache start error: can not locate tcllib8.5.so (Unix)

HaO 2012-05-04: Rivet loads the tcl library using the dynamic linker.

Thus, it must be:

  • in the default location /usr/lib(64)
  • or in a folder listed in the environment variable LD_LIBRARY_PATH of apache.

I felt it easier to add a symlink to /usr/lib(64) instead setting a custom library path.Commands necessary, if tcl is installed in /usr/local/lib:

# cd /usr/lib(64)
# ln -s /usr/local/lib(64)/libtcl8.5.so

  Apache start error: undefined symbol: xxx

HaO 2012-05-04: I got the following error starting apache:

Can't locate API module structure `mod_rivet' in file /etc/httpd/modules/mod_rivet.so: /etc/httpd/modules/mod_rivet.so: undefined symbol: mod_rivet

This was due to the following line in the apache config file:

LoadModule mod_rivet /etc/httpd/modules/mod_rivet.so

The second word mod_rivet was incorrect and its value is shown in the error message. The correct value is: rivet_module

LoadModule rivet_module /etc/httpd/modules/mod_rivet.so

  error return page

George Petasis asked about the default error return page:

George Petasis asked about the default error return page:

return an error page? I have tried "headers numeric 500". Firefox sees that the server responded with an internal server error, but I see a blank page. How can I use the apache default error page?

Massimo Manghi answered:

Massimo Manghi answered:

A tcl error can be handled setting up an ErrorScript. If the error is raised by an abnormal condition you are catching somehow in your code you may call 'abort_page <abort_code>' which will trigger the code set up in AbortScript. Within this script you can check which condition brought about the error using the 'abort_code' command that is supposed to return the <abort_code> you passed when you fired the exception.

See also the 'headers' and 'no_body' commands

Surely you can design your own error page if you want. It should imply some extra work but greater flexibility

Did you check this page about error customization in Apache?

http://httpd.apache.org/docs/2.0/custom-error.html

George Petasis asked how to use the standard Apache error page

George Petasis asked how to use the standard Apache error page

Is this possible?

Massimo answered that this is propably not possible

Massimo answered that this is propably not possible

Apache will certainly return its standard error messages when an internal abnormal condition occur that cannot be handled by Rivet. More questions come up to my mind related to the error handling and Rivet interaction with other Apache components.

Harald Oehlmann wrote, why you need your own error page

Harald Oehlmann wrote, why you need your own error page

Why ? It depends on the requested format. I follow the book "RESTful Web Services Cookbook" by Subbu Allamaraju. Half the book is about "error return"...

My example:

A data base is queried and there are the following formats available:

  • web (pretty web page)
  • http table
  • xml table
  • csv table

First, I find out the required destination format:

  • A form variable
  • if not given: headers(Accept)
     -> there is a new method in 2.0.5 to easily parse this

Then I look into the data base. If the required data is not found or there is another error, I output error pages depending on the required format and the set http status. See also, that I flag "not found data" as cacheable, but server errors as not ;-)

if {[catch {
    set resultData [wwwbaseProductDataGet\
    if {[catch {
        set resultData [wwwbaseProductDataGet\
                [env REMOTE_ADDR]\
                [var get log]\
                $response(key)\
                ""\
                $response(country)\
                $response(language)\
                $response(date)\
                $response(format)]
    } Err dErr]} {
        switch -exact -- [dict get $dErr -errorcode] {
            PARAM  {
                # > Return 400 Bad request
                wwwbaseCacheSet 1
                headers numeric 400
            }
            NOT_FOUND {
                # > Return 404 Not found
                wwwbaseCacheSet 1
                headers numeric 404
            }
            default {
                # > Return 500 Internal server error
                wwwbaseCacheSet 0
                headers numeric 500
            }
            # > Return 404 Not found
        switch -exact -- $response(format) {
            csv {
                puts "Error\n$Err"
            }
            json {
                puts "\{error: \"$Err\"\}"
            }
            xml {
                puts "<error>$Err</error>"
            }
            html {
                puts "<html><head><title>\
                        [mce PageTitleProductRequest]</title>\
                        <body><h1>[mce ErrSearch $Err]</h1></body>"
            }
            form {
                switch -exact -- [dict get $dErr -errorcode] {
                    PARAM  {
                        puts [mce ErrParam $Err]
                    }
                    NOT_FOUND {
                        puts [mce ErrSearch $Err]
                    }
                    default {
                        puts [mce ErrServer $Err]
                    }
                    puts [mce ErrSearch $Err]
                # puts $Err<br/>[string map {\n <br/>} $::errorInfo]
        }
} else {
    } else {
        # > Correct response is cacheable
        wwwbaseCacheSet 1
        switch -exact -- $response(format) {
            csv {
                headers set Content-Disposition\
                        "attachment; filename=product.csv"
            }
            form {
                puts ""
            }
            puts {} 
        puts -nonewline $resultData
        
    
In addition, I have added header information, if the result is cacheable
    if {$fCacheable} {
        headers set Cache-Control max-age=86400,must-revalidate
    } else {
                headers set Cache-Control "max-age=86400,must-revalidate"
        } else {
                headers set Cache-Control "no-cache,no-store"
        }

  Rivet 2.1.x on Redhat and CentOS

HaO 2013-02-26: I am sorry, Rivet 2.1.x requires TCL 8.5.10, due to a fixed Loadlib parameter.