Classes | |
class | AddressMatcher |
Public Member Functions | |
void | acceptClient (String pAddress) |
void | denyClient (String pAddress) |
int | getPort () |
XmlRpcStreamServer | getXmlRpcServer () |
void | log (Throwable pError) |
void | log (String pMessage) |
void | run () |
void | setParanoid (boolean pParanoid) |
synchronized void | shutdown () |
void | start () throws IOException |
WebServer (int pPort) | |
WebServer (int pPort, InetAddress pAddr) | |
Protected Member Functions | |
boolean | allowConnection (Socket s) |
ServerSocket | createServerSocket (int pPort, int backlog, InetAddress addr) throws IOException |
boolean | isParanoid () |
ThreadPool.Task | newTask (WebServer pServer, XmlRpcStreamServer pXmlRpcServer, Socket pSocket) throws IOException |
ThreadPool | newThreadPool () |
XmlRpcStreamServer | newXmlRpcStreamServer () |
Protected Attributes | |
final List | accept = new ArrayList() |
final List | deny = new ArrayList() |
final XmlRpcStreamServer | server = newXmlRpcStreamServer() |
ServerSocket | serverSocket |
Static Package Attributes | |
static final String | HTTP_11 = "HTTP/1.1" |
Private Member Functions | |
synchronized void | setupServerSocket (int backlog) throws IOException |
Private Attributes | |
InetAddress | address |
Thread | listener |
boolean | paranoid |
ThreadPool | pool |
int | port |
The WebServer is a minimal HTTP server, that might be used as an embedded web server.
Use of the WebServer has grown very popular amongst users of Apache XML-RPC. Why this is the case, can hardly be explained, because the WebServer is at best a workaround, compared to full 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 WebServer, it is recommended to use its subclass, the 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 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 port = 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 = webServer.getXmlRpcServer(); server.setConfig(config); server.setHandlerMapping(mapping); webServer.start();
Definition at line 72 of file WebServer.java.
org.apache.xmlrpc.webserver.WebServer.WebServer | ( | int | pPort | ) | [inline] |
Creates a web server at the specified port number.
pPort | Port number; 0 for a random port, choosen by the operating system. |
Definition at line 135 of file WebServer.java.
org.apache.xmlrpc.webserver.WebServer.WebServer | ( | int | pPort, |
InetAddress | pAddr | ||
) | [inline] |
Creates a web server at the specified port number and IP address.
pPort | Port number; 0 for a random port, choosen by the operating system. |
pAddr | Local IP address; null for all available IP addresses. |
Definition at line 144 of file WebServer.java.
void org.apache.xmlrpc.webserver.WebServer.acceptClient | ( | String | pAddress | ) | [inline] |
Add an IP address to the list of accepted clients. The parameter can contain '*' as wildcard character, e.g. "192.168.*.*". You must call setParanoid(true) in order for this to have any effect.
pAddress | The IP address being enabled. |
IllegalArgumentException | Parsing the address failed. |
Definition at line 256 of file WebServer.java.
boolean org.apache.xmlrpc.webserver.WebServer.allowConnection | ( | Socket | s | ) | [inline, protected] |
Checks incoming connections to see if they should be allowed. If not in paranoid mode, always returns true.
s | The socket to inspect. |
Definition at line 280 of file WebServer.java.
ServerSocket org.apache.xmlrpc.webserver.WebServer.createServerSocket | ( | int | pPort, |
int | backlog, | ||
InetAddress | addr | ||
) | throws IOException [inline, protected] |
Factory method to manufacture the server socket. Useful as a hook method for subclasses to override when they desire different flavor of socket (i.e. a SSLServerSocket
).
pPort | Port number; 0 for a random port, choosen by the operating system. |
backlog | |
addr | If null , binds to INADDR_ANY , meaning that all network interfaces on a multi-homed host will be listening. |
IOException | Error creating listener socket. |
Definition at line 162 of file WebServer.java.
void org.apache.xmlrpc.webserver.WebServer.denyClient | ( | String | pAddress | ) | [inline] |
Add an IP address to the list of denied clients. The parameter can contain '*' as wildcard character, e.g. "192.168.*.*". You must call setParanoid(true) in order for this to have any effect.
pAddress | The IP address being disabled. |
IllegalArgumentException | Parsing the address failed. |
Definition at line 269 of file WebServer.java.
int org.apache.xmlrpc.webserver.WebServer.getPort | ( | ) | [inline] |
Returns the port, on which the web server is running. This method may be invoked after start() only.
Definition at line 396 of file WebServer.java.
Returns the org.apache.xmlrpc.server.XmlRpcServer.
Definition at line 416 of file WebServer.java.
boolean org.apache.xmlrpc.webserver.WebServer.isParanoid | ( | ) | [inline, protected] |
Returns the client filtering state.
Definition at line 244 of file WebServer.java.
void org.apache.xmlrpc.webserver.WebServer.log | ( | Throwable | pError | ) | [inline] |
Logs an error.
pError | The error being logged. |
Definition at line 401 of file WebServer.java.
void org.apache.xmlrpc.webserver.WebServer.log | ( | String | pMessage | ) | [inline] |
Logs a message.
pMessage | The being logged. |
Definition at line 409 of file WebServer.java.
ThreadPool.Task org.apache.xmlrpc.webserver.WebServer.newTask | ( | WebServer | pServer, |
XmlRpcStreamServer | pXmlRpcServer, | ||
Socket | pSocket | ||
) | throws IOException [inline, protected] |
Definition at line 304 of file WebServer.java.
ThreadPool org.apache.xmlrpc.webserver.WebServer.newThreadPool | ( | ) | [inline, protected] |
Definition at line 369 of file WebServer.java.
XmlRpcStreamServer org.apache.xmlrpc.webserver.WebServer.newXmlRpcStreamServer | ( | ) | [inline, protected] |
Definition at line 120 of file WebServer.java.
void org.apache.xmlrpc.webserver.WebServer.run | ( | ) | [inline] |
Listens for client requests until stopped. Call start() to invoke this method, and shutdown() to break out of it.
RuntimeException | Generally caused by either an UnknownHostException or BindException with the vanilla web server. |
Definition at line 321 of file WebServer.java.
void org.apache.xmlrpc.webserver.WebServer.setParanoid | ( | boolean | pParanoid | ) | [inline] |
Switch client filtering on/off.
pParanoid | True to enable filtering, false otherwise. |
Definition at line 234 of file WebServer.java.
synchronized void org.apache.xmlrpc.webserver.WebServer.setupServerSocket | ( | int | backlog | ) | throws IOException [inline, private] |
Initializes this server's listener socket with the specified attributes, assuring that a socket timeout has been set. The createServerSocket(int, int, InetAddress) method can be overridden to change the flavor of socket used.
Definition at line 175 of file WebServer.java.
synchronized void org.apache.xmlrpc.webserver.WebServer.shutdown | ( | ) | [inline] |
Stop listening on the server port. Shutting down our listener effectively breaks it out of its run() loop.
Definition at line 380 of file WebServer.java.
void org.apache.xmlrpc.webserver.WebServer.start | ( | ) | throws IOException [inline] |
Spawns a new thread which binds this server to the port it's configured to accept connections on.
IOException | Binding the server socket failed. |
Definition at line 217 of file WebServer.java.
final List org.apache.xmlrpc.webserver.WebServer.accept = new ArrayList() [protected] |
Definition at line 116 of file WebServer.java.
InetAddress org.apache.xmlrpc.webserver.WebServer.address [private] |
Definition at line 125 of file WebServer.java.
final List org.apache.xmlrpc.webserver.WebServer.deny = new ArrayList() [protected] |
Definition at line 117 of file WebServer.java.
final String org.apache.xmlrpc.webserver.WebServer.HTTP_11 = "HTTP/1.1" [static, package] |
Definition at line 130 of file WebServer.java.
Thread org.apache.xmlrpc.webserver.WebServer.listener [private] |
Definition at line 114 of file WebServer.java.
boolean org.apache.xmlrpc.webserver.WebServer.paranoid [private] |
Definition at line 128 of file WebServer.java.
Definition at line 115 of file WebServer.java.
int org.apache.xmlrpc.webserver.WebServer.port [private] |
Definition at line 126 of file WebServer.java.
final XmlRpcStreamServer org.apache.xmlrpc.webserver.WebServer.server = newXmlRpcStreamServer() [protected] |
Definition at line 118 of file WebServer.java.
ServerSocket org.apache.xmlrpc.webserver.WebServer.serverSocket [protected] |
Definition at line 113 of file WebServer.java.