org.apache.xmlrpc
Class WebServer2

java.lang.Object
  extended by org.apache.xmlrpc.WebServer2
All Implemented Interfaces:
java.lang.Runnable

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

The purpose of this WebServer is to provide more robust server which correctly works with keep alive. Original XML RPC WebServer does not wait for threads working in keep-alive mode after shutdown, this causes problems in our tests. It also uses global flag XmlRpc.keepAlive which is inconvenient.

Author:
Pavel.Sher Date: 26.06.2007

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  java.util.ArrayList myHandlerNames
           
protected static byte[] newline
           
protected static byte[] ok
           
protected static byte[] server
           
protected  org.apache.xmlrpc.WebServer2.ServerSocketWrapper serverSocket
           
protected  java.util.Stack threadpool
           
protected  java.util.ArrayList workers
           
protected static byte[] wwwAuthenticate
           
protected  org.apache.xmlrpc.XmlRpcServer xmlrpc
           
 
Method Summary
 void acceptClient(java.lang.String address)
          Add an IP address to the list of accepted clients.
protected  void addDefaultHandlers()
          Adds the bundled handlers to the server.
 void addHandler(java.lang.String name, java.lang.Object target)
          Register a handler object with this name.
protected  boolean allowConnection(java.net.Socket s)
          Checks incoming connections to see if they should be allowed.
protected  boolean checkSocket(java.net.Socket s)
          Deprecated. Use allowConnection(Socket) instead.
static WebServer2 createStartedServer(int initialPort, org.apache.xmlrpc.XmlRpcServer xmlrpc)
           
 void denyClient(java.lang.String address)
          Add an IP address to the list of denied clients.
 java.net.InetAddress getAddress()
           
 int getPort()
           
protected  org.apache.xmlrpc.WebServer2.Runner getRunner()
           
 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 setKeepAlive(boolean keepAlive)
           
 void setParanoid(boolean p)
          Switch client filtering on/off.
 void setSocketReadTimeout(int timeout)
           
 void shutdown()
          Stop listening on the server port.
protected static byte[] toHTTPBytes(java.lang.String text)
          Returns the US-ASCII encoded byte representation of text for HTTP use (as per section 2.2 of RFC 2068).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlrpc

protected org.apache.xmlrpc.XmlRpcServer xmlrpc

serverSocket

protected org.apache.xmlrpc.WebServer2.ServerSocketWrapper serverSocket

listener

protected java.lang.Thread listener

accept

protected java.util.Vector accept

deny

protected java.util.Vector deny

threadpool

protected java.util.Stack threadpool

workers

protected final java.util.ArrayList workers

myHandlerNames

protected final java.util.ArrayList myHandlerNames

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

wwwAuthenticate

protected static final byte[] wwwAuthenticate
Method Detail

createStartedServer

public static WebServer2 createStartedServer(int initialPort,
                                             org.apache.xmlrpc.XmlRpcServer xmlrpc)

setSocketReadTimeout

public void setSocketReadTimeout(int timeout)

getPort

public int getPort()

getAddress

public java.net.InetAddress getAddress()

toHTTPBytes

protected static byte[] toHTTPBytes(java.lang.String text)
Returns the US-ASCII encoded byte representation of text for HTTP use (as per section 2.2 of RFC 2068).


setKeepAlive

public void setKeepAlive(boolean keepAlive)

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".


addDefaultHandlers

protected void addDefaultHandlers()
                           throws java.lang.Exception
Adds the bundled handlers to the server. Called by #main(String[]).

Throws:
java.lang.Exception

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.

Throws:
java.lang.IllegalArgumentException
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.

Throws:
java.lang.IllegalArgumentException
See Also:
acceptClient(java.lang.String), setParanoid(boolean)

allowConnection

protected boolean allowConnection(java.net.Socket s)
Checks incoming connections to see if they should be allowed. If not in paranoid mode, always returns true.

Parameters:
s - The socket to inspect.
Returns:
Whether the connection should be allowed.

checkSocket

protected boolean checkSocket(java.net.Socket s)
Deprecated. Use allowConnection(Socket) instead.

DEPRECATED: Do not use this method, it will be removed soon. Use allowConnection(Socket) instead.

See Also:
allowConnection(Socket)

run

public void run()
Listens for client requests until stopped. Call #start() to invoke this method, and shutdown() to break out of it.

Specified by:
run in interface java.lang.Runnable
Throws:
java.lang.RuntimeException - Generally caused by either an UnknownHostException or BindException with the vanilla web server.
See Also:
#start(), shutdown()

shutdown

public void shutdown()
Stop listening on the server port. Shutting down our listener effectively breaks it out of its run() loop.

See Also:
run()

getRunner

protected org.apache.xmlrpc.WebServer2.Runner getRunner()
Returns: