SDN Controller Programming Guide

148
public void testDelete() {
long idMock = 1;
String path = BASE_PATH + "/" + idMock;
String response = delete(path);
Assert.assertTrue(response.isEmpty());
}
}
Resource Test Dependencies:
<dependency>
<groupId>com.hp.sdn</groupId>
<artifactId>sdn-common-misc</artifactId>
<version>${sdn.version}</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.1.4</version>
</dependency>
Domain Service - REST API Integration
Figure 3 illustrates a common pattern used when working with Servlets: The Model-View-Controller
(MVC) pattern. In this pattern the Servlet acts as the Controller. As mentioned before, when using
RESTful Web Services we don’t directly write Servlets, however a REST API acts as the Controller as
well. A normal behavior of a REST API includes:
1. Decode the requestJSON [37] format in our sample application.
2. Call domain services(Business Logic) to serve the request.
3. Encode the result to include in the responseJSON [37] format in our sample application.
This section describes how to integrate the domain service (Business Logic) and the REST API
(RESTful web services). The objective is to have the REST layer delegating business logic to domain
services.
The life-cycle of Domain Services and RESTful web services [2] is managed by different
technologies. Domain services life-cycle is managed by OSGi; we don’t need to create instances
of our domain services, OSGi will create them for us by scanning classes annotated with
@Component, and they will be ready to be consumed if they are annotated with @Service (as
illustrated in SwitchComponent.javaSample Application OSGi Service Componentfor more
information see Providing Services with OSGi Declarative Services on page 126). In the other
hand RESTful web services are based on Servlets; Jersey Servlet [2] manages the life-cycle of the
REST APIs. Similarly to Domain Services we don’t need to create instances of our REST APIs, the
Jersey Servlet will create them for us by scanning classes annotated with @Path; the Jersey Servlet
handles HTTP requests and dispatches to the right REST API based on the @Path annotations (as
illustrated in Creating Domain Service Resource (REST Interface of Business Logic Service) on page