[plt-scheme] web-server: serving web server files within a servlet

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Aug 7 10:10:26 EDT 2009

Your program works as expected for me on 4.2.1.

Jay

On Fri, Aug 7, 2009 at 1:33 AM, YC<yinso.chen at gmail.com> wrote:
>
> On Thu, Aug 6, 2009 at 9:02 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>>
>> If you call next-dispatcher, the "current" request will be delivered
>> to the next dispatcher (such as the static file handler.) If you want
>> a different one, you could create your own dispatcher with a similar
>> for that uses a different request (maybe I should do that...?) Another
>> option is to return a redirect response.
>
> It seems that I am not understanding dispatcher well enough to use it - can
> (next-dispatcher) be called from within a servlet?  I am getting the
> following error:
>
> (file
> "C:\\Local\\PLT4.1.3\\collects\\web-server\\dispatchers\\dispatch-servlets.ss")
> broke the contract   (-> url? exn? response?) on servlet-error-responder;
> expected <exn?>, given: #<exn:dispatcher>
>
> What I did was basically test to see if this is a path I wanted to handle,
> and throw exn:dispatcher... is there another way of using it?
>
> (define (start request)
>   (let ((path-list (map path/param-path (url-path (request-uri request)))))
>     (cond ((equal? path-list '("test"))
>            `(p "this is a test resopnse"))
>           (else ;; let web-server handle the path.
>            (next-dispatcher)))))
>
> The servlet is run through serve/servlet.
>
> ;; web.ss
> #lang scheme/base
>
> (require web-server/servlet
>          web-server/servlet-env
>          "servlet1.ss"
>          )
> ;; why did the current-directory get reset?
> (thread (lambda ()
>           (serve/servlet start #:port 8800
>                          #:servlet-path "/"
>                          #:launch-browser? #f
>                          #:listen-ip #f
>                          #:servlet-namespace '( "servlet1.ss")
>                          #:servlets-root (current-directory)
>                          #:servlet-regexp #px".*"
>                          #:server-root-path (current-directory)
>                          #:extra-files-paths (map string->path
> '("c:\\data\\ajax"))
>                          )))
>
> ;; servlet1.ss
> #lang scheme/base
> (require (only-in web-server/servlet
> current-servlet-continuation-expiration-handler)
>          web-server/managers/lru
>          web-server/http/request-structs
>          web-server/dispatchers/dispatch
>          net/url
>          )
>
> (define interface-version 'v2)
>
> (define manager
>   (create-LRU-manager current-servlet-continuation-expiration-handler
>                       60
>                       3600
>                       (lambda () #t)
>                       #:initial-count 1
>                       #:inform-p (lambda _ (void))))
>
> (define (start request)
>   (let ((path-list (map path/param-path (url-path (request-uri request)))))
>     (cond ((equal? path-list '("test"))
>            `(p "this is a test resopnse"))
>           (else
>            (next-dispatcher)))))
>
> (provide (all-defined-out))
>
>
>
>
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.