Re: [Simpleweb-Support] Problem of trying simple
Brought to you by:
niallg
From: Niall G. <gal...@ya...> - 2005-09-28 21:51:31
|
Hi Carfield, --- Carfield Yim <car...@gm...> wrote: > > Within BasicServive call the handle method with > the > > status code. So for not found, the following will > > work. > > > > handle(request, response, 404); > > > > or > > > > throw new FileNotFoundException(); > > > > What I need is just set the status code so that I > can test using HTTP > status code, and I've custom error page, if I use > handle(req, res, > 404), will it call the browser to use default error > page? Well, kind of. It will generate a default error message saying "File Not Found". If you would like a custom error page then I suggest that you implement your own simple.http.serve.Format implementation. Or implement the handle(request, response, code) method yourself. > > You should use the > simple.http.load.RedirectService > > this will allow you to forward or redirect to some > > other path or URL. It will forward relative URLs > > (e.g /path/index.html) and redirect absolute URLs > (e.g > > http://domain/path/index.html). > > > > This is an abstract class, how can I get an really > instance? and I > guess the method I should use is > RedirectService.resolve(URI) , right? Yes, you implement the redirect(Request, Response) method which the action you want to take. Then when this finishes return the Resource you want to redirect to. For example, you could do either of these: public Resource redirect(Request req, Response resp) { /* some code here to do somthing */ return resolve("/path/to/some/service.html"); } public Resource redirect(Request req, Response resp) { /* some code here to do somthing */ return lookup("myNamedService"); } > Besides, is this method thread safe? Or it better > that I create new > instance for every redirect call? It is thread safe throughout, you should extend the class and provide some implementation. Although not documented the intended way to use the RedirectService is to perform some operation that does not provide a "display" then forward to a service that does, such as an ActionService. For example: Client ---> RedirectService ---> ActionService > > The Context.getMimeType method will use the file > > extension e.g "html" for index.html to convert to > a > > MIME type. The MIME database is located at > > simple/http/serve/Mime.properties. You can > override > > with mime.xml. > > > I think the default one should work... > > > > 4) Any example of how http request work? E.g. > how to > > > handle multipart request? > > > > Download the simple-upload-0.1.tar.gz package. > > > > I would recommend that you download the > > simple-demo-1.2.tar.gz package to learn how > > configuration files are used. Also, there are > plenty > > of examples. > > > Seen it work good > > However, how can I set the default class for > TemplateEngine? Can I do > similar thing like > > > LoaderEngine engine = new LoaderEngine(); > engine.load("default", > "org.skife.simple.HelloService"); > engine.link("*", "default"); > ProtocolHandler handler = > HandlerFactory.getInstance(engine); > Connection connection = > ConnectionFactory.getConnection(handler); > connection.connect(new ServerSocket(8282)); The above load and link can be encapsulated within an entry to mapper.xml as follows. <resolve match="*" name="default" type="org.skife.simple.HelloService"/> However you must use the PatternMapper. To set this for the server you can edit the simple-demo-1.2 server.xml (which is already set) or you can use a -D command such as: -Dsimple.http.load.mapper=simple.http.load.PatternMapper In the simple-demo-1.2 download the service classes are located in the directory home/class Niall Niall Gallagher __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com |