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

From: YC (yinso.chen at gmail.com)
Date: Fri Aug 7 03:33:47 EDT 2009

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))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090807/eb3cf5e2/attachment.html>

Posted on the users mailing list.