views:

209

answers:

1

Hey yall, I have a wicket- and also a server-related question:

We built a little server with java (yeah, I know, why re-invent the wheel ... I got that a lot when I asked the question on the wicket-mailing-list) .... so let's just say, it is desperately needed b/c ... ehm ... I still can't think of a good reason, but there's not a lot I can do about it ... so I finally got this little server to run servlets ... as far as I know, to run wicket you need a server that can run servlets ... (as for my lack of english let's just say: it is supposed to be a servlet container like tomcat) ... now that I do have this very beautiful server, does anybody have an idea what I have to do, so that my wicket-apps run on it? how do I tell my server that it is supposed to run a wicket-app?

Hope I explained it well ... thnx in advance :)

... dg


ok, a little source ... I did this following a tutorial:

HttpServer where the "magic" happens:

 while (!shutdown) {
  // ... all the stuff before

    //check if this is a request for a servlet or a static resource
    //a request for a servlet begins with "/servlet/"
    if (request.getUri().startsWith("/servlet/")) {
        System.out.println( "SERVLET-REQUEST\n\n" );
      ServletProcessor2 processor = new ServletProcessor2();
      processor.process(request, response);
    }
    else {
        System.out.println( "STATICRESOURCE-REQUEST" );
      StaticResourceProcessor processor = new StaticResourceProcessor();
      processor.process(request, response);
    }
 // ... all the stuff after
}

Now the ServletProcessor:

public class ServletProcessor2 {

public void process(Request request, Response response) {

 String uri = request.getUri();
 String servletName = uri.substring(uri.lastIndexOf("/") + 1);
 System.out.println( "SERVLETNAME ... " + servletName );
 URLClassLoader loader = null;

try {
   // create a URLClassLoader
   URL[] urls = new URL[1];
   URLStreamHandler streamHandler = null;
   File classPath = new File(Constants.WEB_ROOT);
   // the forming of repository is taken from the createClassLoader method in
   // org.apache.catalina.startup.ClassLoaderFactory
   String repository = (new URL("file", null, classPath.getCanonicalPath() + File.separator)).toString() ;
   System.out.println( "REPOSITORY ... " + repository );
   // the code for forming the URL is taken from the addRepository method in
   // org.apache.catalina.loader.StandardClassLoader class.
   urls[0] = new URL(null, repository, streamHandler);
   loader = new URLClassLoader(urls);
 }
 catch (IOException e) {
   System.out.println(e.toString() );
 }
 Class myClass = null;
 try {
   myClass = loader.loadClass(servletName);
 }
 catch (ClassNotFoundException e) {
   System.out.println("FEHLER: " + e.toString() + " ... CAUSE: " + e.getCause() );
   e.printStackTrace();
 }

 Servlet servlet = null;
 RequestFacade requestFacade = new RequestFacade(request);
 ResponseFacade responseFacade = new ResponseFacade(response);
 try {
     servlet = (Servlet) myClass.newInstance();
     servlet.service((ServletRequest) requestFacade, (ServletResponse) responseFacade);
 }
 catch (Exception e) {
   System.out.println( "Fehler: " + e.toString() + " ... CAUSE: " + e.getCause() );
   e.printStackTrace();
 }
 catch (Throwable e) {
   System.out.println(e.toString());
 }

}
}
+3  A: 

the simple answer is that you will need to implement the Servlet API. The wicket documentation doesn't seem to say what the exact required version but I'm sure it'll be at least 2.4. Not a job I'd recommend you do, it's a difficult thing to do correctly and your just opening your self to a world of pain.

If you need to embed a server then might I recommend you start with jetty and customise it to meet what ever requirements you have. Jetty has a very permissive license so you don't have to worry about using in a commercial product and can scale pretty much with the best of them.

Gareth Davis
thank you gid, that's somehow the answer I was expecting ... at least the "it is not easy, better dun do it ..."-part ... sad but true ... Thank you!
doro
Just looking at your ServletRequest processor...there is a bit more to running a servlet than just creating it and calling service(). There a whole servlet life cycle to implement and that's just for starters
Gareth Davis
good to know that I am not underestimating this whole server thing for nothing ... just need to explain that to my boss *g*
doro