CS 596: Client-Server Programming
| CGI and Java | slide # 1 |
| ...Problems with all CGI Programs | slide # 1 |
| ...Problems Using Java in CGI Programs | slide # 2 |
| ...Solutions to Java and CGI problems | slide # 3 |
| ......Strawman SimpleWrapper | slide # 4 |
| ...Problems with SimpleWrapper | slide # 7 |
| ......Solution 1 - Other Libraries | slide # 7 |
| ......Solution 2 - One Wrapper fits all | slide # 8 |
| ......Solution 3 System.properties | slide # 10 |
| ...The Final Wrapper | slide # 11 |
| ...A C Equivalent of Wrapper | slide # 12 |

2. Java programs are started with a two word command:
class HiMom
{
public static void main( String args[] ) throws Exception
{
System.out.print("Content-type: text/plain\n\n");
System.out.println("Hi Mom");
}
}
Result:
2. Can't use SDSU java library or other libraries not part of standard Java distribution
3. Each CGI program requires it's own modified SimpleWrapper program
The Shell program:
#!/bin/sh
betterWrapper:
#!/bin/sh
Goto cgi bin directory( in my case)
Now access the URL:
Properties is a subclass of Hashtable
Given the class Test below, the command line:
class Test
{
public static void main( String args[] ) throws Exception
{
String theName = System.getProperty( "name");
Properties systemStuff = System.getProperties();
System.out.print( theName );
System.out.println( systemStuff.get( "class" ) );
}
}
#!/bin/sh
# Java-Wrapper Version 1.1
# Copyright (C) 1996 by Marc Balmer, CH-4055 Basel, marc@msys.ch.
# This wrapper executes java binaries as CGI programs
# Modified by Roger Whitney, added suffix, DIR, Classpath, sorted and added some env variables
BASENAME="/usr/bin/basename"
DIRNAME="/usr/bin/dirname"
JAVA="/opt/java/bin"
CLASSPATH=".:/opt/java/classes:/usr/local/lib/java"
CGISUFFIX=".cgi"
CLASS=`$BASENAME $0 $CGISUFFIX`
DIR=`$DIRNAME $0`
cd $DIR
if [ -f $CLASS.class ] ; then
$JAVA -classpath $CLASSPATH \
-DAUTH_TYPE=$AUTH_TYPE \
-DCONTENT_LENGTH=$CONTENT_LENGTH \
-DCONTENT_TYPE=$CONTENT_TYPE \
-DDOCUMENT_ROOT=$DOCUMENT_ROOT \
-DGATEWAY_INTERFACE=$GATEWAY_INTERFACE \
-DHTTP_ACCEPT="$HTTP_ACCEPT" \
-DHTTP_CONNECTION=$HTTP_CONNECTION \
-DHTTP_HOST=$HTTP_HOST \
-DHTTP_USER_AGENT="$HTTP_USER_AGENT" \
-DPATH_INFO=$PATH_INFO \
-DPATH_TRANSLATED=$PATH_TRANSLATED \
-DQUERY_STRING=$QUERY_STRING \
-DREMOTE_ADDR=$REMOTE_ADDR \
-DREMOTE_HOST=$REMOTE_HOST \
-DREMOTE_IDENT=$REMOTE_IDENT \
-DREMOTE_USER=$REMOTE_USER \
-DREQUEST_METHOD=$REQUEST_METHOD \
-DSCRIPT_NAME=$SCRIPT_NAME \
-DSERVER_NAME=$SERVER_NAME \
-DSERVER_PORT=$SERVER_PORT \
-DSERVER_PROTOCOL=$SERVER_PROTOCOL \
-DSERVER_SOFTWARE=$SERVER_SOFTWARE \
$CLASS
else
echo Content-type: text/html
echo
echo \<head\>\<title\>Java-Wrapper Error\</title\>\</head\>
echo \<body\>
echo \<h1\>Java-Wrapper error\</h1\>
echo The requested java class file \<b\>$CLASS.class\</b\>
echo was not found on this server.
echo \</body\>
fihttp://www.eli.sdsu.edu/java-SDSU/examples/net/jcgi.c
jcgi.c is slightly more general. It will send all environment variables that starts with "HTTP_"
This difference is will not affect assignment 5.