Extending HttpURLConnection
Greetings,
I've been using HttpURLConnection to implement WebDAV on 1.3 and 1.4 JDK. I've now upgraded to 1.6 and am no longer able to cast from sun.net.www.protocol.http.HttpURLConnection to my extension.
My custom HttpURLConnection does extend the sun class and when I retrieve the HttpURLConnection from URL.openConnection, I receive a ClassCastException. Below is my code snippet:
mycustomclass.HttpURLConnection http = (mycustomclass.HttpURLConnection)url.openConnection();
http.setRequestProperty("Authorization","Basic " + auth.toString() );
http.setRequestProperty("Content-Type","text/xml" );
http.setDoOutput(true );
I've tested thaturl.openConnection(); does return a HttpURLConnection object, but the class cast exception is still thrown. The "Authorization" property is an encoded Base64 representation of my username and password.
I've been able to get around this by using the constructor in HttpURLConnection as below instead of casting from the openConnection:
mycustomclass.HttpURLConnection http =new mycustomclass.HttpURLConnection(url,"", 0);
However, now when I try to retrieve the output stream I recieve a java.net.ConnectionException:connect: Address is invalid on local machine, or port is not valid on remote machine.
The address is valid and the code works under 1.4JDK, but not on 1.6. I noticed that the HttpAuthenticator class is deprecated, which I've also extended. Any idea why this approach doesn't work on JDK 1.6?
Thanks,
Marcel

