org.iids.aos.systemservices.communicator
Class LSWebServer

java.lang.Object
  extended by org.iids.aos.systemservices.communicator.LSWebServer
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
XmlRpcLSWebServer

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

A modified version of the XML-RPC 2.0 WebServer. This version will deal with XML-RPC requests (HTTP-POST) as usual, but is also able to handle HTTP-GET requests.


Nested Class Summary
static class LSWebServer.HttpResult
           
static class LSWebServer.HttpResultType
          The result returned by httpMethod.
 
Field Summary
protected  java.util.Vector<org.iids.aos.systemservices.communicator.LSWebServer.AddressMatcher> accept
           
protected static byte[] clength
           
protected static byte[] conclose
           
protected static byte[] conkeep
           
protected static byte[] csstype
           
protected static byte[] ctype
           
protected  java.util.Vector<org.iids.aos.systemservices.communicator.LSWebServer.AddressMatcher> deny
           
protected static byte[] doubleNewline
           
protected static byte[] giftype
           
protected static byte[] htype
           
protected static byte[] jstype
           
protected  java.lang.Thread listener
           
protected static byte[] newline
           
protected static byte[] ok
           
protected static byte[] ptype
           
protected  java.lang.ThreadGroup runners
           
protected static byte[] server
           
protected  java.net.ServerSocket serverSocket
           
protected static byte[] wwwAuthenticate
           
protected  org.apache.xmlrpc.XmlRpcServer xmlrpc
           
 
Constructor Summary
LSWebServer(int port)
          Creates a web server at the specified port number.
LSWebServer(int port, java.net.InetAddress addr)
          Creates a web server at the specified port number and IP address.
LSWebServer(int port, java.net.InetAddress addr, org.apache.xmlrpc.XmlRpcServer xmlrpc)
          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.
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.
protected  java.net.ServerSocket createServerSocket(int port, int backlog, java.net.InetAddress addr)
          Factory method to manufacture the server socket.
 void denyClient(java.lang.String address)
          Add an IP address to the list of denied clients.
protected static int determinePort(java.lang.String[] argv, int defaultPort)
          Examines command line arguments from argv.
protected  org.iids.aos.systemservices.communicator.LSWebServer.Runner getRunner()
           
static void main(java.lang.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(java.lang.String name)
          Remove a handler object that was previously registered with this server.
 void run()
          Listens for client requests until stopped.
 void setHttpMethod(java.lang.Object o, java.lang.reflect.Method m)
           
 void setParanoid(boolean p)
          Switch client filtering on/off.
 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(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 java.net.ServerSocket serverSocket

listener

protected java.lang.Thread listener

accept

protected java.util.Vector<org.iids.aos.systemservices.communicator.LSWebServer.AddressMatcher> accept

deny

protected java.util.Vector<org.iids.aos.systemservices.communicator.LSWebServer.AddressMatcher> deny

runners

protected java.lang.ThreadGroup runners

ctype

protected static final byte[] ctype

htype

protected static final byte[] htype

ptype

protected static final byte[] ptype

csstype

protected static final byte[] csstype

jstype

protected static final byte[] jstype

giftype

protected static final byte[] giftype

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
Constructor Detail

LSWebServer

public LSWebServer(int port)
Creates a web server at the specified port number.


LSWebServer

public LSWebServer(int port,
                   java.net.InetAddress addr)
Creates a web server at the specified port number and IP address.


LSWebServer

public LSWebServer(int port,
                   java.net.InetAddress addr,
                   org.apache.xmlrpc.XmlRpcServer xmlrpc)
Creates a web server at the specified port number and IP address.

Method Detail

main

public static void main(java.lang.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:

See Also:
addDefaultHandlers()

determinePort

protected static int determinePort(java.lang.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.

Parameters:
defaultPort - The port to use if none was specified.

toHTTPBytes

protected static final 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).


createServerSocket

protected java.net.ServerSocket createServerSocket(int port,
                                                   int backlog,
                                                   java.net.InetAddress addr)
                                            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).

Parameters:
port -
backlog -
addr - If null, binds to INADDR_ANY, meaning that all network interfaces on a multi-homed host will be listening.
Throws:
java.lang.Exception - Error creating listener socket.

start

public void start()
Spawns a new thread which binds this server to the port it's configured to accept connections on.

See Also:
run()

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.iids.aos.systemservices.communicator.LSWebServer.Runner getRunner()

setHttpMethod

public void setHttpMethod(java.lang.Object o,
                          java.lang.reflect.Method m)


Copyright © 2003, 2004 IIDS Group. All Rights Reserved.