Reference Guide

Table Of Contents
functionality refers to the application’s domain model or business logic. Besides the domain model
functionality, a view normally has requirements that are specific to presentation logic (For example
a view could call the server to retrieve a catalog of pictures related to an item). It is not desired to
pollute the RESTful web services from hm-rs module with presentation logic specific methods.
Therefore, it’s considered a good practice creating GUI-specific REST APIs in the hm-ui module.
Similarly to the hm-rs module, in order to implement REST web services the module needs to
declare some dependencies; open the hm-ui/pom.xml file and add the XML extract from the
Creating Domain Service Resource (REST Interface of Business Logic Service) on p age 169 under
the “REST Module Dependencies” listing and the RESTful Web Services Unit Test on page 178
under “Resource Test Dependencies” listing, to the <dependencies> node (Remove any
duplicates). After updating the POM file update the Eclipse project dependencies (see Updating
Project Dependencies on page 146).
The following SwitchResource.java listing shows how to create the Switch View REST API named
SwitchResource. The SwitchResource.java listing shows an extract of the resource. To use JSON
encoding see JSON Encoding on page 183. To write unit test follow the instructions from RESTful
Web Services Unit Test on page 178.
SwitchResource.java:
package com.hp.hm.ui.rs;
...
@Path("hm")
public class SwitchResource extends ControllerResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response hello() {
return ok("The world is all about Switch!!! <p>” + “The Hewlett-
Packard is here to prove it by providing” + you with a Test
APP to verify SDK guide, the Health Monitor”).build();
}
}
Now update the web.xml placeholder added in Module Configuration on page 201 under the “UI
Module Web Application (web.xml)” listing. The Jersey Servlet [2] that handles HTTP requests and
dispatches to the right REST API based on the @Path annotations needs to be defined. Update hm-
ui/src/main/webapp/WEB-INF/web.xml file with the content from the following listing:
UI Module Web Application (web.xml) Defining Jersey Servlet:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Health Monitor UI</display-name>
<servlet>
205