SDN Controller Programming Guide

59
File: pom.xml
Purpose: specifies the Jersey REST URL prefix
UI Extension webapp context path:
<properties>
<jersey.version>1.8</jersey.version>
<webapp.context>acme/ui/myapp</webapp.context>
Directory:/myapp/src/main/java
Javapackage:com.acme.myapp.ui
File:MyAppUIExtension.java
Purpose: creates the UI Extension registration class, providing SDN with the paths to find the
js.html and css.html files.
When a UI project implements ControllerUIExtension (extending SelfRegisteringUIExtension), SDN
will register the Extension to the SDN UI Extension Registry. The Registry keeps track of all
available UI extensions. During runtime, when the main page (index) is loaded, the HTTP request
for the index page is actually serviced by the AppIndexResource. This resource dynamically builds
up the main HTTP page using a static template file (com.hp.sdn.ui.index.html) and injects all
content from all of the registered UI Extensions by replacing embedded tags (CSS-INCLUDES,
JAVASCRIPT-INCLUDES, and so on).
UI Extension Java implementation:
public class MyAppUIExtension extends SelfRegisteringUIExtension {
/** Create the controller UI elements contributor. */
public MyAppUIExtension() {
super("myapp", "com/acme/myapp/ui", MyAppUIExtension.class);
}
}
Directory: /myapp/src/main/java
Java package: com.acme.myapp.ui.rs
File: MyAppResource.java
Purpose: creates the server-side resource that returns JSON string data via the HTTP GET at URL
acme/ui/myapp/app/rs/mydata (app/rs comes from the web.xml).
UI Extension Java resource implementation:
@Path("mydata")
public class MyAppResource extends ControllerResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response data() {
// code to create my JSON data
return ok(myJsonData).build();
}
}