help with java.lang.ClassCastException in JSSE

I need an urgent help.

i am writing code in JSSE for getting Server certificater(through SSL)

i wrote

public class url

{

public static void main(String[] args)

{

try

{

System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

Security.addProvider(new Provider());

URL url=new URL("https://localhost:8443");

HttpsURLConenction urlc=(HttpsURLConnection) url.openConnection();

}

catch(Exception e)

{

System.out.println(e);

}

}

}

when i am executing this programing, i am getting the following run time error

java.lang.ClassCastException

I think i am getting error for the following line of code

" HttpsURLConenction urlc=(HttpsURLConnection)url.openConnection(); "

Please help me out to overcome this run time error.

I would be grateful to you if you can solve my error

[955 byte] By [hard_timea] at [2007-10-1 19:54:58]
# 1

Hi,

A slight modification

I need your help. I am getting java.lang.ClassCastException when implementing httpsconnection.

Here is my code

try

{

System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

System.setProperty("java.protocol.handler.pkgs","javax.net.ssl");

//System.setProperty("java.protocol.handler.pkgs","sun.net.www.protocol");

//System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl");

//System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.HttpsURLConnection");

Security.addProvider(new Provider());

//System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl");

URL url=new URL("https://www.verisign.com/");

System.out.println("Connection is type: " + url.getClass().getName());

HttpsURLConnection urlc=(HttpsURLConnection)url.openConnection();

I tried all sorts of adding properties, but i am still getting this error.

I searched every where, but could not able to succeed.

I would appreciate if you can solve out my problem.

I dont know where i am going wrong

I am getting output as

Connection is type: java.net.URL

java.lang.ClassCastException

Thanks,

hard_timea at 2007-7-11 16:22:32 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 2
f you are using JDK 1.4 or later you don't need any of the properties and some of the values are wrong anyway for 1.4. Delete them all.
ejpa at 2007-7-11 16:22:32 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 3

I am receiving an internal servlet error which states:

ajp12:ServletError: java.lang.ClassCastException: com.sun.net.ssl.

This is a servlet that was written to retrieve data from an Oracle database and pass it to an outside secure site to receive an answer and enter it to the database. It was written by another developer who has left the company and when system was upgraded to Java1.5, it is receiving these errors. Please HELP!

Merchweba at 2007-7-11 16:22:32 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 4

Hi all

I have the same error:

java.lang.ClassCastException: com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl

MY CODE IS:

// Set the system and security properties

System.setProperty("javax.net.ssl.trustStore",

"C:\\certificados\\cacerts");

System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

// Keystore location and password

System.setProperty("javax.net.ssl.keyStore",

"C:\\certificados\\keystore");

System.setProperty("javax.net.ssl.keyStorePassword", "changeit");

//Set the request

String url_ = "https://195.235.160.165";

//Creamos la petici髇 html

StringBuffer buffer = new StringBuffer();

buffer.append(url_);

buffer.append("/GPP/WLServer?Method=M_FINDIT&CLIENT=");

buffer.append(client);

buffer.append("&CLI_PASSWD=");

buffer.append(cli_passwd);

buffer.append("&USER=");

buffer.append(user_login);

buffer.append("&USER_PASSWD=");

buffer.append(user_passwd);

buffer.append("&TUSERID=");

buffer.append(MSISDN);

buffer.append("&TUSERID_TYPE=MSISDN");

buffer.append("&GROUP=");

buffer.append(group_id);

buffer.append("&SRS=GPP:UTM28");

url_ = buffer.toString();

URL url = new URL(url_);

HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();

conn.setHostnameVerifier(new HostnameVerifier() {

public boolean verify(String hostname, SSLSession session)

{

// I don't care if the certificate doesn't match host name

return true;

}

});

BufferedReader in = new BufferedReader(

new InputStreamReader(

conn.getInputStream()));

//Creates a writer with the encoding parameter as "UTF-8"

Writer out_ = new OutputStreamWriter(response.getOutputStream(), "UTF-8" );

String inputLine;

String fichero_in = "";

while ((inputLine = in.readLine()) != null){

if(inputLine.length()!=0){

System.out.println(inputLine);

fichero_in = inputLine;

out_.write(inputLine);

}

}

in.close();

//Sets the Content-Type header

response.setContentType("application/xml; charset=utf-8");

//response.setContentType("text/html; charset=UTF-8");

//Sends the response XML to the client

out_.write(url_);

//out_.write(fichero_in);

out_.flush();

response.sendRedirect(response.encodeRedirectURL("out_"));

Anyone can hel me?

Thanks in advance

darngara at 2007-7-11 16:22:32 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 5
Hi,I am also getting the same ClassCastException while opening HttpsConnection .Did you get any solution for this.I will really appreciate your cooperation.Thanks.
Vachaspatia at 2007-7-11 16:22:32 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 6
The solution was posted fifteen months ago in reply #2. Make sure you don't have any references in your code to com.sun.*. All the classes and providers are built into the JDK starting from JDK 1.4.
ejpa at 2007-7-11 16:22:32 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 7
Thank You.
Vachaspatia at 2007-7-11 16:22:32 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 8
Thanks Man it worked
gk_sezhiana at 2007-7-11 16:22:32 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...