1

I am new to web service. I have given a task to write a client code which will call a authentication web service which is exposed on https. I need to pass username and password from client code to check for valid user. I also have keystore and trustore file. I don't know how to use these files. Can anyone please guide me and provide a sample client code?

I am using Axis to generate client stub from wsdl.

Regards,

Vishal

vishal Kumar
  • 95
  • 3
  • 8

3 Answers3

0
  1. When you say Webservice and Axis, I think you are talking about SOAP. You may want to check Java webservice (soap) client - use certificates.

  2. SOAP is a protocol over HTTP. If you want it to be over SSL it would be on HTTPS.

  3. If you are working on RESTful implementations of JSR-311 like CXF, jersey etc, you will find examples in their websites.

Community
  • 1
  • 1
Chris
  • 5,584
  • 9
  • 40
  • 58
0

If you can access the URL then you need to add the certificate.

  • Access the URL and click on the lock icon to view the certificate.
  • Go to the details tab of the certificate and save certificate in Base64 .cer format
  • Install the certificates
  • Execute the following command

The command:

$ keytool -import -noprompt -trustcacerts -alias ALIASNAME -file FILENAME_OF_THE_INSTALLED_CERTIFICATE -keystore PATH_TO_CACERTS_FILE -storepass PASSWORD

Reference: http://docs.oracle.com/javase/tutorial/security/toolsign/rstep2.html

Vivek
  • 1
  • 1
0

axis1 or axis2? anyway.. if it's just https, you need to import the certificate and depending on the policy of the server you are calling you might have to present yourself with a certificate too.....

look here https://axis.apache.org/axis2/java/rampart/samples.html for information and an example on basic auth..

As for adding a certificate to the outgoing request you need to do something along these lines:

      System.setProperty("javax.net.ssl.trustStoreType", "JKS");
      System.setProperty("javax.net.ssl.trustStore", "keystore.jks");
      System.setProperty("javax.net.ssl.trustStorePassword", "password");
      System.setProperty("javax.net.ssl.keyStoreType", "pkcs12");
      System.setProperty("javax.net.ssl.keyStore", "client.p12");
      System.setProperty("javax.net.ssl.keyStorePassword", "password");

Take additional care if your communication is going through a proxy..

witchedwiz
  • 295
  • 2
  • 10