The {@link WebServer} is a minimal HTTP server, that might be usedas an embedded web server.
Use of the {@link WebServer} has grown very popular amongst usersof Apache XML-RPC. Why this is the case, can hardly be explained, because the {@link WebServer} is at best a workaround, compared tofull blown servlet engines like Tomcat or Jetty. For example, under heavy load it will almost definitely be slower than a real servlet engine, because it does neither support proper keepalive (multiple requests per physical connection) nor chunked mode (in other words, it cannot stream requests).
If you still insist in using the {@link WebServer}, it is recommended to use its subclass, the {@link ServletWebServer} instead,which offers a minimal subset of the servlet API. In other words, you keep yourself the option to migrate to a real servlet engine later.
Use of the {@link WebServer} goes roughly like this: First of all,create a property file (for example "MyHandlers.properties") and add it to your jar file. The property keys are handler names and the property values are the handler classes. Once that is done, create an instance of WebServer:
final int portNumber = 8088; final String propertyFile = "MyHandler.properties"; PropertyHandlerMapping mapping = new PropertyHandlerMapping(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); mapping.load(cl, propertyFile); WebServer webServer = new WebServer(port); XmlRpcServerConfigImpl config = new XmlRpcServerConfigImpl(); XmlRpcServer server = server.getXmlRpcServer(); server.setConfig(config); server.setHandlerMapping(mapping); server.start();
|
|