[plt-scheme] Module-based web servlet examples

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Tue Oct 17 10:24:26 EDT 2006

Norman Gray skrev:
> Noel and Jens -- thanks for your help, here.
> On 2006 Oct 17, Norman Gray wrote:
>>> Can anyone point me towards examples of module-based servlets within 
>>> the PLT Scheme web server?
> On 2006 Oct 17 , at 12.39, Jens Axel Søgaard wrote:
>> ---
>> Erroneous Xexpr
>> An Xexpr in the servlet is malformed. The exact error is
>> Expected a string, symbol, number, comment, processing instruction, or 
>> list, given #
>> The Full Xexpr Is
>> #
> It looks like there may be something platform-dependent, here (Jens is 
> clearly on Windows, I'm on OS X).

It is more likely it is due to different versions. I ran the
eaxmples on 352.6.

Note: If you have installed 352.6 as a preview version, be careful
that you start the corresponding web-server-text and not the
default one (in my case the v301 web-server-text [that's on
purpose, my web-server still runs 301]).

> Jens described what he did with my example, which worked.  Doing 
> apparently the same thing on my machine failed.  But I think I've 
> isolated a problem.
> The following servlet works:
> (module minimal-servlet mzscheme
>    (provide interface-version timeout start)
>    (require (lib "servlet.ss" "web-server"))
>    (define interface-version 'v1)
>    (define timeout 10)
>    (define (start rq)
>      (define-struct wibble (foo))
>      (let ((w (make-wibble "arg")))
>        `(html
>          (head (title "Minimal servlet"))
>          (body (h1 "Minimal servlet")
>                (p ,(format "~s" w))))))
> )
> But replacing the last item in the Xexpr by (p ,w) hangs in the way I 
> described.  That is, it was the (td ,(request-uri rq)) in my original 
> version that was causing the trouble.
> It appears, therefore, that the code translating the Xexpr to XML might 
> be a little fragile, at least on this platform (a platform dependency 
> here is surely surprising...).

A wibble-struct is not allowed as part of an Xexpr, which is
what you get with: (p ,w). Instead write a wibble->string and
use (p ,(wibble->string w)).

> Jens Axel Søgaard wrote:
>>> Jay: Is the documentation on bindings still up-to-date?
>>> <http://download.plt-scheme.org/doc/352/html/web-server/web-server-Z-H-12.html#node_idx_126> 
>> Nevermind, I found the new documentation here:
>> <http://pre.plt-scheme.org/docs/html/web-server/web-server-Z-H-12.html#node_sec_10.1.2> 
> There might still be a mismatch.  That page documents the 'request' 
> structure as
>     (define-struct request (method uri headers bindings host-ip client-ip))
> But .../PLT\ Scheme\ v352/collects/web-server/request-structs.ss includes
>     (define-struct request (method uri headers/raw bindings/raw
>                                  host-ip host-port client-ip))

 > Ought I to be worried by the mismatch?  I think this is being included
 > by servlet.ss, via servlet-structs.ss, if I'm interpreting the module
 > loading semantics correctly.

I think the definition of request changed from the official 352 and
the SVN version 352.6 I am using. If you stick to the documentation
in the HelpDesk everything ought to fit together.

Sorry for causing any confusion (I was confused myself).

Jens Axel Søgaard

Posted on the users mailing list.