org.apache.xmlrpc
Class WebServer

java.lang.Object
  |
  +--org.apache.xmlrpc.WebServer
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
SecureWebServer

public class WebServer
extends java.lang.Object
implements java.lang.Runnable

A minimal web server that exclusively handles XML-RPC requests.

Author:
Hannes Wallnoefer, Jason van Zyl, Daniel Rall

Inner Class Summary
(package private)  class WebServer.AddressMatcher
           
(package private)  class WebServer.Connection
           
(package private)  class WebServer.Runner
           
 
Field Summary
protected  java.util.Vector accept
           
protected static byte[] clength
           
protected static byte[] conclose
           
protected static byte[] conkeep
           
protected static byte[] ctype
           
protected  java.util.Vector deny
           
protected static byte[] doubleNewline
           
protected  java.lang.Thread listener
           
protected static byte[] newline
           
protected static byte[] ok
           
protected  boolean paranoid
           
protected  int port
           
protected  java.lang.ThreadGroup runners
           
protected static byte[] server
           
protected  java.net.ServerSocket serverSocket
           
protected  java.util.Stack threadpool
           
protected  XmlRpcServer xmlrpc
           
 
Constructor Summary
WebServer(int port)
          Creates a Web server at the specified port number.
WebServer(int port, java.net.InetAddress add)
          Creates a Web server at the specified port number and IP address.
 
Method Summary
 void acceptClient(java.lang.String address)
          Add an IP address to the list of accepted clients.
 void addHandler(java.lang.String name, java.lang.Object target)
          Register a handler object with this name.
protected  boolean checkSocket(java.net.Socket s)
           
protected  java.net.ServerSocket createServerSocket(int port, int backlog, java.net.InetAddress add)
          Factory method to manufacture the server socket.
 void denyClient(java.lang.String address)
          Add an IP address to the list of denied clients.
protected  WebServer.Runner getRunner()
           
static void main(java.lang.String[] args)
          This can be called from command line, but you'll have to edit and recompile to change the server port or handler objects.
(package private)  void releaseRunner(WebServer.Runner runner)
           
 void removeHandler(java.lang.String name)
          Remove a handler object that was previously registered with this server.
 void run()
          Listens for client requests until stopped.
 void setParanoid(boolean p)
          Switch client filtering on/off.
 void setupServerSocket(int port, int backlog, java.net.InetAddress add)
          Initializes this server's listener socket with the specified attributes.
 void shutdown()
          Stop listening on the server port.
 void start()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

xmlrpc

protected XmlRpcServer xmlrpc

serverSocket

protected java.net.ServerSocket serverSocket

port

protected int port

listener

protected java.lang.Thread listener

paranoid

protected boolean paranoid

accept

protected java.util.Vector accept

deny

protected java.util.Vector deny

threadpool

protected java.util.Stack threadpool

runners

protected java.lang.ThreadGroup runners

ctype

protected static final byte[] ctype

clength

protected static final byte[] clength

newline

protected static final byte[] newline

doubleNewline

protected static final byte[] doubleNewline

conkeep

protected static final byte[] conkeep

conclose

protected static final byte[] conclose

ok

protected static final byte[] ok

server

protected static final byte[] server
Constructor Detail

WebServer

public WebServer(int port)
          throws java.io.IOException
Creates a Web server at the specified port number.

WebServer

public WebServer(int port,
                 java.net.InetAddress add)
          throws java.io.IOException
Creates a Web server at the specified port number and IP address.
Method Detail

main

public static void main(java.lang.String[] args)
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:

createServerSocket

protected java.net.ServerSocket createServerSocket(int port,
                                                   int backlog,
                                                   java.net.InetAddress add)
                                            throws java.lang.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).
Throws:
java.lang.Exception - Error creating listener socket.

setupServerSocket

public void setupServerSocket(int port,
                              int backlog,
                              java.net.InetAddress add)
                       throws java.lang.Exception
Initializes this server's listener socket with the specified attributes. The createServerSocket() method can be overridden to change the flavor of socket used.
See Also:
createServerSocket(int port, int backlog, InetAddress add)

start

public void start()

addHandler

public void addHandler(java.lang.String name,
                       java.lang.Object target)
Register a handler object with this name. Methods of this objects will be callable over XML-RPC as "name.method".

removeHandler

public void removeHandler(java.lang.String name)
Remove a handler object that was previously registered with this server.

setParanoid

public void setParanoid(boolean p)
Switch client filtering on/off.
See Also:
acceptClient(java.lang.String), denyClient(java.lang.String)

acceptClient

public void acceptClient(java.lang.String address)
                  throws java.lang.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.
See Also:
denyClient(java.lang.String), setParanoid(boolean)

denyClient

public void denyClient(java.lang.String address)
                throws java.lang.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.
See Also:
acceptClient(java.lang.String), setParanoid(boolean)

checkSocket

protected boolean checkSocket(java.net.Socket s)

run

public void run()
Listens for client requests until stopped.
Specified by:
run in interface java.lang.Runnable

shutdown

public void shutdown()
Stop listening on the server port.

getRunner

protected WebServer.Runner getRunner()

releaseRunner

void releaseRunner(WebServer.Runner runner)


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.