This page details the steps necessary to create a REST client, using eclipse, that is able to communicate with the holiday web service. For the client I used Jersey, and downloaded the client and core jars here.
1. Create a new project using eclipse
2. Add the Jersey jars to the buildpath.
3. Go to run configurations and add the Jersey jars to the classpath
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 of your project's run
configuration):
-Djavax.net.ssl.trustStore=/path/to/keystore
-Djavax.net.ssl.trustStorePassword=changeit (default password is changeit)
4. Create the main method
public static void main(String[] args) {
try {
Client client = Client.create();
WebResource webResource = client.resource("https://www.testIMPORTANT NOTE: THE BEHAVIOR BELOW IS DEPRECATED
In order to communicate with the Holiday Web Service via REST, the url of the web method must be according to these guidelines.
The base url for the REST controller (on the test server) is [https://www.hawaii.edu/its/ws/holiday/rest]
From there the name of the method is appended onto the url Ex. /exists, /closest, /inMonth, /inYear, /inRange
The name of the method is followed by a '?' and then the parameters separated by '&'.
Ex. https://www.hawaii.edu/its/ws/holiday/rest/closest?date=2012-01-01&isObserved=true
Supported methods:
For all methods that require the full date the format must be yyyy-MM-dd, even if the day or month is a single digit it must be preceded by a 0, Ex. 01, 02, etc.
Only the parameters concerning the date are necessary all other parameters are optional, however any boolean values will default to true if not specified.
- boolean isObserved - Used to indicate if the user is referring to the date the holiday is observed (true), or the official date (false).
- boolean searchForward - Used by closest method to search forward if true or backwards if false.
- boolean includeStartAndEnd - Used by inRange method to decide if the search should include the start and end dates.
- String type - An optional parameter through which the user can select which type of Holiday should be returned (Federal, Bank, UH, State)
exists(date, isObserved, type) - Returns whether the given date is a holiday or not.
Ex. https://www.hawaii.edu/its/ws/holiday/rest/closest");
MultivaluedMap<String, String> parameters = new MultivaluedMapImpl();
parameters.add("date", "2012-01-01");
parameters.add("isObserved", "true");
ClientResponse response = webResource.queryParams(parameters).accept("application.json").get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Output from Server .... \n");
System.out.println(output);
}
catch (Exception e) {
e.printStackTrace();
}
}exists?date=2012-01-02&isObserved=true&type=Federal
closest(date, searchForward, isObserved, type) - Returns the closest holiday to the given date.
Ex. https://www.hawaii.edu/its/ws/holiday/rest/closest?date=2012-01-10&searchForward=true
inMonth(month, year, isObserved, type) - Returns all holidays within the given month. The year parameter is optional and will default to the current year if not specified.
Ex. https://www.hawaii.edu/its/ws/holiday/rest/inMonth?month=03&type=state
inYear(year, isObserved, type) - Returns all holidays within the given year.
Ex. https://www.hawaii.edu/its/ws/holiday/rest/inYear?year=2012
inRange(beginDate, endDate, includeStartAndEnd, isObserved, type) - Returns all holidays within the range.
Ex. https://www.hawaii.edu/its/ws/holiday/rest/inRange?beginDate=2012-01-27&endDate=2012-06-29&includeStartAndEnd=true