Hi,
I went on playing on my syslog analyser and tried the webrick framework wich I like a lot as it is simple but powerful. I defined a servlet which should read a definition file and render its result.
My dir structur looks like
htdocs
- filter/
- filter1.fd
- filter2.fd
I mount my servlet to /filter and it should take any file argument in the url after /filter as a filename to a filter definition file e.g. http://localhost/filter/filter1.fd should render the output produced by filter one.
I browsed the webrick source (httprequest.rb etc. but I can't find a var for that. Is there a better way then extract the information from the request_uri var?
Other solutions are also welcome.
···
--
Daniel Völkerts
"Irren ist menschlich, und noch menschlicher ist es,
einem Computer die Schuld zu geben." - U
Daniel Völkerts wrote:
Hi,
I went on playing on my syslog analyser and tried the webrick framework wich I like a lot as it is simple but powerful. I defined a servlet which should read a definition file and render its result.
My dir structur looks like
htdocs
- filter/
- filter1.fd
- filter2.fd
I mount my servlet to /filter and it should take any file argument in the url after /filter as a filename to a filter definition file e.g. http://localhost/filter/filter1.fd should render the output produced by filter one.
And it doesn't?
I browsed the webrick source (httprequest.rb etc. but I can't find a var for that. Is there a better way then extract the information from the request_uri var?
I believe request.script_name gives the the text after the leading part of the URL. But it looks to me that this should just work as it is.
You should not have to explicitly extract the file name; WEBrick should just serve back the file, since filter/ maps to the directory where the filter files are.
For example, if I start a server, running from /some/dir/, with this:
port = 12000
puts "URL: http://#{Socket.gethostname}:#{port}"
s = HTTPServer.new(
:Port => port
)
s.mount("/", WEBrick::HTTPServlet::FileHandler, dir, true)
then if some/dir/ has a file foo.txt, I can load it with
http://localhost:12000/foo.txt
James
···
Other solutions are also welcome.
James Britt wrote:
Thanks for your reply.
I mount my servlet to /filter and it should take any file argument in the url after /filter as a filename to a filter definition file e.g. http://localhost/filter/filter1.fd should render the output produced by filter one.
And it doesn't?
No, I'd like to pass the called file to the servlet which regonize the request...
This is my flow
Browser is pointed to http://localhost/filter/filter1.fd
As my Servlet ist mounted to /filter he regonize the request and thats the part I'd like to implement -> now the servlet should look up the filter to use (here filter1.fd) and should parse this filter file for directives which controll the output.
So I've to extract the filename from the request_uri. The way I went today is to call
filterName = req.request_uri.to_s.scan(/\w+\.fd/)
My question was if there is another possible better ruby way or variable included with webrick to accomplish this task.
···
--
Daniel Völkerts
"Irren ist menschlich, und noch menschlicher ist es,
einem Computer die Schuld zu geben." - U
Daniel Völkerts wrote:
This is my flow
Browser is pointed to http://localhost/filter/filter1.fd
As my Servlet ist mounted to /filter he regonize the request and thats the part I'd like to implement -> now the servlet should look up the filter to use (here filter1.fd) and should parse this filter file for directives which controll the output.
So, the part of the URL that comes after /filter/ is data to be passed to some method?
So I've to extract the filename from the request_uri. The way I went today is to call
filterName = req.request_uri.to_s.scan(/\w+\.fd/)
My question was if there is another possible better ruby way or variable included with webrick to accomplish this task.
If you have /filter/ mapped to a servlet, and call http://localhost/filter/someFilterFile, then, in your servlet, request.path should give you "/filter/someFilterFile"
def do_GET(req, res)
url_parts = req.path.split( '/' )
base = url_parts[0]
filter_file_path = url_parts[1]
end
That's one way to grab the data. (Not the best; no error checking, etc.)
James
James Britt wrote:
So, the part of the URL that comes after /filter/ is data to be passed to some method?
Yeah.That's the way I'd like to process the file through the servlet.
If you have /filter/ mapped to a servlet, and call http://localhost/filter/someFilterFile, then, in your servlet, request.path should give you "/filter/someFilterFile"
def do_GET(req, res)
url_parts = req.path.split( '/' )
base = url_parts[0]
filter_file_path = url_parts[1]
end
That's one way to grab the data. (Not the best; no error checking, etc.)
So do I. I extend it with a kind of error correction and it works. Thanks in advance.
···
--
Daniel Völkerts
"Irren ist menschlich, und noch menschlicher ist es,
einem Computer die Schuld zu geben." - U