Monday, February 27, 2012

Client authentication: The Steps to access web service on https


Web Service Client over HTTPS
       

Step 1: Create a normal java program. Right click and select New Project.



Step 2: Right click on project(TestClient) New --> Others. Select Web Service on Categories and select Web Service Client on File Types. Click next.

Select wsdl url and paste your specified URL in it (https://xyz.com/ServerAgent/server?wsdl). Click finish.

Step 3: Client code to connect the sever.


package testclient;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ClientPgm{

    public static void main(String[] args) {
        try {
            System.setProperty("javax.net.ssl.keyStore", "tmp/client-keystore.jks"); //path of client-key
            System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
            System.setProperty("javax.net.ssl.trustStore", "src/tmp/server-truststore.jks"); //path of trust store
            System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
         
/**
 *         Define your server methods here...
 */

        } catch (MalformedURLException ex) {
            Logger.getLogger(LocalMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

The server side methods will be under.

 you can drag and drop these methods to your code.

Step 4: Run the ClientPgm.java.


I tried these steps and its working fine. Please share ur comments if there are any mistake.

1 comment: