cancel
Showing results for 
Search instead for 
Did you mean: 

HttpsURLConnection URL connection issue

Former Member
0 Kudos

Hi All,

I need to create URL connection with HTTPS URL. I can run Main java class successfully in machine which hosted in SAP Java server, but fail to run integrate it with e-commence application. When depployed in to SAP Java server cannot open HttpsURLConnection and always return CalssCastexception. However same code run as Java Main class

Is this can be a (SSL) Handshake? or is this SSL issue?

MyCode:

String httpsURL = "https://encrypted.google.com/";
    URL myurl = new URL(httpsURL);
    HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
    InputStream ins = con.getInputStream();
    InputStreamReader isr = new InputStreamReader(ins);
    BufferedReader in = new BufferedReader(isr);

    String inputLine;

    while ((inputLine = in.readLine()) != null) {
      System.out.println(inputLine);
    }

    in.close();

Thank You

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

This is purely ssl issue. You can try adding the below logic first.. This code basically sets ssl properties for us.

import java.security.Security;

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties properties = System.getProperties();
String handlers = System.getProperty("java.protocol.handler.pkgs");
if (handlers == null) {
    // nothing specified yet (expected case)
    properties.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
}
else {
    // something already there, put ourselves out front
    properties.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol|".concat(handlers));	 
}
System.setProperties(properties); 

Below you start your code....

Former Member
0 Kudos

Hi,

Thank you very much for your support, it's works fine.

Thank You

former_member227405
Participant
0 Kudos

Hi Baskar,

I have used you code in my place also :

But from the highlighted one I am not able to process further from here and it is directly coming out of the method.

Means something wrong with the connection.

Please suggest if you need any more explanation

Thanks

Sonu

Answers (0)