D
David G
Hello, I have run across a really weird situation with the
HttpURLConnection. I always seem to get the following error when connecting
(via HttpURLConnection) to a lunux tomcat servlet engine:
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://venus/david/utils/formTester.jsp?url=testurl&
However, when I make a connection to the exact same page on a windows tomcat
it works.
This is what I'm seeing. When ever I request a static page from tomcat (on
linux), it works fine, but if I request a jsp it breaks with the 500 error
above.
For example:
venus is a linux server and davidlg is my development windows 2000
pt.doGet("http://venus/index.html"); // returns the html page
pt.doGet("http://venus:8080/david/utils/password.jsp"); // returns error
500
pt.doGet("http://venus:8080/david/utils/formTester.jsp?url=testurl"); //
returns error 500
pt.doGet("http://davidlg:8084/index.html"); // returns html
pt.doGet("http://davidlg:8084/apps/utils/password.jsp"); // returns
generated web page (simple page that looks for cgi parm and prints it)
pt.doGet("http://davidlg:8084/apps/utils/formTester.jsp?url=testurl");//
returns generated web page (another simple page that prints a form with a
cgi parm in it)
Anybody have any ideas? This is driving me nuts...
Here is my code that makes the connection:
public String doGet(String urlString, Hashtable parms)
throws ProtocolException, IOException, UnsupportedEncodingException {
String name;
String value;
// make sure there is a ? between the page and parms.
Enumeration e = parms.keys();
if (urlString.indexOf("?") < 0) {
urlString += "?";
} else if (urlString.indexOf("?") != urlString.length() - 1) {
urlString += "&";
}
boolean useDepracated = false;
log("java.version:" + System.getProperty("java.version"));
useDepracated =
(System.getProperty("java.version").indexOf("1.2")) == 0;
if (useDepracated) {
log(
"Found earlier version of java (1.2.2), using the"
+ " depricated version of url encode:");
}
while (e.hasMoreElements()) {
name = (String)e.nextElement();
value = (String)parms.get(name);
// encode the value:
if (useDepracated) {
value = URLEncoder.encode(value);
} else {
value = URLEncoder.encode(value, "UTF-8");
}
urlString += name + "=" + value + "&";
log(name + "=" + value + "&");
}
log("Sending the following to " + urlString);
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
PrintWriter out = new PrintWriter(conn.getOutputStream());
out.println();
out.flush();
out.close();
// read the response:
//conn.connect();
conn.getResponseMessage(); // OK, Forbidden, etc
conn.getResponseCode(); // 200, 404, etc
// this is where it throws the 500 error.
BufferedReader in =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer response = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
log(line);
response.append(line);
}
in.close();
return response.toString();
}
Thanks for any suggestions you have to offer.
-David
HttpURLConnection. I always seem to get the following error when connecting
(via HttpURLConnection) to a lunux tomcat servlet engine:
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://venus/david/utils/formTester.jsp?url=testurl&
However, when I make a connection to the exact same page on a windows tomcat
it works.
This is what I'm seeing. When ever I request a static page from tomcat (on
linux), it works fine, but if I request a jsp it breaks with the 500 error
above.
For example:
venus is a linux server and davidlg is my development windows 2000
pt.doGet("http://venus/index.html"); // returns the html page
pt.doGet("http://venus:8080/david/utils/password.jsp"); // returns error
500
pt.doGet("http://venus:8080/david/utils/formTester.jsp?url=testurl"); //
returns error 500
pt.doGet("http://davidlg:8084/index.html"); // returns html
pt.doGet("http://davidlg:8084/apps/utils/password.jsp"); // returns
generated web page (simple page that looks for cgi parm and prints it)
pt.doGet("http://davidlg:8084/apps/utils/formTester.jsp?url=testurl");//
returns generated web page (another simple page that prints a form with a
cgi parm in it)
Anybody have any ideas? This is driving me nuts...
Here is my code that makes the connection:
public String doGet(String urlString, Hashtable parms)
throws ProtocolException, IOException, UnsupportedEncodingException {
String name;
String value;
// make sure there is a ? between the page and parms.
Enumeration e = parms.keys();
if (urlString.indexOf("?") < 0) {
urlString += "?";
} else if (urlString.indexOf("?") != urlString.length() - 1) {
urlString += "&";
}
boolean useDepracated = false;
log("java.version:" + System.getProperty("java.version"));
useDepracated =
(System.getProperty("java.version").indexOf("1.2")) == 0;
if (useDepracated) {
log(
"Found earlier version of java (1.2.2), using the"
+ " depricated version of url encode:");
}
while (e.hasMoreElements()) {
name = (String)e.nextElement();
value = (String)parms.get(name);
// encode the value:
if (useDepracated) {
value = URLEncoder.encode(value);
} else {
value = URLEncoder.encode(value, "UTF-8");
}
urlString += name + "=" + value + "&";
log(name + "=" + value + "&");
}
log("Sending the following to " + urlString);
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
PrintWriter out = new PrintWriter(conn.getOutputStream());
out.println();
out.flush();
out.close();
// read the response:
//conn.connect();
conn.getResponseMessage(); // OK, Forbidden, etc
conn.getResponseCode(); // 200, 404, etc
// this is where it throws the 500 error.
BufferedReader in =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer response = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
log(line);
response.append(line);
}
in.close();
return response.toString();
}
Thanks for any suggestions you have to offer.
-David