Re: [Simpleweb-Support] Problem of trying simple
Brought to you by:
niallg
From: Niall G. <gal...@ya...> - 2005-09-29 23:26:38
|
Hi, --- Carfield Yim <car...@ca...> wrote: > > 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. > > Too sad that I can't just set the response code easy > as servlet api > does, will you consider to provide this feature in > future release? You can set the response code using Response.setCode. > > > > 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"); > > } > > > > Haven't notice that some interface API haven't been > implemented... I am not sure what your are asking here? > > 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 > > > > Where should this mapper.xml put so that simple can > load? > Is it possible for me to set these information at > code? I think I can use Anywhere within the context root the current working directory or anywhere the Locator can reach. Look at simple.http.serve.FileLocator. System.setProperty("simple.http.load.mapper","simple.http.load.PatternMapper"); > > To set the mapper using, but how can I change the > resolve properties > that mapper.xml tell the system? Edit the mapper.xml file, its loaded once on startup. > Another question is how many instance will the > ActionService created? > Will it create a new instance for every request, or > it act like > servlet, create one instance then run the process() > method many time > to serve difference request? For now, my application > like this: > One instance is created, if the TemplateEngine will reload the class if it is modified though. I would set a Controller attribute. For example: controller.set("core", new Core()); And within the ActionService.prepare acquire the instance doing the following: core = (Core) system.get("core"); > public class Controller extends ActionService { > final private core.Context ctx; > public Controller(Context context) { > super(context); > try { > final File file = new File("WEB-INF/data/"); > this.ctx = new core.Context(file); > } catch (Exception e) { > throw new RuntimeException(e); > } > } > > protected void finalize() throws Throwable { > super.finalize(); > ctx.shutdown(); > } > > private void handleRequest(Request req, Response > res, Document document); > > public void process(Request request, Response > response) throws Exception { > try { > handleRequest(request, response, > system.lookup("template.vm")); > } catch (Exception e) { > throw new RuntimeException(e); > } > } > > public static void main(String[] list) throws > Exception { > TemplateEngine engine = new TemplateEngine(new > FileContext(), new > VelocityContainer(new TemplateManager().engine())); > Connection connection = > ConnectionFactory.getConnection(engine); > connection.connect(new ServerSocket(8082)); > } > } > > Where > final private core.Context ctx > should only created once for the application, if > Controller will > create may time then I need to think difference > implement, and now I > use finalizer to trigger the clean up, which is not > work in most case. > Just wonder if simple provide standard way for me to > clean up > application if the user quit? > Niall Niall Gallagher __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com |