Title: Web Proxy Server
1Web Proxy Server
2Proxy Server Introduction
- Returns status and error messages.
- Handles http CGI requests.
- For more information about CGI please refer to
NCSA's CGI tutorial at http//hoohoo.ncsa.uiuc.edu
/cgi/. - Determines the Class to run Dynamically no code
change is needed. - Decodes the encoded parameter list.
- Is multi-threaded.
3The Apps Class
- You can retrieve the source for the abstract Apps
class on cochise at http//cochise.cs.washington.e
du/maxwell/proxy/Apps.java. - The server calls setSocket for the application
passing it the socket of the connection. - This function opens a BufferedReader and a
PrintWriter. - These functions are convenient for sending
strings back and forth. - You can still gain access to the socket and open
your own readers and writers. - The parameter list.
- Inherits from Thread.
4Creating your own Application
- Extend your class from class Apps. Implement a
procedure public void run(). - This is the function, which gets called to start
the thread. - Send a content type back down the output stream.
- Send all your information.
- Close the output stream.
5Wrapper Class
- If you want to write your application in
something other the Java you will need to create
a Java wrapper class. - First create a class that extends Apps and create
a function public void run(). In this function
you need to do the following. - String arg new String numArgs 1
- arg0 "ProgramName"
- arg1 argument1
- argnumArgs null
- Runtime r Runtime.getRuntime()
- Process p r.exec(arg)
- Buffered Reader pIn new BufferedReader(new
InputStreamReader(p.getInputStream())) - PrintWriter pOut new PrintWriter(p.getOutputStre
am()) - pOut.println(parm)
- String in
- while((in pIn.readln()))
- dOut in
6Schedule ClientÂ
7Web
8Web
9PC GUI
- The control of the GUI works as follows.
- The first screen that is displayed is the login
screen. - The user will login and the information is sent
to the Controller to be processed. - Once the login is verified, the splash screen is
displayed while information needed by the
schedule GUI is received from the server. - Finally, the Main GUI is displayed.
- The Main GUI enables the user to look at events
from a year, month, or day perspective. - If the user wants to add an event, they will
enter it in the space provided. - That information is sent to the Main GUI.
- The Main GUI sends it on to the Controller.
- The Controller sends it to the server.
10Data Processing
- The Network Control is running in a separate
thread than the Controller. - When processing the user login, the information
is bundled up into a SendEvent and passed on to
the Network Control. - The Network Control sends the event to the Encode
class to be encoded into a URL string. - The the Network Control sends this string to the
Send class to be sent to the server. - The Server information is stored in a class
called ProxyInfo.class. If the server information
changed, the class can be removed and replaced
with the correct information. - When the information is sent, it opens a URL
connection. - This sends back the content, which is a Buffered
Input Stream. - The stream is passed by the Network Control to
the Receive Class. - The Receive classes parses each line of
information, sends it to the Decode class to be
parsed further and sent to the Network Control. - The Network Control packages it up into a
ReceiveEvent and sends it to the Controller to be
processed and sent to the GUI.
11package schedule import java.lang. import
java.io. import java.net. import
java.util. public class NetworkThread extends
Thread implements SendListener private
SendEvent evt private Vector listeners private
boolean readyToSend false public
NetworkThread() super()
listeners new Vector()
public void processSend(SendEvent evt)
// System.out.println("Getting to network
send...") if (!isAlive()) this.start()
if(!readyToSend)
this.evt evt readyToSend true
12public void addReceiveListener(ReceiveListener
sl) listeners.addElement(sl) public
void removeReceiveListener(ReceiveListener sl)
listeners.removeElement(sl) private void
notifyListeners(ReceiveEvent re) for (int
i0 i lt listeners.size() i)
((ReceiveListener)listeners.elementAt(i)).processR
eceive(re) public void run()
ReceiveEvent rEvent
while (true)
if(!readyToSend) try
sleep(10) catch
(InterruptedException e)
13else String
encodedString Encode encode
new Encode() encodedString
encode.encodeString(evt) Send
sender new Send() Object
openStream sender.OpenStream(encodedString)
if (openStream null )
System.out.println("Server
Down.....") readyToSend
false notifyListeners(null)
continue
Receive receiver new
Receive(openStream) String s
null Decode decoder new
Decode() while
((s receiver.readLine()) ! null)
decoder.decodeNextLine(s)
rEvent
decoder.getReceiveEvent()
notifyListeners(rEvent)
readyToSend false
14package schedule import java.net. public
class Encode public String
encodeString(SendEvent e) String
CGI String encoded CGI ""
e.getApplicationName() "?username"
e.getUserName() "password"
e.getPassWord() "command" e.getCommand()
"" e.getInfo()
System.out.println("Encoding string " CGI)
encoded URLEncoder.encode(CGI)
return encoded
15(No Transcript)
16JDBC Function Calls
- Loading the Driver
- twz1.jdbc.mysql.jdbcMysqlDriver
- Getting parameters
- jdbcMysqlBase.getDefaultNames()
- .jdbcMysql.properties file
- Connecting
- DriverManager.getConnection(url)
- Connection Handle
- setCatalog()
- Queries
- execute
- Result Sets