I had been fighting with some silly old-fashioned servlet code. No need to say, I was not getting the upper hand. Never having been a web developer, I was baffled with why my POST request never got the contents I expected it to.
The following line running on Cygwin bash was my “testing” tool:
$ cat contents | lwp-request -m POST -P http://devhost/app/post_servlet?p1=arg1&p2=arg2
After a while, I found HttpServletRequest.getParameterMap() as handy to see what was entering the doPost() method and tried to look at its return:
{p1=[Ljava.lang.String;@90a11e, From: me
To: you
BODY=[Ljava.lang.String;@141d281}
What is that? Ain’t that beautiful array and map stringification? I refused to write yet another piece of code to see what was inside. I reached for Jyaml and then used
Yaml.dump(request.getParameterMap()) to dump the request parameters, which brought me this:
--- !org.apache.catalina.util.ParameterMap p1: !java.lang.String[] - arg1 "From: me\nTo: you\n\nBODY": !java.lang.String[] - ""
How wonderful! The error was not quoting the URL preventing bash to interpret '&' as a special and not declaring explicitly the content-type of the request. The parsing of parameters went beyond the (truncated) query string to the post contents, eating my stream.
YAML is very useful for debugging and I got used to it when programming Perl. And now I can take this habit to Java as well.
Thanks, Toby Ho (airportyh) for Jyaml!
P.S. Of course there should be better ways to debug this, more specific techniques which don’t apply everywhere as YAML does. Not quoting was a bug with the “testing” tool but the content-type declaration was the bug I was looking for. It saved me time. Well, I don’t like debuggers either.


Why don't you use a debugger and set breakpoints and just look at the variable in your handy-dandy debugger tool?
@Bill: debuggers bug me. A good dumping library can give you an instant feeling of the contents of a deep data structure with very few technology around you (like debuggers and fancy IDEs). They also work in a live application if you set logging mechanisms together with dumping facilities. As a personal issue, I am easily distracted and will probably miss the important bits a few times when running a debugger. (So I am not very productive with them.) That is not an issue if I have a record of things that were dumped and that you could review.