|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.xmlrpc.webserver.WebServer
public class WebServer
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();
Nested Class Summary | |
---|---|
private class |
WebServer.AddressMatcher
|
Field Summary | |
---|---|
protected java.util.List |
accept
|
private java.net.InetAddress |
address
|
protected java.util.List |
deny
|
(package private) static java.lang.String |
HTTP_11
|
private java.lang.Thread |
listener
|
private static org.apache.commons.logging.Log |
log
|
private boolean |
paranoid
|
private org.apache.xmlrpc.util.ThreadPool |
pool
|
private int |
port
|
protected XmlRpcStreamServer |
server
|
protected java.net.ServerSocket |
serverSocket
|
Constructor Summary | |
---|---|
WebServer(int pPort)
Creates a web server at the specified port number. |
|
WebServer(int pPort,
java.net.InetAddress pAddr)
Creates a web server at the specified port number and IP address. |
Method Summary | |
---|---|
void |
acceptClient(java.lang.String pAddress)
Add an IP address to the list of accepted clients. |
protected boolean |
allowConnection(java.net.Socket s)
Checks incoming connections to see if they should be allowed. |
protected java.net.ServerSocket |
createServerSocket(int pPort,
int backlog,
java.net.InetAddress addr)
Factory method to manufacture the server socket. |
void |
denyClient(java.lang.String pAddress)
Add an IP address to the list of denied clients. |
int |
getPort()
Returns the port, on which the web server is running. |
XmlRpcStreamServer |
getXmlRpcServer()
Returns the XmlRpcServer . |
void |
log(java.lang.String pMessage)
Logs a message. |
void |
log(java.lang.Throwable pError)
Logs an error. |
protected org.apache.xmlrpc.util.ThreadPool.Task |
newTask(WebServer pServer,
XmlRpcStreamServer pXmlRpcServer,
java.net.Socket pSocket)
|
protected org.apache.xmlrpc.util.ThreadPool |
newThreadPool()
|
protected XmlRpcStreamServer |
newXmlRpcStreamServer()
|
void |
run()
Listens for client requests until stopped. |
void |
setParanoid(boolean pParanoid)
Switch client filtering on/off. |
private void |
setupServerSocket(int backlog)
Initializes this server's listener socket with the specified attributes, assuring that a socket timeout has been set. |
void |
shutdown()
Stop listening on the server port. |
void |
start()
Spawns a new thread which binds this server to the port it's configured to accept connections on. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final org.apache.commons.logging.Log log
protected java.net.ServerSocket serverSocket
private java.lang.Thread listener
private org.apache.xmlrpc.util.ThreadPool pool
protected final java.util.List accept
protected final java.util.List deny
protected final XmlRpcStreamServer server
private java.net.InetAddress address
private int port
private boolean paranoid
static final java.lang.String HTTP_11
Constructor Detail |
---|
public WebServer(int pPort)
pPort
- Port number; 0 for a random port, choosen by the
operating system.public WebServer(int pPort, java.net.InetAddress pAddr)
pPort
- Port number; 0 for a random port, choosen by the
operating system.pAddr
- Local IP address; null for all available IP addresses.Method Detail |
---|
protected XmlRpcStreamServer newXmlRpcStreamServer()
protected java.net.ServerSocket createServerSocket(int pPort, int backlog, java.net.InetAddress addr) throws java.io.IOException
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.
java.io.IOException
- Error creating listener socket.private void setupServerSocket(int backlog) throws java.io.IOException
createServerSocket(int, int, InetAddress)
method can
be overridden to change the flavor of socket used.
java.io.IOException
createServerSocket(int, int, InetAddress)
public void start() throws java.io.IOException
java.io.IOException
- Binding the server socket failed.run()
public void setParanoid(boolean pParanoid)
pParanoid
- True to enable filtering, false otherwise.acceptClient(java.lang.String)
,
denyClient(java.lang.String)
public void acceptClient(java.lang.String pAddress)
pAddress
- The IP address being enabled.
java.lang.IllegalArgumentException
- Parsing the address failed.denyClient(java.lang.String)
,
setParanoid(boolean)
public void denyClient(java.lang.String pAddress)
pAddress
- The IP address being disabled.
java.lang.IllegalArgumentException
- Parsing the address failed.acceptClient(java.lang.String)
,
setParanoid(boolean)
protected boolean allowConnection(java.net.Socket s)
s
- The socket to inspect.
protected org.apache.xmlrpc.util.ThreadPool.Task newTask(WebServer pServer, XmlRpcStreamServer pXmlRpcServer, java.net.Socket pSocket) throws java.io.IOException
java.io.IOException
public void run()
start()
to invoke this method, and shutdown()
to
break out of it.
run
in interface java.lang.Runnable
java.lang.RuntimeException
- Generally caused by either an
UnknownHostException
or BindException
with the vanilla web server.start()
,
shutdown()
protected org.apache.xmlrpc.util.ThreadPool newThreadPool()
public void shutdown()
listener
effectively breaks it out of its run()
loop.
run()
public int getPort()
start()
only.
public void log(java.lang.Throwable pError)
pError
- The error being logged.public void log(java.lang.String pMessage)
pMessage
- The being logged.public XmlRpcStreamServer getXmlRpcServer()
XmlRpcServer
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |