I have a jsp page running in a jboss 4.2.2 server. In the jsp im trying to print the headers of a http post request using methods like request.getMethod() and request.getHeaderNames(). Im sure that the request is a http post because im generating it from another program but what the jsp print is a http get request instead, the content-length printed is -1 and the headers printed doesnt match the headers im sending.
The code of the application that generate the request is, more or less, like this:
URL url = new URL(the_url);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-type", "application/timestamp-query");
con.setRequestProperty("Content-length", String.valueOf(data.length));
out = con.getOutputStream();
out.write(data);
out.flush();
The code of the application where im trying to print the request header is:
<%@page import="java.io.InputStream"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
import="java.util.Enumeration"
import="java.io.File"
import="java.io.FileOutputStream"
import="java.util.Date"%><%
File logfile = new File("/home/tsa/logfile");
FileOutputStream log_os = new FileOutputStream(logfile);
Enumeration header_names = request.getHeaderNames();
log_os.write(("cont-len: "+request.getContentLength()+"\r\n").getBytes());
log_os.write(("method: "+request.getMethod()+"\r\n").getBytes());
while (header_names.hasMoreElements()) {
String name = (String)header_names.nextElement();
log_os.write((name+": "+request.getHeader(name)+"\r\n").getBytes());
}
log_os.close();%>
HTTP data I should be receiving:
POST / HTTP/1.1
Content-type: application/timestamp-query
User-Agent: Java/1.7.0_05
Host: localhost:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 51
MDECAQEwITAJBgUrDgMCGgUABBSg8UkKINAhHJl7RLw1fhly3quK4wYGBACPZwEBAQH/
HTTP data I'm receiving:
User-Agent: Java/1.7.0_05
Host: 192.168.56.101:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
The method reported is GET and the Content-Length: -1
Thank you for your help.
I had the same issue. I updated to JDK 1.7.0_u21 and the problem went away.