Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

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.test.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();
  }
}

  • No labels