• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to print out the content of the HttpServletRequest

 
Randy Paries
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
I am doing some debugging between MS LiveWriter and my implementation of apaches XmlRpcServlet

i need to print to the console for debugging the content of the HttpServletRequest


Enumeration headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()) {
String headerName = (String)headerNames.nextElement();
System.out.print(headerName+"-->");
System.out.println(request.getHeader(headerName));
}

the above displays this results
content-type-->text/xml
host-->192.168.10.50:8080
content-length-->442

what i can not figure out is how to display the content to the consle

thanks for any help


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out will emit its output wherever the container has pointed it to. For Tomcat, that's usually the catalina.out file in the logs folder.

Why aren't you using real logging?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Tomcat, you don't need to write this yourself.
Look for and uncoment "RequestDumperValve" in you tomcat/conf/server.xml file.

As Bear mentioned, the output usually goes to logs (which is better than having it go to the console).
If you're on a *nix system, you can use tail -f <filename> to follow the file as it's updated from your console.
For windows users there are programs like mTail that do the same thing.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Souther wrote:If you're using Tomcat, you don't need to write this yourself.
Look for and uncoment "RequestDumperValve" in you tomcat/conf/server.xml file.


This sent me off reading about RequestDumperValve and led me to find the following for tomcat 5.5:
http://tomcat.apache.org/tomcat-5.5-doc/config/valve.html

Note: this Valve is now deprecated in favor of the RequestDumperFilter, which does the same thing in a portable manner. This Filter is included in the examples application: see $CATALINA_HOME/webapps/examples/WEB-INF/classes/filters for the source.


not sure what this means by "portable manner" but I thought I'd note it here.

but from the tomcat 6 docs, it seems like RequestDumperValve has been rehabilitated?
http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html#Request%20Dumper%20Valve


 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "portable" I think they mean "works in all spec compliant containers". Valves are Tomcat specific.

Hopefully they will keep it around.
The advantage to a valve is that it is at the container level so can be run on any app (or all apps in the container), without touching the internals of the applications themselves.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic