Hi,
I am trying to run a servlet directly from an application (or an Applet if
you want). Nothing could be more simple I thought, but I always get a
FileNotFoundException. However it does seem to work whenever I try to use
this address in my webbroser (I get the proper output of the servlet), and
also it seems to work when I try to connect an outside server serving a
servlet. I found many pointers to this problem out on the web, but none with
a solution for it (there are even references on the Java Bug Parade).
If this does not work, then this could mean a serious problem for whoever
wants to make a B2B integration solution, as this is mostly the work he
needs to do.

// case 1:
URL url = new URL("http","127.0.0.1",80,"/asn/servlet/SnoopServlet");
// case 2:
// URL url = new
URL("http","www.somerealserveroutthere.com",80,"/asn/servlet/SnoopServlet");

HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setDoInput(true);
http.setDoOutput(true);
http.setUseCaches(false);
http.setRequestProperty("Content-Type", "text/plain");

PrintWriter writer = new PrintWriter(http.getOutputStream());
writer.println("Do Some Output");
writer.flush();
writer.close();

String inputLine;
// Gives FileNotFoundException (except case 2):
BufferedReader in = new BufferedReader(new
InputStreamReader(http.getInputStream()));
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();

//Also Would give FileNotFoundException if previous commented out:
int ret = http.getResponseCode();
if (ret != HttpURLConnection.HTTP_OK) {
System.err.println("Could Not Post ASN's");
}
http.disconnect();