Page 1 of 1

Using default HttpURLConnection

Posted: Tue Aug 07, 2012 2:21 pm
by mandar.j
Hi,

It looks like Oxygen doesn't use default "sun.net.www.protocol.http.HttpURLConnection" for HttpURLConnection. I tried to create a connection using:

Code: Select all

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
It doesn't throws error with this but the same code does work through command-line.

I also tried

Code: Select all

sun.net.www.protocol.http.HttpURLConnection conn = (sun.net.www.protocol.http.HttpURLConnection) url.openConnection();
But it throws "can not cast" exception.

Is there any way to use default sun.net.www.protocol.http.HttpURLConnection in Oxygen Plugin?

Thanks,
Mandar

Re: Using default HttpURLConnection

Posted: Tue Aug 07, 2012 2:33 pm
by Radu
Hi Mandar,

Yes, Oxygen installs and uses its own implementation of java.net.HttpURLConnection based on the Apache HTTP Client open source libraries.
So creating an URL based on HTTP and opening a connection by calling its methods will return our custom connection.

In order to use a SUN HTTP connection from a plugin you could have some code like:

Code: Select all

    sun.net.www.protocol.http.HttpURLConnection conn = new sun.net.www.protocol.http.HttpURLConnection(url, null);
conn.connect();
conn.getInputStream();...
Regards,
Radu