Re: [Simpleweb-Support] Problem of trying simple
Brought to you by:
niallg
|
From: Carfield Y. <car...@ca...> - 2005-09-29 22:14:18
|
> 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?
>
> 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...
> The above load and link can be encapsulated within an
> entry to mapper.xml as follows.
>
> <resolve match=3D"*" name=3D"default"
> type=3D"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=3Dsimple.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
System.setProperty("simple.http.load.mapper","simple.http.load.PatternMappe=
r");
To set the mapper using, but how can I change the resolve properties
that mapper.xml tell the system?
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:
public class Controller extends ActionService {
=09final private core.Context ctx;
=09public Controller(Context context) {
=09=09super(context);
=09=09try {
=09=09=09final File file =3D new File("WEB-INF/data/");
=09=09=09this.ctx =3D new core.Context(file);
=09=09} catch (Exception e) {
=09=09=09throw new RuntimeException(e);
=09=09}
=09}
=09protected void finalize() throws Throwable {
=09=09super.finalize();
=09=09ctx.shutdown();
=09}
=09private void handleRequest(Request req, Response res, Document document)=
;
=09public void process(Request request, Response response) throws Exception=
{
=09=09try {
=09=09=09handleRequest(request, response, system.lookup("template.vm"));
=09=09} catch (Exception e) {
=09=09=09throw new RuntimeException(e);
=09=09}
=09}
=09public static void main(String[] list) throws Exception {
=09=09TemplateEngine engine =3D new TemplateEngine(new FileContext(), new
VelocityContainer(new TemplateManager().engine()));
=09=09Connection connection =3D ConnectionFactory.getConnection(engine);
=09=09connection.connect(new ServerSocket(8082));
=09}
}
Where
=09final 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?
|