Sunday, June 16, 2013

SSL client on Jdeveloper


If we want to access a URL which is ssl protected either through a java.net.URL or using a webservice client we need to have the trusted keystore location to communicate.

When we got a ssl certificate we need to import the certificate to the keystore

D:\Middleware\JDev11gR1PS4\jdk160_24\jre\bin>keytool -list -keystore D:\Middlewa
re\JDev11gR1PS4\jdk160_24\jre\lib\security\cacerts


Adding the trusted key into the keystore.

D:\Middleware\JDev11gR1PS4\jdk160_24\jre\bin>keytool -keystore D:\Middleware\JDe
v11gR1PS4\jdk160_24\jre\lib\security\cacerts -alias mycert

D:\Middleware\JDev11gR1PS4\jdk160_24\jre\bin>keytool -delete D:\Middleware\JDe
v11gR1PS4\jdk160_24\jre\lib\security\cacerts -alias mycert

The default password is "changeit" .keytool -help will give list of options available.

Write a Java program with main method as :

    public static void main(String[] args) {
        URL url;


        try {
            url = new URL("https://test.test.com/test");
       
                BufferedReader in =
                    new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()));
                String urlString = "";
                String current;
                while ((current = in.readLine()) != null) {
                    urlString += current;
                }
                System.out.println(urlString);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

From the tools> Preference >Credential , points to the keystore location.


Run the java programe to connect to the https:// url.

If you want to use a seperate keystore other than JDK keystore, Copy the cacerts to some different location. Import the key as above.


No comments: