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());
}
}
}