here's another version that might actually compile without you needing
to fix bits.
I haven't tested this at all but it's correct as far as I know th CGI
spec.
If you get it working I'd appreciate you sending it back to me with
any bugs fixed.
Nic
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
/** a very rough and ready CGI servlet.
* You need to map this to <code>*.sh</code>.
*
* @author Nic Ferrier - [EMAIL PROTECTED]
*/
public class MyCGIServlet
extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse
response)
throws IOException,ServletException
{
Runtime rt=Runtime.getRuntime();
String[] env=new String[...];
env[0]="REQUEST_METHOD=GET";
//this is also used as the command location
env[1]="SCRIPT_NAME="+request.getRequestURI();
env[2]="QUERY_STRING="+request.getQueryString();
env[3]="CONTENT_TYPE="+request.getContentType();
env[4]="CONTENT_LENGTH="+request.getContentLength();
env[5]="REMOTE_ADDR="+request.getRemoteAddr();
env[6]="SERVER_SOFTWARE=Paperclips-CGIServlet";
env[7]="SERVER_PROTOCOL=HTTP/1.1";
Process cgiScript=rt.exec(env[1],env);
//obtain all the streams
InputStream in=request.getInputStream();
OutputStream out=response.getOutputStream();
InputStream cgiOutput=cgiScript.getInputStream();
OutputStream cgiInput=cgiScript.getOutputStream();
byte[] buf=new byte[5000];
//send the CGI script the input stream to the server
int red=-1;
if(in.avalable())
red=in.read(buf,0,5000);
while(red>-1)
{
cgiInput.write(buf,0,red);
red=-1;
if(in.available())
red=in.read(buf,0,5000);
}
cgiInput.flush();
//send the CGIs response back to the UA
red=cgiOutput.read(buf,0,5000);
while(red>-1)
{
out.write(buf,0,red);
red=cgiOutput.read(buf,0,5000);
}
out.close();
}
}
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html