This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How do I generate a org.apache.commons.httpclient.ProtocolException ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I generate a org.apache.commons.httpclient.ProtocolException ?" Watch "How do I generate a org.apache.commons.httpclient.ProtocolException ?" New topic
Author

How do I generate a org.apache.commons.httpclient.ProtocolException ?

Andrew Walmsley
Greenhorn

Joined: Jun 02, 2009
Posts: 2
Not sure where to put this query so...

Occasionally I'm getting a protocolException error returned, so I wrote a handler to catch it.
I'd like to test that it is being caught and handled correctly. So, I now have a perl script on an apache server that I'm trying to mangle to return something which will generate this error, but all I am managing to do is get a 500 Server Error, or is accepted as a valid return.
How do I generate html code to throw this exception for testing porpoises?

Any thoughts? I really don't want to release untested code.

Original Error
2009-05-25 16:17:50,341 ERROR [XXXX.web.servlet.controller.BookingController] org.apache.commons.httpclient.ProtocolException: Unable to parse header: 6

Script andrew.pl
#!/usr/local/bin/perl

use CGI;
use strict;

my $cgi = CGI->new;

print $cgi->header('text/bunnies'),
$cgi->start_html,
$cgi->p,
"Hello, World!",
$cgi->p,
$cgi->end_html;


perl -MNet::HTTP -e '$h = Net::HTTP->new(Host => "eric"); $h->write_request(HEAD => "/andrew.pl");($code, $mess, %headers) =$h->read_response_headers; printf("%s %s\n",$code,$mess);'
200 OK


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Welcome to JavaRanch

How aboutIs that exception checked or unchecked?
Andrew Walmsley
Greenhorn

Joined: Jun 02, 2009
Posts: 2
Campbell Ritchie wrote:Welcome to JavaRanch

How aboutIs that exception checked or unchecked?


Took 10 sips of coffee this mornign before I got what you meant ! (_whap self_)
replace the URL call with a throw exception statement so one is always thrown!

Should have thought of that myself, thanks.

This is why I was always a fan of pub programming, someone in the pub would always spot the obvious you missed before you went off on a complex tangenty and there were plently of beer made for code snippets.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Andrew Walmsley wrote: . . . plently of beer . . .
We need a Homer Simpson Aaaaaaaaah! smilie!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I generate a org.apache.commons.httpclient.ProtocolException ?