The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
May 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

cgi from Java - FileNotFound problems

Posted by Andrew Tringham on May 08, 2000 at 3:20 PM

I have an applet which calls a cgi (C++) program. Works fine when I test it on my own machine (Win 98, using MS Personal Web Server). Stick it on a real server (Unix or NT) on the net and most things work OK, but not the cgi. Can retrieve various files from the server, but when attempting to run the cgi, I get java.io.FileNotFoundException: www.vatlab.uk8.net:80//cgi-bin/pcroydon.exe. The file is there, with (I'm told!) sensible permissions.

In essence:

String AHost = new String("http://" +getCodeBase().getHost());
URL u = new URL(AHost + "/cgi-bin" + "/" + pcroydon.exe);
URLConnection urlc = u.openConnection();
urlc.setDoOutput(true);
urlc.setDoInput(true);
urlc.setAllowUserInteraction(false);
DataInputStream in = new DataInputStream(urlc.getInputStream());
DataOutputStream server = new DataOutputStream(urlc.getOutputStream());
server.writeBytes(query); // A string of data

All goes fine, until the next line:

try {
server.close();
}
catch (Exception e23) {
System.out.println("Server close failure " +e23.toString());
}

which produces

java.io.FileNotFoundException: www.vatlab.uk8.net:80//cgi-bin/pcroydon.exe

The port is (presumably) correct, but I don't get where the double slash comes from, as:

urlc.toString() produces:

com.ms.net.wininet.http.HttpURLConnection:http://www.vatlab.uk8.net/cgi-bin/pcroydon.exe

and urlc.getURL().toString() gives

http://www.vatlab.uk8.net/cgi-bin/pcroydon.exe

Help!! I'm completely stuck! Is it my Java or something odd on theserver, which isn't under my control.

Thanks for at least reading this far. This application is to do with a spiffy indirect (sales) tax system for Europe, so if I can't reciprocate with Java help, ask me a VAT question instead!

Andrew

Longer code:

Syst = new String("pcroydon.exe");
DataInputStream in = null;
String query = "submit=Submit";
// + some more removed from here

// Send the data using CGI's POST process:
URL u = null;
try {
u = new URL(AHost + "/cgi-bin" + "/" + Syst);
URLConnection urlc = u.openConnection();
urlc.setDoOutput(true);
urlc.setDoInput(true);
try {
urlc.setAllowUserInteraction(false);
announce("setAllowUserInteraction false");
}
catch (Exception eSUI) {
System.out.println("Set User Int failed"
+ eSUI.toString());
}
DataOutputStream server;
try {
server = new DataOutputStream(urlc.getOutputStream());
}
catch (Exception e3) {
announce("Exception e3: Connections failed");
System.out.println("e3.toString() + u.toString());
return;
}
// Send the data
try {
server.writeBytes(query);
announce("Sending the selections to the remote server ...");
}
catch (Exception e94) {
System.out.println("e94: "+e94.toString());
}
try {
server.close();
System.out.println("server Closed");
}
catch (Exception e23) {
System.out.println("Server close failure " +e23.toString());
}

InputStreamReader(urlc.getInputStream()));
System.out.println("Trying to open DataInputStream");
try {
in = new DataInputStream(urlc.getInputStream());
}
catch (Exception eIS) {
System.out.println("** InStream failure: "+eIS.toString());
System.out.println("** urlc: "+urlc.toString());
System.out.println("** urlc: "+urlc.getURL().toString());
System.out.println("Process stopped");
return;
}

// Rest cut

Exception e23 produces:

Server close failure java.io.FileNotFoundException: www.vatlab.uk8.net:80//cgi-bin/pcroydon.exe

Exception eIS:

** InStream failure: java.io.IOException
** urlc: com.ms.net.wininet.http.HttpURLConnection:http://www.vatlab.uk8.net/cgi-bin/pcroydon.exe
** urlc: http://www.vatlab.uk8.net/cgi-bin/pcroydon.exe
Process stopped





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us