Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
This page details the steps necessary to create a REST client, using eclipse, that is able to communicate with the holiday web service.

...

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):

...

  For the client I used [Jersey|http://jersey.java.net/], and downloaded the client and core jars [here|http://jersey.java.net/nonav/documentation/latest/chapter_deps.html#core_client].

*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|http://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed.html],
            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*

import javax.ws.rs.core.MultivaluedMap;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;

public class holidayClientMain {
  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");

...


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MultivaluedMap<String, String> parameters = new MultivaluedMapImpl();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parameters.add("date", "2012-01-01")

...

;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parameters.add("isObserved", "true")

...

;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ClientResponse response = webResource.queryParams(parameters).accept("application.json").get(ClientResponse.class);

...



&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (response.getStatus() \!= 200)

...

 \{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());

...


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String output = response.getEntity(String.class)

...

;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Output from Server .... \n")

...

;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(output)

...

;
&nbsp;&nbsp;&nbsp;&nbsp;\}
&nbsp;&nbsp;&nbsp;&nbsp;catch (Exception e) \{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();
&nbsp;&nbsp;&nbsp;&nbsp;\}
&nbsp;&nbsp;\}
\}