Wednesday, August 08, 2012

Catching HTTP 401/403 using Java SWT IE Browser

I've been working on a bit of Java code which needs to handle an HTTP proxy authentication failure, the code in question uses IE via the SWT browser and unfortunately I've discovered that you cannot chain onto the NavigateError event!

The event is handled inside IE.java (SWT source) but just does some specialised UNC handling without giving you the opportunity to do something useful (like catch the HTTP status code). As such I've had to restort to using an additional connection using HttpURLConnection and Authenticator.setDefault() / getPasswordAuthentication() - which is wasteful as I'm now having to make two connections to the webserver...

It's not even as if you can derive a new class from org.eclipse.swt.browser.IE because the required member variables have default visibility which means anything outside the org.eclipse.swt.browser package can't access them :(

1 comment:

BIG DOG said...

I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information. ucmini