org.apache.xmlrpc
Class WebServer
java.lang.Object
org.apache.xmlrpc.WebServer
- Runnable
public class WebServer
extends java.lang.Object
implements Runnable
A minimal web server that exclusively handles XML-RPC requests.
WebServer(int port) - Creates a web server at the specified port number.
|
WebServer(int port, InetAddress addr) - Creates a web server at the specified port number and IP address.
|
WebServer(int port, InetAddress addr, XmlRpcServer xmlrpc) - Creates a web server at the specified port number and IP
address.
|
void | acceptClient(String address) - Add an IP address to the list of accepted clients.
|
protected void | addDefaultHandlers() - Adds the bundled handlers to the server.
|
void | addHandler(String name, Object target) - Register a handler object with this name.
|
protected boolean | allowConnection(Socket s) - Checks incoming connections to see if they should be allowed.
|
protected boolean | checkSocket(Socket s) - Use allowConnection(Socket) instead.
|
protected ServerSocket | createServerSocket(int port, int backlog, InetAddress addr) - Factory method to manufacture the server socket.
|
void | denyClient(String address) - Add an IP address to the list of denied clients.
|
protected static int | determinePort(String[] argv, int defaultPort) - Examines command line arguments from
argv .
|
protected WebServer.Runner | getRunner()
|
static void | main(String[] argv) - This can be called from command line, but you'll have to edit
and recompile to change the server port or handler objects.
|
void | removeHandler(String name) - Remove a handler object that was previously registered with this server.
|
(package private) void | repoolRunner(WebServer.Runner runner) - Put
runner back into threadpool .
|
void | run() - Listens for client requests until stopped.
|
void | setParanoid(boolean p) - 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.
|
protected static byte[] | toHTTPBytes(String text) - Returns the US-ASCII encoded byte representation of text for
HTTP use (as per section 2.2 of RFC 2068).
|
HTTP_11
private static final String HTTP_11
STAR
private static final String STAR
accept
protected Vector accept
address
private InetAddress address
clength
protected static final byte[] clength
conclose
protected static final byte[] conclose
conkeep
protected static final byte[] conkeep
ctype
protected static final byte[] ctype
deny
protected Vector deny
doubleNewline
protected static final byte[] doubleNewline
listener
protected Thread listener
newline
protected static final byte[] newline
ok
protected static final byte[] ok
paranoid
private boolean paranoid
runners
protected ThreadGroup runners
server
protected static final byte[] server
serverSocket
protected ServerSocket serverSocket
threadpool
protected Stack threadpool
wwwAuthenticate
protected static final byte[] wwwAuthenticate
WebServer
public WebServer(int port)
Creates a web server at the specified port number.
WebServer
public WebServer(int port,
InetAddress addr)
Creates a web server at the specified port number and IP address.
WebServer
public WebServer(int port,
InetAddress addr,
XmlRpcServer xmlrpc)
Creates a web server at the specified port number and IP
address.
acceptClient
public void acceptClient(String address)
throws IllegalArgumentException
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.
addDefaultHandlers
protected void addDefaultHandlers()
throws Exception
addHandler
public void addHandler(String name,
Object target)
Register a handler object with this name. Methods of this objects will be
callable over XML-RPC as "name.method".
allowConnection
protected boolean allowConnection(Socket s)
Checks incoming connections to see if they should be allowed.
If not in paranoid mode, always returns true.
s
- The socket to inspect.
- Whether the connection should be allowed.
checkSocket
protected boolean checkSocket(Socket s)
Use allowConnection(Socket) instead.
createServerSocket
protected ServerSocket createServerSocket(int port,
int backlog,
InetAddress addr)
throws Exception
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
).
port
- backlog
- addr
- If null
, binds to
INADDR_ANY
, meaning that all network interfaces on
a multi-homed host will be listening.
denyClient
public void denyClient(String address)
throws IllegalArgumentException
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.
determinePort
protected static int determinePort(String[] argv,
int defaultPort)
Examines command line arguments from argv
. If a
port may have been provided, parses that port (exiting with
error status if the port cannot be parsed). If no port is
specified, defaults to defaultPort
.
defaultPort
- The port to use if none was specified.
main
public static void main(String[] argv)
This
can be called from command line, but you'll have to edit
and recompile to change the server port or handler objects. By default,
it sets up the following responders:
- A java.lang.String object
- The java.lang.Math class (making its static methods callable via
XML-RPC)
- An Echo handler that returns the argument array
removeHandler
public void removeHandler(String name)
Remove a handler object that was previously registered with this server.
repoolRunner
(package private) void repoolRunner(WebServer.Runner runner)
runner
- The instance to reclaim.
run
public void run()
Listens for client requests until stopped. Call
start()
to invoke this method, and
shutdown()
to
break out of it.
setParanoid
public void setParanoid(boolean p)
Switch client filtering on/off.
acceptClient(java.lang.String)
, denyClient(java.lang.String)
setupServerSocket
private void setupServerSocket(int backlog)
throws Exception
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.
shutdown
public void shutdown()
Stop listening on the server port. Shutting down our
listener
effectively breaks it out of its
run()
loop.
start
public void start()
Spawns a new thread which binds this server to the port it's
configured to accept connections on.
toHTTPBytes
protected static final byte[] toHTTPBytes(String text)
Returns the US-ASCII encoded byte representation of text for
HTTP use (as per section 2.2 of RFC 2068).
Copyright B) 1999-2002 Apache Software Foundation. All Rights Reserved.