aspose file tools*
The moose likes Servlets and the fly likes how to print out the content of the HttpServletRequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to print out the content of the HttpServletRequest" Watch "how to print out the content of the HttpServletRequest" New topic
Author

how to print out the content of the HttpServletRequest

Randy Paries
Greenhorn

Joined: Dec 31, 2004
Posts: 4
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

Joined: Jan 10, 2002
Posts: 61662
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61662
    
  67

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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

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

Joined: Dec 11, 2004
Posts: 13410

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to print out the content of the HttpServletRequest