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]

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,
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