This page details the steps necessary to create a client, using eclipse, that is able to communicate with the holiday web service.
1. Create a new project using eclipse
2. Go to Run Configurations
- a. Under Java Applications -> main tab
- i. Set main class to: org.apache.axis.wsdl.WSDL2Java
- ii. Set Project to whatever project you created
- iii. Set name to whatever name you want.
- b. Under Java Applications -> arguments tab
- i. Set Program Arguments to: http://localhost:8080/holidayWebService/services/holiday?wsdl -o src (The url location for the wsdl)
- c. Under Java Applications -> classpath tab
- i. Add in latest jars for:
- activation.jar
- axis.jar
- commons-discovery.jar
- commons-logging.jar
- commons-net.jar
- jaxrpc.jar
- jaxrpc-api.jar
- mail.jar
- saaj.jar
- wsdl4j.jar
- (also add these jars to the buildpath, these jars are available in the misint -> holidayWebService repository in the HolidayServiceClient Project)
- i. Add in latest jars for:
NOTE: When creating a client for the test server it is required that you add the test site's certificate to the keystore as described here,
and then run the project with arguments (In Eclipse these should be added to the VM arguments in the arguments tab of your
projects run configuration):
-Djavax.net.ssl.trustStore=/path/to/keystore
-Djavax.net.ssl.trustStorePassword=changeit (default password is changeit)
3. Ensure the web service is running, and then run the project. This should generate the necessary files for creating a client.
PKIX path building error:
IF there is a PKIX path building failed: SunCertPathBuilderException the web services security certificate has not been added to Java's cacerts file (file of trusted websites). This is required as our test servers are using a self-signed certificate which is not viewed as a valid certificate by Java.
Adding the certificate can be done as described here.
4. Create a main method
/**
* Simple sample of main method, it queries the web service for the closest observed holiday to January 1st, 2012.
*/
public static void main(String[] args) throws MalformedURLException
{
HolidayService service = new HolidayServiceLocator();
Calendar newYears = Calendar.getInstance();
// Error with grails calendar. If hour is above 12 then the day will be wrong, so set hours, minutes, seconds to zero to be on safe side.
newYears.set(Calendar.getInstance().get(Calendar.YEAR), Calendar.JANUARY, 1, 0, 0, 0);
try
{
Holiday closest = service.getHolidayServicePort().getClosestHoliday(newYears, true, true);
String name = closest.getDescription();
assert("New Year's Day".equals(name));
}
catch (Exception e)
{
System.out.println(e.toString());
}
}