Reference Guide
Table Of Contents
- 1 Introduction
- 2 Establishing Your Test and Development Environments
- 3 Developing Applications
- Introduction
- Authentication
- REST API
- Audit Logging
- Alert Logging
- Configuration
- High Availability
- OpenFlow
- Metrics Framework
- GUI
- SKI Framework - Overview
- SKI Framework - Navigation Tree
- SKI Framework - Hash Navigation
- SKI Framework - View Life-Cycle
- SKI Framework - Live Reference Application
- UI Extension
- Introduction
- Controller Teaming
- Distributed Coordination Service
- Persistence
- Backup and Restore
- Device Driver Framework
- 4 Application Security
- 5 Including Debian Packages with Applications
- 6 Sample Application
- Application Description
- Creating Application Development Workspace
- Application Generator (Automatic Workspace Creation)
- Creating Eclipse Projects
- Updating Project Dependencies
- Building the Application
- Installing the Application
- Application Code
- 7 Testing Applications
- 8 Built-In Applications
- Appendix A
- Appendix B
- Bibliography
Now that the JSON factory is in place, update the SwitchResource to use the JsonService to
encode and decode Switch objects. The SwitchResource.java Using JSON Codecs listing shows a
modification of SwitchResource that uses a JSON codec to encode Switch objects.
SwitchResource.java Using JSON Codecs:
package com.hp.hm.rs;
import com.hp.sdn.json.JsonService;
...
@Path("switches")
public class SwitchResource extends ControllerResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response list() {
SwitchService service = get(SwitchService.class);
List<Switch> switches = service.find(null, null);
JsonService jsonService = get(JsonService.class);
String result = jsonService.toJsonList(switches, Switch.class, true);
return ok(result).build();
}
...
}
JsonService Module Dependencies:
<dependency>
<groupId>com.hp.sdn</groupId>
<artifactId>sdn-cmmon-api</artifactId>
<version>${sdn.version}</version>
</dependency>
The following listing, SwitchResourceTest.java Using JSON Codecs, is a modification of the
SwitchResourceTest.java that also uses JsonService to complete the tests.
SwitchResourceTest.java Using JSON Codecs:
package com.hp.hm.rs;
import com.hp.sdn.json.JsonService;
...
public class SwitchResourceTest extends ControllerResourceTest {
private static final String BASE_PATH = "switches";
private SwitchService switchServiceMock;
private JsonService jsonServiceMock;
public SwitchResourceTest() {
187