|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--iglu.net.ClientHandler | +--iglu.net.WebHandler
Implements the ClientHandler needed for a proxy server. This object lets PortServer act as a proxy server for web connections. It does all the proxy work for you. To use this object, create a descendent class and override the doneWithNetworkAccess method. In that method, put the code to deal with what should be done for a url once it has been accessed. When used with PortServer, once instance of this class will be created for every url a browser tries to access. So if an html file is accessed by a browser that has five pictures on it, at least six instances of this class will be created for that page. If using this class with the PortServer, each instance of this class will run on its own thread.
Notice that most of the members of this class get their values during processClient. So they should be set properly by doneWithNetworkAccess.
See iglu.examples.ProxyServerExample for information on how to use this class to create a proxy server.
Note: This version of WebHandler will not allow you to daisy chain onto other proxy servers. But it would not be too hard to do. Just add a new constructor which takes a host and port number of the proxy and stores them in global members. Then modify process client to not worry about any parsing. Just pass all information on to the proxy and send all the other information back.
Field Summary | |
int |
ATTEMPTS
The number of times to try to connect to the web server |
int |
BUFFSIZE
|
java.lang.String |
clientCommands
unprocessed list of chars from the client's request |
java.lang.String |
Command
the command (GET, POST, etc) of the request |
static int |
defaultSize
|
java.lang.String |
doc
the page that was requested (without the server name) |
java.lang.String |
host
host name of the web server the request was for |
static int |
HTML
html request |
int |
port
port for the web server the request went to |
byte[] |
rawServerContent
unprocessed list of chars from server header |
java.lang.String |
requestedURL
the url that was requested |
java.lang.String |
serverContent
|
java.lang.String |
serverHeader
|
java.lang.String |
serverReply
|
static int |
UNKNOWN
Not known. |
int |
WAIT
The amount of time to pause between retries |
protected java.net.Socket |
webServer
a socket for connecting to the webserver |
protected java.io.InputStream |
wsin
for reading from the webServer pipe |
protected java.io.OutputStream |
wsout
for writing to the webServer pipe |
Fields inherited from class iglu.net.ClientHandler |
clientSocket, in, myServer, out |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
WebHandler(java.net.Socket client,
PortServer ms)
Initialize the variables for this class |
Method Summary | |
protected java.lang.String |
figureOutDestination()
|
static byte[] |
grow(byte[] array,
int size)
|
void |
internalDoneWithNetworkAccess()
Unzips the input stream if it is gzipped. |
static java.lang.String |
lookupValue(java.lang.String text,
java.lang.String key)
|
protected void |
performCom(java.lang.String firstLine)
|
void |
processClient()
Actually go out and get the document. |
int |
requestType()
try to figure out what kind of request was made. |
Methods inherited from class iglu.net.ClientHandler |
doneWithNetworkAccess, init, run |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.net.Socket webServer
protected java.io.InputStream wsin
protected java.io.OutputStream wsout
public java.lang.String clientCommands
public byte[] rawServerContent
public java.lang.String serverReply
public java.lang.String serverHeader
public java.lang.String serverContent
public static final int defaultSize
public java.lang.String host
public int port
public java.lang.String Command
public java.lang.String doc
public java.lang.String requestedURL
public int ATTEMPTS
public int WAIT
public int BUFFSIZE
public static final int UNKNOWN
public static final int HTML
Constructor Detail |
public WebHandler(java.net.Socket client, PortServer ms) throws java.io.IOException
client
- What socket the client is listening/talking on.ms
- The portserver creating this client. Included to allow
inter-client communication so it is easier to implement something like a
chat server.
java.io.IOException
- If it cannot establish the correct
communication.Method Detail |
public void processClient()
processClient
in class ClientHandler
protected java.lang.String figureOutDestination()
protected void performCom(java.lang.String firstLine)
public int requestType()
public void internalDoneWithNetworkAccess()
internalDoneWithNetworkAccess
in class ClientHandler
public static java.lang.String lookupValue(java.lang.String text, java.lang.String key)
public static byte[] grow(byte[] array, int size)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |