ClassCastException in HttpsURLConnection

I try to connect to https://verisign.com using HttpsURLConnection..and i get :
Exception in thread "main" java.lang.ClassCastException: com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl
     at URLReader.main(URLReader.java:22)
code:
     java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
     System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
     System.setProperty("javax.net.ssl.trustStore","/home/httpd/servlets/cacerts");
URL verisign = new URL("https://www.verisign.com/");
HttpsURLConnection cx =(HttpsURLConnection)verisign.openConnection();
     BufferedReader in = new BufferedReader(
     new InputStreamReader(verisign.openStream()));
     String inputLine;
     while ((inputLine = in.readLine()) != null)
     System.out.println(inputLine);
     in.close();
Is this problem connected with wrong certificate?
But why is it a CastException?
Please help thanks.

Had this one.
You probably use the new class:
javax.net.ssl.HttpsURLConnection and verisign uses
older com.sun.net.ssl.HttpsURLConnection.

Similar Messages

  • ClassCastException using HttpsURLConnection with Tomcat 4.1.27

    Hi,
    I try to open an SSL connection using HttpsURLConnection that works fine with a standalone application (see code fragment):
    import javax.net.ssl.HttpsURLConnection;
    import java.net.*;
    import java.io.*;
    URL website = new URL( "https://aSampleSSLSite" );
    HttpsURLConnection connection = ( HttpsURLConnection ) website.openConnection();
    Using the same code in Tomcat 4.1.27 and Struts 1.1 throws a java.lang.ClassCastException while trying to use website.openConnection().
    What is the difference?

    Hi,
    I'm using JDK 1.4.2 and haven't installed JSSE separately at all. Actually I really use javax.net.ssl.HttpsURLConnection. However, I tried com.sun.net.ssl.HttpsURLConnection as well and got a 'java.net.SocketException: Default SSL context init failed' instead of.
    Oddly enough the code works fine in a standalone application.

  • HttpsURLConnection gives ClassCastException in Weblogic 5.1

    am getting an error when i run my application in weblogic 5.1 as
    java.lang.ClassCastException: weblogic.net.http.HttpsURLConnection.
    I know the reason after creating URLConneciton the object i am getting
    is "weblogic.net.http.HttpsURLConnection" instead of com.sun.net.ssl.HttpsURLConnection
    But if I run this application outside weblogic environment my application is running fine.
    How do I make the weblogic server to pick com.sun.net.ssl.HttpsURLConnection instead of weblogic.net.http.HttpsURLConnection.
    Thanks in advance
    Arshad

    Are you casting the object to com.sun.net.ssl.HttpsURLConnection?
    Why not just use javax.net.HttpsURLConnection? I have never worked with
    WebLogic before, but I'm sure it will extend that class.

  • ClassCastException - HttpsURLConnection

    I am getting the following error:
    java.lang.ClassCastException: com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection
    Does anybody have a solution to this? I am developing in WSAD 5.
    if (protocol.equalsIgnoreCase("https"))
      //use Sun's JSSE to deal with SSL
      //java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
      System.out.println("1");
      System.setProperty( "java.protocol.handler.pkgs","com.ibm.net.ssl.internal.www.protocol");
      System.out.println("2");
      java.security.Security.addProvider(new com.ibm.jsse.IBMJSSEProvider());
      //System.getProperties().put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
      //System.getProperties().put("java.protocol.handler.pkgs", "com.ibm.net.ssl.internal.www.protocol");
      System.out.println("3");
      url = new URL(protocol + "://" + hostname + "/" + prefix + "/" + service);
      System.out.println("4");
      connection = (HttpsURLConnection) url.openConnection();  //this is where the error is occuring
      System.out.println("5");
    else     
      url = new URL(protocol + "://" + hostname + "/" + prefix + "/" + service);
      connection = (HttpURLConnection) url.openConnection();
    }

    Okay, maybe I have t reversed :P There are two HttpsURLConnections, one in javax.net the other one you are using. If you have imported one or both, you will have to qualify which you mean:
    connection = (com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection) url.openConnection();And make sure connection is instantiated as:
    com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection as well.

  • HTTPS ClassCastException for SOAPHttpsURLConnection to HttpsURLConnection

    JDEV 11gR1PS1
    Hi all,
    I'm writing a Java class that posts via HTTPS. I'm getting the the following error when executing the class:
    java.lang.ClassCastException: weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
    using the following code (just a snip of what's relevant:
                url = new URL(nurl);
                connection = (HttpsURLConnection)url.openConnection();
                responseCode = connection.getResponseCode();I've also tried based on some research on the web
                url = new URL(null, nurl, new com.sun.net.ssl.internal.www.protocol.https.Handler());
                connection = (HttpsURLConnection)url.openConnection();
                responseCode = connection.getResponseCode();and instead I this error
    java.lang.ClassCastException: com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl cannot be cast to javax.net.ssl.HttpsURLConnection
    Ideas?

    Import this instead
    import weblogic.net.http.SOAPHttpsURLConnection;
    and then when attempting the connection try using the SOAPHttpsURLConnection object

  • ClassCastException while instantiate HttpsURLConnection

    When I try to instantiate an HttpsURLConnection from an URL instance called "Server,"
    HttpsURLConnection conn =(HttpsURLConnection) server.openConnection();I got the following exception:
    java.lang.ClassCastException: sun.net.www.protocol.http.HttpURLConnection incompatible with javax.net.ssl.HttpsURLConnection
    May I know if there is anyway to solve it? I have to use HttpsURLConnection.
    Thank you!

    Hi,
    you did not provide your import statements contained in the class. Please check which class named HttpsURLConnection you are trying to import.
    Maybe your import refers to sun.net.www.protocol.http..., which is imcompatible with the one in javax.net.ssl....
    Bye.

  • ClassCastException in Tomcat 4.1. Pointing to old HttpsURLConnection

    Hi There
    My servlet casts ClassCastException when I try to craete HttpsURLConnection instance from URL.openConnection(). Here are the facts.
    OS = Linux RH 8.0
    JDK Version = 1.4.2
    Tomcat Version = 4.1
    $JAVA_HOME is set to the JDK 1.4.2
    Here's the code:
    URL u = new URL("https://url/to/the/site");
    javax.net.ssl.HttpsURLConnection connection = (javax.net.ssl.HttpsURLConnection)u.openConnection();
    This causes ClassCastException.
    Then I found out that the URL.openConnection() is acutually returning an instance of com.sun.net.ssl.HttpsURLConnection. And this is what is causing this problem.
    So my qustion is how I can point Tomcat to use javax.net.ssl.HttpsURLConnection instead of old com.sun.net.ssl.HttpsURLConnection.
    JAVA_HOME is set to the newest version of JDK (1.4.2) and I don't know whereelse Tomcat looks for files... Do I have to change the conf files?
    I would greatly appreciate your help.
    Michi

    hello Michi,
    I am assuming that you are using the TOMCAT that comes with Java Web Services Developer's pack from java.sun.com. First DownLoad and install the JDK in question (the one that you want catalina to use). Then set the value of JAVA_HOME in the catalina.sh file in the <CATALINA_HOME>/bin folder. Just tinker with it for sometime, trying to set the JAVA_HOME variable. This should be enough to change your java.home to the new JDK.
    IF that does not work, then you may have to change the system 'path' variable as well. That should do it.
    First try out the first one. Try the second one only if the first one does not work.
    all the best,
    Pawan

  • Problem with HttpsURLConnection - classcastexception

    i declared url connection from java.net pakage thru weblogic server
    when i am trying to execute following servlet
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.net.URL;
    public class SimpleServlet extends HttpServlet
    public void doGet (HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException
    java.net.URL url = new java.net.URL("http:\\www.mail.yahoo.com");
    System.out.println("url class name is -->"+ url.getClass().getName());
    java.net.URLConnection urlc = url.openConnection();
    System.out.println("urlc class name is "+urlc.getClass().getName());
    // System.out.println("url open connection class name is -->"+ url.openConnection().getClass().getName());
    // System.out.println("SimpleServlet 1 ->com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection");
    com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection urlcon = (com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection) url.openConnection();
    System.out.println("class name is .."+urlcon.getClass().getName());
    the out put is showling weblogic class. it should not be, how to set property pkgs.handlers in weblogic
    thanks in advance
    Bala
    [email protected]

    Why didn't you call ResultSet.getDouble(columnIndex) or Resultset.getFloat(columnIndex) in the first place, rather than whatever you did? Then the database driver would have handled the data translation for you instead of making you do all that nasty casting.

  • Exception: java.lang.ClassCastException: HTTPClient.HttpURLConnection

    Hi All,
    I am getting below exception when I am trying to establish HTTPS connection using
    Exception: java.lang.ClassCastException: HTTPClient.HttpURLConnection
    sometime my code works and some time it gives me this exception
    below is the exception which i traced in a log file
    2008/09/11 01:07:57->1_1210001776_0:1_1210001776_0URL CONNECTION CALLED https://netfundstest.com/fsu/router
    2008/09/11 01:07:57->1_1210001776_0:1_1210001776_0URL CONNECTION Created HTTPClient.HttpURLConnection[https://netfundstest.com/fsu/router]
    2008/09/11 01:07:57->1_1210001776_0:entered into else Block
    2008/09/11 01:07:57->1_1210001776_0:1_1210001776_0Error URLC Not a instance of HTTPS Connection: HTTPClient.HttpURLConnection[https://netfundstest.com/fsu/router]
    2008/09/11 01:07:57->1_1210001776_0:Exception: java.lang.ClassCastException: HTTPClient.HttpURLConnection
    In the success case when my HTTPS connection gets established I am getting following in the log file.
    2008/08/24 11:51:28->1_1210001776_0:1_1210001776_0URL CONNECTION CALLED https://netfunds.com/fsu/router
    2008/08/24 11:51:28->1_1210001776_0:1_1210001776_0URL CONNECTION Created com.sun.net.ssl.internal.www.protocol.https.DelegateHttpsURLConnection:https://netfunds.com/fsu/router
    Here is the code which I am using
    I am importing following packages in my code
    import java.security.*;
    import java.security.cert.*;
    //import javax.net.ssl.*;
    import javax.net.ssl.SSLSocket;
    import javax.net.ssl.SSLSocketFactory;
    import javax.net.ssl.HandshakeCompletedListener;
    import javax.net.ssl.HandshakeCompletedEvent;
    import javax.net.ssl.SSLSession;
    import java.net.*;
    import java.util.*;
    import java.io.*;
    //import javax.security.cert.*;
    import com.sun.net.ssl.*;
    //import org.apache.xalan.*;
    //import org.apache.xerces.*;
    import org.apache.xerces.dom.*;
    import org.apache.xml.serialize.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import oracle.xml.classgen.*;
    try
    System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    System.setProperty("https.proxyHost",geProxy);
    System.setProperty("https.proxyPort",geProxyPort);
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    int n=0;
    while(n<3)
    debugMsg(instCount+"URL CONNECTION CALLED " + fsuFrontEndURL);
    url = new URL(fsuFrontEndURL);
    /* Changed to include Tunnel code */
    urlc = url.openConnection();
    debugMsg(instCount+"URL CONNECTION Created " + urlc);
    if (urlc instanceof com.sun.net.ssl.HttpsURLConnection)
    debugMsg("entered into If Block");
    debugMsg("Value of n:" + n);
    ((com.sun.net.ssl.HttpsURLConnection) urlc).setSSLSocketFactory(new SSLTunnelSocketFactory(geProxy, geProxyPort));
    ((com.sun.net.ssl.HttpsURLConnection) urlc).setRequestMethod("POST");
    debugMsg("after If Block");
    break;
    else {
    try{
    debugMsg("entered into else Block");
    ((javax.net.ssl.HttpsURLConnection) urlc).setSSLSocketFactory(new SSLTunnelSocketFactory(geProxy, geProxyPort));
    ((javax.net.ssl.HttpsURLConnection) urlc).setRequestMethod("POST");
    debugMsg("after else Block");
    break;
    catch(Exception e) {
    debugMsg(instCount+"Error URLC Not a instance of HTTPS Connection: " + urlc);
    debugMsg("Exception: " + e);
    I am using JDK 1.5 and Apache/1.3.19
    Can anyone help me out ....?

    for URL'S Starting with HTTPS only.....Sometimes it works and sometimes it gives me the classcast exception
    As soon as I bounces my Apache application server...then it starts working...I dont know why its happening like that..
    Is there any issue with the Ports I am trying to connect or some Apache configuration files settings are getting changed ?

  • Getting java.lang.ClassCastException

    Hi All,
    I am getting below exception when I am trying to establish HTTPS connection using
    Exception: java.lang.ClassCastException: HTTPClient.HttpURLConnection
    sometime my code works and some time it gives me this exception
    below is the exception which i traced in a log file
    2008/09/11 01:07:57->1_1210001776_0:1_1210001776_0URL CONNECTION CALLED https://netfundstest.com/fsu/router
    2008/09/11 01:07:57->1_1210001776_0:1_1210001776_0URL CONNECTION Created HTTPClient.HttpURLConnection[https://netfundstest.com/fsu/router]
    2008/09/11 01:07:57->1_1210001776_0:entered into else Block
    2008/09/11 01:07:57->1_1210001776_0:1_1210001776_0Error URLC Not a instance of HTTPS Connection: HTTPClient.HttpURLConnection[https://netfundstest.com/fsu/router]
    2008/09/11 01:07:57->1_1210001776_0:Exception: java.lang.ClassCastException: HTTPClient.HttpURLConnection
    In the success case when my HTTPS connection gets established I am getting following in the log file.
    2008/08/24 11:51:28->1_1210001776_0:1_1210001776_0URL CONNECTION CALLED https://netfunds.com/fsu/router
    2008/08/24 11:51:28->1_1210001776_0:1_1210001776_0URL CONNECTION Created com.sun.net.ssl.internal.www.protocol.https.DelegateHttpsURLConnection:https://netfunds.com/fsu/router
    Here is the code which I am using
    I am importing following packages in my code
    import java.security.*;
    import java.security.cert.*;
    //import javax.net.ssl.*;
    import javax.net.ssl.SSLSocket;
    import javax.net.ssl.SSLSocketFactory;
    import javax.net.ssl.HandshakeCompletedListener;
    import javax.net.ssl.HandshakeCompletedEvent;
    import javax.net.ssl.SSLSession;
    import java.net.*;
    import java.util.*;
    import java.io.*;
    //import javax.security.cert.*;
    import com.sun.net.ssl.*;
    //import org.apache.xalan.*;
    //import org.apache.xerces.*;
    import org.apache.xerces.dom.*;
    import org.apache.xml.serialize.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import oracle.xml.classgen.*;
    try
    System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    System.setProperty("https.proxyHost",geProxy);
    System.setProperty("https.proxyPort",geProxyPort);
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    int n=0;
    while(n<3)
    debugMsg(instCount+"URL CONNECTION CALLED " + fsuFrontEndURL);
    url = new URL(fsuFrontEndURL);
    /* Changed to include Tunnel code */
    urlc = url.openConnection();
    debugMsg(instCount+"URL CONNECTION Created " + urlc);
    if (urlc instanceof com.sun.net.ssl.HttpsURLConnection)
    debugMsg("entered into If Block");
    debugMsg("Value of n:" + n);
    ((com.sun.net.ssl.HttpsURLConnection) urlc).setSSLSocketFactory(new SSLTunnelSocketFactory(geProxy, geProxyPort));
    ((com.sun.net.ssl.HttpsURLConnection) urlc).setRequestMethod("POST");
    debugMsg("after If Block");
    break;
    else {
    try{
    debugMsg("entered into else Block");
    ((javax.net.ssl.HttpsURLConnection) urlc).setSSLSocketFactory(new SSLTunnelSocketFactory(geProxy, geProxyPort));
    ((javax.net.ssl.HttpsURLConnection) urlc).setRequestMethod("POST");
    debugMsg("after else Block");
    break;
    catch(Exception e) {
    debugMsg(instCount+"Error URLC Not a instance of HTTPS Connection: " + urlc);
    debugMsg("Exception: " + e);
    I am using JDK 1.5 and Apache/1.3.19
    Can anyone help me out ....?

    Hi ejp,
    thanks for ur response
    I did what ever u suggested ...but after compiling the code I am getting following errors
    cannot find symbol
    symbol : class X509TrustManager
    location: class EPCardXMLExchange
    class MyX509TrustManager implements X509TrustManager {
    ^
    EPCardXMLExchange.java:594: cannot find symbol
    symbol : class HostnameVerifier
    location: class EPCardXMLExchange
    class MyHostnameVerifier implements HostnameVerifier {
    ^
    EPCardXMLExchange.java:413: cannot find symbol
    symbol : class X509TrustManager
    location: class EPCardXMLExchange
    X509TrustManager tm = new MyX509TrustManager();
    ^
    EPCardXMLExchange.java:414: cannot find symbol
    symbol : class HostnameVerifier
    location: class EPCardXMLExchange
    HostnameVerifier hm = new MyHostnameVerifier();
    ^
    EPCardXMLExchange.java:429: cannot find symbol
    symbol : class KeyManagerFactory
    location: class EPCardXMLExchange
    KeyManagerFactory kmf;
    ^
    EPCardXMLExchange.java:430: cannot find symbol
    symbol : variable KeyManagerFactory
    location: class EPCardXMLExchange
    kmf = KeyManagerFactory.getInstance("SunX509");
    ^
    EPCardXMLExchange.java:440: cannot find symbol
    symbol : class TrustManager
    location: class EPCardXMLExchange
    TrustManager []tma = {tm};
    ^
    EPCardXMLExchange.java:441: cannot find symbol
    symbol : class SSLContext
    location: class EPCardXMLExchange
    SSLContext sc = SSLContext.getInstance("SSL");
    ^
    EPCardXMLExchange.java:441: cannot find symbol
    symbol : variable SSLContext
    location: class EPCardXMLExchange
    SSLContext sc = SSLContext.getInstance("SSL");
    ^
    EPCardXMLExchange.java:444: cannot find symbol
    symbol : variable HttpsURLConnection
    location: class EPCardXMLExchange
    HttpsURLConnection.setDefaultSSLSocketFactory(sf1);
    ^
    EPCardXMLExchange.java:445: cannot find symbol
    symbol : variable HttpsURLConnection
    location: class EPCardXMLExchange
    HttpsURLConnection.setDefaultHostnameVerifier(hm);
    ^
    EPCardXMLExchange.java:643: cannot find symbol
    symbol : class X509TrustManager
    location: class EPCardXMLExchange.SSLTunnelSocketFactory
    X509TrustManager tm = new MyX509TrustManager();
    ^
    EPCardXMLExchange.java:644: cannot find symbol
    symbol : class HostnameVerifier
    location: class EPCardXMLExchange.SSLTunnelSocketFactory
    HostnameVerifier hm = new MyHostnameVerifier();
    ^
    EPCardXMLExchange.java:658: cannot find symbol
    symbol : class KeyManagerFactory
    location: class EPCardXMLExchange.SSLTunnelSocketFactory
    KeyManagerFactory kmf;
    ^
    EPCardXMLExchange.java:659: cannot find symbol
    symbol : variable KeyManagerFactory
    location: class EPCardXMLExchange.SSLTunnelSocketFactory
    kmf = KeyManagerFactory.getInstance("SunX509");
    ^
    EPCardXMLExchange.java:669: cannot find symbol
    symbol : class TrustManager
    location: class EPCardXMLExchange.SSLTunnelSocketFactory
    TrustManager []tma = {tm};
    ^
    EPCardXMLExchange.java:670: cannot find symbol
    symbol : class SSLContext
    location: class EPCardXMLExchange.SSLTunnelSocketFactory
    SSLContext sc = SSLContext.getInstance("SSL");
    ^
    EPCardXMLExchange.java:670: cannot find symbol
    symbol : variable SSLContext
    location: class EPCardXMLExchange.SSLTunnelSocketFactory
    SSLContext sc = SSLContext.getInstance("SSL");
    ^
    EPCardXMLExchange.java:675: cannot find symbol
    symbol : variable HttpsURLConnection
    location: class EPCardXMLExchange.SSLTunnelSocketFactory
    HttpsURLConnection.setDefaultSSLSocketFactory(dfactory);
    ^
    EPCardXMLExchange.java:676: cannot find symbol
    symbol : variable HttpsURLConnection
    location: class EPCardXMLExchange.SSLTunnelSocketFactory
    HttpsURLConnection.setDefaultHostnameVerifier(hm);
    ^
    20 errors
    Can you tell me what I am getting errors ?

  • How to use JSSE HttpsURLConnection in WL 5.1

    I am trying to POST, from a jsp within weblogic,
    to an outside https URL. It appears to me that
    weblogic.net.http.HttpsURLConnection cannot POST
    to a connection.
    I am now trying to use Sun's JSSE 1.0.3.
    I've installed jcert.jar, jnet.jar and jsse.jar to
    C:\usr\local\java\jdk1.3.1_04\jre\lib\ext
    Here is the relevant code:
    <%@ page import="java.io.*,java.net.*,java.util.*,java.lang.*,javax.servlet.*,java.security.*,com.sun.net.ssl.*"
    %>
    <%
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    System.setProperty("java.protocol.handler.pkgs", com.sun.net.ssl.internal.www.protocol");
    url = new java.net.URL("https://www.some-secure-site.com"); // This is where
    the ClassCastException occurs.
    %>
    Here is the thread dump:
    java.lang.ClassCastException: weblogic.net.http.HttpsURLConnection
    at jsp_servlet._payPal.__verify._jspService(__verify.java:150)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:120)
    at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:945)
    at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:909)
    at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:269)
    at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:392)
    at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:274)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:130)
    I think I need to register an HTTPS URLStreamHandler when
    instantiating my URL object so I receive a
    com.sun.net.ssl.HttpsURLConnection instead of a
    weblogic.net.http.HttpsURLConnection - like so:
    URL url = new URL("https", "some.site.com", 443, "/some/uri", new some.URLStreamHandler());
    Any help is greatly appreciated.
    -SS

    you should use specifal constructor .. for url..
    some thing like..
    URL( "https","www.verisign.com","443","",new
    com.sun.net.ssl.internal.www.protocol.https.Handler());
    thanks
    kiran
    "sstaats" <[email protected]> wrote in message
    news:[email protected]...
    >
    I am trying to POST, from a jsp within weblogic,
    to an outside https URL. It appears to me that
    weblogic.net.http.HttpsURLConnection cannot POST
    to a connection.
    I am now trying to use Sun's JSSE 1.0.3.
    I've installed jcert.jar, jnet.jar and jsse.jar to
    C:\usr\local\java\jdk1.3.1_04\jre\lib\ext
    Here is the relevant code:
    <%@ pageimport="java.io.*,java.net.*,java.util.*,java.lang.*,javax.servlet.*,java.se
    curity.*,com.sun.net.ssl.*"
    %>
    <%
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    System.setProperty("java.protocol.handler.pkgs",com.sun.net.ssl.internal.www.protocol");
    url = new java.net.URL("https://www.some-secure-site.com"); // This is
    where
    the ClassCastException occurs.
    %>
    Here is the thread dump:
    java.lang.ClassCastException: weblogic.net.http.HttpsURLConnection
    at jsp_servlet._payPal.__verify._jspService(__verify.java:150)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    atweblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
    :120)
    atweblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
    l.java:945)
    atweblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
    l.java:909)
    atweblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
    Manager.java:269)
    atweblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:392)
    atweblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:274)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:130)
    I think I need to register an HTTPS URLStreamHandler when
    instantiating my URL object so I receive a
    com.sun.net.ssl.HttpsURLConnection instead of a
    weblogic.net.http.HttpsURLConnection - like so:
    URL url = new URL("https", "some.site.com", 443, "/some/uri", newsome.URLStreamHandler());
    >
    Any help is greatly appreciated.
    -SS

  • Need help with Casting to HttpsURLConnection

    Can anyone see why this simple cast will not work for me?
    Thanks.
    Here's the error message I get when I try to run it:
    C:\myJava\code\Source>java TestHttpsClientPost
    We have successfully initialized the default SSLSocketFactory!
    java.lang.ClassCastException
    at TestHttpsClientPost.openURLConn(TestHttpsClientPost.java:47)
    at TestHttpsClientPost.callBasicTest(TestHttpsClientPost.java:64)
    at TestHttpsClientPost.main(TestHttpsClientPost.java:86)
    Done with basictest.
    Here's the code, with two methods, a constructor and main:
    import java.io.*;
    import java.net.*;
    import javax.net.ssl.*;
    public class TestHttpsClientPost
    //class variables:
    public static String enc = "UTF-8";
    // THE URL CONNECTION ATTRIBUTES:
    private URL url;
    private HttpsURLConnection urlConn;
    public TestHttpsClientPost() // THE CLASS CONSTRUCTOR:
    // MAKE SURE SSL CAN BE HANDLED
    System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
    java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    // CREATE AN SSL FACTORY THAT WILL TRUST ALL SERVER CERTIFICATES
    try
    javax.net.ssl.SSLSocket sock = null;
    TrustManager[] tma = ( new TrustManager[]
    { new MyTrustManager() }
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null,tma,new java.security.SecureRandom());
    SSLSocketFactory sf1 = sc.getSocketFactory();
    HttpsURLConnection.setDefaultSSLSocketFactory(sf1);
    System.out.print( "We have successfully initialized the default SSLSocketFactory!\n" );
    } catch(Exception e)
    e.printStackTrace();
    private void openURLConn(String pUrlAddress)
    try
    // SET THE URL TO BE CONNECTED TO:
    url = new URL("https://www.verisign.com");
    // OPEN CONNECTION
    urlConn = (javax.net.ssl.HttpsURLConnection)url.openConnection();
    //HttpsURLConnection urlConn = (HttpsURLConnection)url.openConnection();
    } catch(Exception e)
    e.printStackTrace();
    private void callBasicTest()
    try
    // CONSTRUCT THE POSTSTRING:
    String postString = URLEncoder.encode("function",enc) + "=" + URLEncoder.encode("basictest",enc) +
    "&" + URLEncoder.encode("username",enc) + "=" + URLEncoder.encode("Bob",enc);
    // OPEN A CONNECTION.
    openURLConn(null);
    // POST REQUEST TO URL
    postRequest(postString);
    // WRITE OUTPUT TO STOUT.
    outputResponse(System.out,null);
    // CLOSE CONNECTION
    closeURLConn();
    System.out.println("Done with basictest");
    } catch (Exception e)
    e.printStackTrace();
    public static void main(String[] args) throws Exception
    try
         // CREATE AN INSTANCE OF THIS CLASS.
    TestHttpsClientPost thisClient = new TestHttpsClientPost();
    thisClient.callBasicTest();
    } catch (Exception e)
    e.printStackTrace();

    Thanks again! I get "This is incorrect" when applying your test, which I expected, because I tried to cast using that full path (javax.net.ssl.HttpsURLConnection) and it failed.
    There was a runtime version of java on my computer before I installed the J2SE.... it is in a directory called j2re1.4.1_02. I just left it there when I installed j2sdk1.4.2 in a different directory. Do you think this could cause my problem? I'll can try uninstalling the older runtime version.
    Also, the only thing in my CLASSPATH is a period followed by a semicolon. Is that correct or should I point to a classes directory in j2sdk1.4.2? And, I have nothing in my PATH regarding java.... is that a problem?

  • 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

    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�n 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

  • Servlet/Tomcat using HTTPsUrlConnection error

    Hello all,
    I am fairly new to java/tomcat and am attempting to develop an SSO connection. When I get to the following line of code in my servlet
    HttpsURLConnection httpConn = (HttpsURLConnection)sso.openConnection();
    I receive the following error:
    SingleSignOn threw exception
    java.lang.ClassCastException: sun.net.www.protocol.http.HttpURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
    Any help is much appreciated.
    Regards,
    --Omar
    Edited by: user7041419 on Nov 17, 2010 3:26 PM

    Yes that is one of the issues I have. Thanks for the assistance.

  • ClassCastException: HttpsURLConnectionOldImpl

    I am working with jdk 1.4.0 and the incorporated JSSE and I am using Tomcat 4.0.3 with SSL. I am attempting a secure connection to a url, using https. When I try to cast my URLConnection object to a javax.net.ssl.HttpsURLConnection I receive the exception below in Tomcat. Note, I have successfully communicated between client/server over secure sockets, (reading/writing from the designated port's stream) but my goal is to use the HttpsURLConnection class. Thanks in advance for your assistance.
    java.lang.ClassCastException: com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl
    at mil.disa.dtools.testing.HttpsRequest.processRequest(HttpsRequest.java:157)
    at mil.disa.dtools.testing.HttpsRequest.doGet(HttpsRequest.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.
    ava:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
    at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
    at java.lang.Thread.run(Thread.java:536)

    I've got the same problem with Tomcat 4.1.18 through 24 under JDK 1.4.1_02. I've tried every logical setting for the handler.protocol, including javax.net.ssl.internal.www.protocol, javax.net.ssl, and many others as well as sun.net.www.protocol from looking at the structure of the jsse.jar in JDK 1.4. But the (apparent) Tomcat continues to (apparnetly) ignore my setting.
    Have you learned anything specific here? Do you have any other suggestions? ... I'm fresh out of ideas!

Maybe you are looking for

  • Error 155007 (Path is not a working copy directory) after XCode upgrade

    Another person with an error caused after upgrading XCode to 3.2.3 from 3.1.3! My project now compiles and seems to run in the simulator, but the bottom of the project window shows the above error message as soon as I open the project. It also adds t

  • VGA Connection - help

    When I plug in my macbook to my DLP TV (via Mini-DVI to VGA) I only get the background, I can't see the dock or the menu at the top. Is this all I should see? Please help. Thanks, H-dog Macbok   Mac OS X (10.4.10)  

  • Why is there suddenly a one inch black margin on each side of my MB Pro?

    Suddenly there is this black, one inch margin running down both sides of my view screen. How do I get out of it? It just appeared this morning when I turned my laptop on. Can't find anything in preferences that would eliminate it. tx!

  • Laptop dmv4 - how do i create a windows recovery disk?

    If my hard drive crashes and I need a windowd CD  how do I make one?

  • Smart Form Download

    Hi all, When a smart form is downloaded it gets downloaded as .xml file. The question is, how does the smart form get converted to xml file. Is there any function module that is called when we download it and if so what is the function module.