You could try this:
I found some code on:
http://www.webdeveloper.com/java/java_jj_read_write.html .
Combining that with a servlet, I was able to call a script that prints out the junk from the CGI environment (local Apache httpd w/ Perl).
Your idea sparked my interest and I can use it.
Here is the doGet() from my servlet CGIHandler.
Hope this helps.
-Randy
*************************************
public void doGet(
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException, java.io.IOException
{
boolean isValid = false;
//get theCgiUrl from Request URL or just set it to a static dest.
String theCgiUrl = "http://localhost/cgi-bin/printenv.pl";
String errorUrl = "http://127.0.0.1/"; //probably a local
JSP like cgiError.jsp or something
ServletContext ctx = getServletContext();
//do some authorization, I will just set to true
isValid = true;
URL myUrl = null;
if(isValid)
{
myUrl = new URL(theCgiUrl);
}
else // isValid == false <=> not authorized
{
myUrl = new URL(errorUrl);
}
//log which URK
ctx.log(this.getClass().getName() + " -> using URL: " + myUrl);
//capture the URL's ctxtent
URLConnection conn = myUrl.openConnection();
conn.connect();
ctx.log(this.getClass().getName() + " -> connected..." );
//now get the content into a buffer.
DataInputStream data = null;
String line;
String content = "";
StringBuffer buf = new StringBuffer();
data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
while ((line = data.readLine()) != null)
{
buf.append(line + "\n");
content += line;
}
data.close();
//print it out
PrintWriter out = response.getWriter();
out.print(content);
}//end doGet()