Restructuring the form of REST API deployment to provide
for security of app's REST APIs and for consistency of
exception mappers and JSON writer.

Change-Id: Id318372bf62f82ed974355c05e7fe64e0fbfc0c5
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java b/apps/acl/src/main/java/org/onosproject/acl/AclWebApplication.java
similarity index 62%
copy from web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java
copy to apps/acl/src/main/java/org/onosproject/acl/AclWebApplication.java
index 2d7a1ea..c66c3f8 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java
+++ b/apps/acl/src/main/java/org/onosproject/acl/AclWebApplication.java
@@ -13,19 +13,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
 
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
+package org.onosproject.acl;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
 
 /**
- * Mapper for illegal argument exceptions to the BAD_REQUEST response code.
+ * ACL REST API web application.
  */
-@Provider
-public class IllegalArgumentExceptionMapper extends AbstractMapper<IllegalArgumentException> {
+public class AclWebApplication extends AbstractWebApplication {
     @Override
-    protected Response.Status responseStatus() {
-        return Response.Status.BAD_REQUEST;
+    public Set<Class<?>> getClasses() {
+        return getClasses(AclWebResource.class);
     }
 }
 
diff --git a/apps/acl/src/main/webapp/WEB-INF/web.xml b/apps/acl/src/main/webapp/WEB-INF/web.xml
index fc188b7..bd5de2f 100644
--- a/apps/acl/src/main/webapp/WEB-INF/web.xml
+++ b/apps/acl/src/main/webapp/WEB-INF/web.xml
@@ -22,20 +22,35 @@
          xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          id="ONOS" version="2.5">
-    <display-name>ACL application</display-name>
+    <display-name>ACL application REST API</display-name>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Secured</web-resource-name>
+            <url-pattern>/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>admin</role-name>
+        </auth-constraint>
+    </security-constraint>
+
+    <security-role>
+        <role-name>admin</role-name>
+    </security-role>
+
+    <login-config>
+        <auth-method>BASIC</auth-method>
+        <realm-name>karaf</realm-name>
+    </login-config>
 
     <servlet>
         <servlet-name>JAX-RS Service</servlet-name>
         <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
         <init-param>
-            <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
-            <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.onosproject.acl.AclWebApplication</param-value>
         </init-param>
-        <init-param>
-            <param-name>com.sun.jersey.config.property.classnames</param-name>
-            <param-value>org.onosproject.acl.AclWebResource</param-value>
-        </init-param>
-        <load-on-startup>10</load-on-startup>
+        <load-on-startup>1</load-on-startup>
     </servlet>
 
     <servlet-mapping>
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java b/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebApplication.java
similarity index 62%
copy from web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java
copy to apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebApplication.java
index 2d7a1ea..65c99da 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java
+++ b/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebApplication.java
@@ -13,19 +13,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
 
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
+package org.onosproject.dhcp.rest;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
 
 /**
- * Mapper for illegal argument exceptions to the BAD_REQUEST response code.
+ * DHCP Web application.
  */
-@Provider
-public class IllegalArgumentExceptionMapper extends AbstractMapper<IllegalArgumentException> {
+public class DhcpWebApplication extends AbstractWebApplication {
     @Override
-    protected Response.Status responseStatus() {
-        return Response.Status.BAD_REQUEST;
+    public Set<Class<?>> getClasses() {
+        return getClasses(DhcpWebResource.class);
     }
 }
-
diff --git a/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebResource.java b/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebResource.java
index 6265fee..36c7a6c 100644
--- a/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebResource.java
+++ b/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebResource.java
@@ -44,7 +44,7 @@
 @Path("dhcp")
 public class DhcpWebResource extends AbstractWebResource {
 
-    final DhcpService service = get(DhcpService.class);
+    private final DhcpService service = get(DhcpService.class);
 
     /**
      * Get DHCP server configuration data.
@@ -56,12 +56,11 @@
     @GET
     @Path("config")
     public Response getConfigs() {
-        DhcpService service = get(DhcpService.class);
         ObjectNode node = mapper().createObjectNode()
                 .put("leaseTime", service.getLeaseTime())
                 .put("renewalTime", service.getRenewalTime())
                 .put("rebindingTime", service.getRebindingTime());
-        return ok(node.toString()).build();
+        return ok(node).build();
     }
 
     /**
@@ -76,13 +75,13 @@
     public Response listMappings() {
         ObjectNode root = mapper().createObjectNode();
 
-        final Map<HostId, IpAssignment> intents = service.listMapping();
+        Map<HostId, IpAssignment> intents = service.listMapping();
         ArrayNode arrayNode = root.putArray("mappings");
         intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
                                                               .put("host", i.getKey().toString())
                                                               .put("ip", i.getValue().ipAddress().toString())));
 
-        return ok(root.toString()).build();
+        return ok(root).build();
     }
 
 
@@ -96,12 +95,11 @@
     @GET
     @Path("available")
     public Response listAvailableIPs() {
-        final Iterable<Ip4Address> availableIPList = service.getAvailableIPs();
-
-        final ObjectNode root = mapper().createObjectNode();
+        Iterable<Ip4Address> availableIPList = service.getAvailableIPs();
+        ObjectNode root = mapper().createObjectNode();
         ArrayNode arrayNode = root.putArray("availableIP");
         availableIPList.forEach(i -> arrayNode.add(i.toString()));
-        return ok(root.toString()).build();
+        return ok(root).build();
     }
 
     /**
@@ -139,7 +137,7 @@
         } catch (IOException e) {
             throw new IllegalArgumentException(e.getMessage());
         }
-        return ok(root.toString()).build();
+        return ok(root).build();
     }
 
     /**
@@ -152,7 +150,6 @@
     @DELETE
     @Path("mappings/{macID}")
     public Response deleteMapping(@PathParam("macID") String macID) {
-
         ObjectNode root = mapper().createObjectNode();
 
         if (!service.removeStaticMapping(MacAddress.valueOf(macID))) {
@@ -164,6 +161,6 @@
                                                               .put("host", i.getKey().toString())
                                                               .put("ip", i.getValue().ipAddress().toString())));
 
-        return ok(root.toString()).build();
+        return ok(root).build();
     }
 }
diff --git a/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml b/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml
index a53110e..974ac99 100644
--- a/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml
+++ b/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml
@@ -14,24 +14,38 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License.
   -->
-<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://java.sun.com/xml/ns/javaee"
          xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          id="ONOS" version="2.5">
     <display-name>DHCP Server REST API v1.0</display-name>
 
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Secured</web-resource-name>
+            <url-pattern>/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>admin</role-name>
+        </auth-constraint>
+    </security-constraint>
+
+    <security-role>
+        <role-name>admin</role-name>
+    </security-role>
+
+    <login-config>
+        <auth-method>BASIC</auth-method>
+        <realm-name>karaf</realm-name>
+    </login-config>
+
     <servlet>
         <servlet-name>JAX-RS Service</servlet-name>
         <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
         <init-param>
-            <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
-            <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
-        </init-param>
-        <init-param>
-            <param-name>com.sun.jersey.config.property.classnames</param-name>
-            <param-value>
-                org.onosproject.dhcp.rest.DhcpWebResource
-            </param-value>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.onosproject.dhcp.rest.DhcpWebApplication</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VtnWebApplication.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VtnWebApplication.java
new file mode 100644
index 0000000..4f24a2f
--- /dev/null
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VtnWebApplication.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.vtnweb.resources;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * VTN REST API web application.
+ */
+public class VtnWebApplication extends AbstractWebApplication {
+    @Override
+    public Set<Class<?>> getClasses() {
+        return getClasses(TenantNetworkWebResource.class,
+                          SubnetWebResource.class,
+                          VirtualPortWebResource.class,
+                          FlowClassifierWebResource.class,
+                          PortChainWebResource.class,
+                          PortPairGroupWebResource.class,
+                          PortPairWebResource.class,
+                          FloatingIpWebResource.class,
+                          RouterWebResource.class);
+    }
+}
+
diff --git a/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml b/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml
index 3b8d5d7..abc83e4 100644
--- a/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml
+++ b/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml
@@ -42,41 +42,17 @@
     -->
 
     <servlet>
-        <servlet-name>VTNRSC JAX-RS Service</servlet-name>
+        <servlet-name>JAX-RS Service</servlet-name>
         <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
         <init-param>
-            <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
-            <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
-        </init-param>
-        <init-param>
-            <param-name>com.sun.jersey.config.property.classnames</param-name>
-            <param-value>
-                org.onosproject.rest.exceptions.EntityNotFoundMapper,
-                org.onosproject.rest.exceptions.ServiceNotFoundMapper,
-                org.onosproject.rest.exceptions.NotFoundMapper,
-                org.onosproject.rest.exceptions.ServerErrorMapper,
-                org.onosproject.rest.exceptions.BadRequestMapper,
-                org.onosproject.rest.exceptions.WebApplicationExceptionMapper,
-                org.onosproject.rest.exceptions.IllegalArgumentExceptionMapper,
-                org.onosproject.rest.exceptions.IllegalStateExceptionMapper,
-                org.onosproject.rest.resources.JsonBodyWriter,
-
-                org.onosproject.vtnweb.resources.TenantNetworkWebResource,
-                org.onosproject.vtnweb.resources.SubnetWebResource,
-                org.onosproject.vtnweb.resources.VirtualPortWebResource,
-                org.onosproject.vtnweb.resources.FlowClassifierWebResource,
-                org.onosproject.vtnweb.resources.PortChainWebResource,
-                org.onosproject.vtnweb.resources.PortPairGroupWebResource,
-                org.onosproject.vtnweb.resources.PortPairWebResource,
-                org.onosproject.vtnweb.resources.FloatingIpWebResource,
-                org.onosproject.vtnweb.resources.RouterWebResource
-            </param-value>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.onosproject.vtnweb.resources.VtnWebApplication</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>
 
     <servlet-mapping>
-        <servlet-name>VTNRSC JAX-RS Service</servlet-name>
+        <servlet-name>JAX-RS Service</servlet-name>
         <url-pattern>/*</url-pattern>
     </servlet-mapping>
 </web-app>
diff --git a/utils/rest/pom.xml b/utils/rest/pom.xml
index c9a7df7..990391a 100644
--- a/utils/rest/pom.xml
+++ b/utils/rest/pom.xml
@@ -33,6 +33,25 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-misc</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-osgi</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>com.sun.jersey.jersey-test-framework</groupId>
             <artifactId>jersey-test-framework-core</artifactId>
             <scope>test</scope>
@@ -42,12 +61,6 @@
             <artifactId>jersey-test-framework-grizzly2</artifactId>
             <scope>test</scope>
         </dependency>
-
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onlab-osgi</artifactId>
-            <version>${project.version}</version>
-        </dependency>
     </dependencies>
 
 </project>
diff --git a/utils/rest/src/main/java/org/onlab/rest/AbstractWebApplication.java b/utils/rest/src/main/java/org/onlab/rest/AbstractWebApplication.java
new file mode 100644
index 0000000..5d6b06d
--- /dev/null
+++ b/utils/rest/src/main/java/org/onlab/rest/AbstractWebApplication.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onlab.rest;
+
+import com.google.common.collect.ImmutableSet;
+import org.onlab.rest.exceptions.BadRequestMapper;
+import org.onlab.rest.exceptions.EntityNotFoundMapper;
+import org.onlab.rest.exceptions.IllegalArgumentExceptionMapper;
+import org.onlab.rest.exceptions.IllegalStateExceptionMapper;
+import org.onlab.rest.exceptions.NotFoundMapper;
+import org.onlab.rest.exceptions.ServerErrorMapper;
+import org.onlab.rest.exceptions.ServiceNotFoundMapper;
+import org.onlab.rest.exceptions.WebApplicationExceptionMapper;
+
+import javax.ws.rs.core.Application;
+import java.util.Set;
+
+/**
+ * Base web application.
+ */
+public abstract class AbstractWebApplication extends Application {
+
+    /**
+     * Returns the aggregate set of resources, writers and mappers combined
+     * with a default set of such web entities.
+     *
+     * @param classes set of resources, writers and mappers
+     * @return combined set of web entities
+     */
+    protected Set<Class<?>> getClasses(Class<?>... classes) {
+        ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder();
+        builder.add(ServiceNotFoundMapper.class,
+                    EntityNotFoundMapper.class,
+                    NotFoundMapper.class,
+                    ServerErrorMapper.class,
+                    BadRequestMapper.class,
+                    WebApplicationExceptionMapper.class,
+                    IllegalArgumentExceptionMapper.class,
+                    IllegalStateExceptionMapper.class,
+                    JsonBodyWriter.class);
+        builder.add(classes);
+        return builder.build();
+    }
+
+    @Override
+    public abstract Set<Class<?>> getClasses();
+
+}
diff --git a/utils/rest/src/main/java/org/onlab/rest/JsonBodyWriter.java b/utils/rest/src/main/java/org/onlab/rest/JsonBodyWriter.java
new file mode 100644
index 0000000..8e14167
--- /dev/null
+++ b/utils/rest/src/main/java/org/onlab/rest/JsonBodyWriter.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onlab.rest;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+/**
+ * JAX-RS Response message body writer.
+ */
+@Provider
+@Produces("application/json")
+public class JsonBodyWriter implements MessageBodyWriter<ObjectNode> {
+
+    private ObjectMapper mapper = new ObjectMapper();
+
+    @Override
+    public boolean isWriteable(Class<?> type, Type genericType,
+                               Annotation[] annotations, MediaType mediaType) {
+        return type == ObjectNode.class;
+    }
+
+    @Override
+    public long getSize(ObjectNode node, Class<?> type, Type genericType,
+                        Annotation[] annotations, MediaType mediaType) {
+        return -1;
+    }
+
+    @Override
+    public void writeTo(ObjectNode node, Class<?> type, Type genericType,
+                        Annotation[] annotations, MediaType mediaType,
+                        MultivaluedMap<String, Object> httpHeaders,
+                        OutputStream entityStream) throws IOException {
+        mapper.writer().writeValue(entityStream, node);
+        entityStream.flush();
+    }
+}
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/AbstractMapper.java
similarity index 98%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/AbstractMapper.java
index 0d9d94d..fa94c2d 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/AbstractMapper.java
@@ -13,7 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
+
+package org.onlab.rest.exceptions;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/BadRequestMapper.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/BadRequestMapper.java
similarity index 91%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/BadRequestMapper.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/BadRequestMapper.java
index 89b1368..10cbbea 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/BadRequestMapper.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/BadRequestMapper.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2014-2015 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
+
+package org.onlab.rest.exceptions;
 
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.Provider;
-
 import java.io.IOException;
 
 /**
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/EntityNotFoundMapper.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/EntityNotFoundMapper.java
similarity index 95%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/EntityNotFoundMapper.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/EntityNotFoundMapper.java
index 9e42a56..4a2a9ae 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/EntityNotFoundMapper.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/EntityNotFoundMapper.java
@@ -13,7 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
+
+package org.onlab.rest.exceptions;
 
 import org.onlab.util.ItemNotFoundException;
 
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/IllegalArgumentExceptionMapper.java
similarity index 95%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/IllegalArgumentExceptionMapper.java
index 2d7a1ea..5d607a8 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/IllegalArgumentExceptionMapper.java
@@ -13,7 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
+
+package org.onlab.rest.exceptions;
 
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.Provider;
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalStateExceptionMapper.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/IllegalStateExceptionMapper.java
similarity index 91%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/IllegalStateExceptionMapper.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/IllegalStateExceptionMapper.java
index a9f977c..3f50f00 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalStateExceptionMapper.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/IllegalStateExceptionMapper.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2014-2015 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
+
+package org.onlab.rest.exceptions;
 
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.Provider;
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/NotFoundMapper.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/NotFoundMapper.java
similarity index 91%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/NotFoundMapper.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/NotFoundMapper.java
index 2bf3614..9d833a6 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/NotFoundMapper.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/NotFoundMapper.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2014-2015 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
+
+package org.onlab.rest.exceptions;
+
+import com.sun.jersey.api.NotFoundException;
 
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.Provider;
 
-import com.sun.jersey.api.NotFoundException;
-
 /**
  * Mapper for api not found exceptions to the NOT_FOUND response code.
  */
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/ServerErrorMapper.java
similarity index 96%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/ServerErrorMapper.java
index 778750e..0d87fb8 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/ServerErrorMapper.java
@@ -13,13 +13,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
+
+package org.onlab.rest.exceptions;
+
+import org.slf4j.Logger;
 
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.Provider;
 
-import org.slf4j.Logger;
-
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/ServiceNotFoundMapper.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/ServiceNotFoundMapper.java
similarity index 95%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/ServiceNotFoundMapper.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/ServiceNotFoundMapper.java
index 69e5508..6dc4f2e 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/ServiceNotFoundMapper.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/ServiceNotFoundMapper.java
@@ -13,7 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
+
+package org.onlab.rest.exceptions;
 
 import org.onlab.osgi.ServiceNotFoundException;
 
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/WebApplicationExceptionMapper.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/WebApplicationExceptionMapper.java
similarity index 94%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/WebApplicationExceptionMapper.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/WebApplicationExceptionMapper.java
index 86d8434..8ad6ee9 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/WebApplicationExceptionMapper.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/WebApplicationExceptionMapper.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2014-2015 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.rest.exceptions;
+
+package org.onlab.rest.exceptions;
 
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/package-info.java b/utils/rest/src/main/java/org/onlab/rest/exceptions/package-info.java
similarity index 87%
rename from web/api/src/main/java/org/onosproject/rest/exceptions/package-info.java
rename to utils/rest/src/main/java/org/onlab/rest/exceptions/package-info.java
index 6b581bc..24357f0 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/package-info.java
+++ b/utils/rest/src/main/java/org/onlab/rest/exceptions/package-info.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Open Networking Laboratory
+ * Copyright 2014-2015 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,4 +17,4 @@
 /**
  * Various exception mappers to map errors to proper response status codes.
  */
-package org.onosproject.rest.exceptions;
+package org.onlab.rest.exceptions;
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/CoreWebApplication.java b/web/api/src/main/java/org/onosproject/rest/resources/CoreWebApplication.java
new file mode 100644
index 0000000..44ad52a
--- /dev/null
+++ b/web/api/src/main/java/org/onosproject/rest/resources/CoreWebApplication.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.rest.resources;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * Core REST APIs web application.
+ */
+public class CoreWebApplication extends AbstractWebApplication {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        return getClasses(ApiDocResource.class,
+                          ApplicationsWebResource.class,
+                          ComponentConfigWebResource.class,
+                          NetworkConfigWebResource.class,
+                          ClusterWebResource.class,
+                          DevicesWebResource.class,
+                          LinksWebResource.class,
+                          HostsWebResource.class,
+                          IntentsWebResource.class,
+                          FlowsWebResource.class,
+                          TopologyWebResource.class,
+                          ConfigWebResource.class,
+                          PathsWebResource.class,
+                          StatisticsWebResource.class
+        );
+    }
+}
diff --git a/web/api/src/main/webapp/WEB-INF/web.xml b/web/api/src/main/webapp/WEB-INF/web.xml
index e3382fc..c6b02f1 100644
--- a/web/api/src/main/webapp/WEB-INF/web.xml
+++ b/web/api/src/main/webapp/WEB-INF/web.xml
@@ -45,37 +45,8 @@
         <servlet-name>JAX-RS Service</servlet-name>
         <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
         <init-param>
-            <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
-            <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
-        </init-param>
-        <init-param>
-            <param-name>com.sun.jersey.config.property.classnames</param-name>
-            <param-value>
-                org.onosproject.rest.exceptions.EntityNotFoundMapper,
-                org.onosproject.rest.exceptions.ServiceNotFoundMapper,
-                org.onosproject.rest.exceptions.NotFoundMapper,
-                org.onosproject.rest.exceptions.ServerErrorMapper,
-                org.onosproject.rest.exceptions.BadRequestMapper,
-                org.onosproject.rest.exceptions.WebApplicationExceptionMapper,
-                org.onosproject.rest.exceptions.IllegalArgumentExceptionMapper,
-                org.onosproject.rest.exceptions.IllegalStateExceptionMapper,
-                org.onosproject.rest.resources.JsonBodyWriter,
-
-                org.onosproject.rest.resources.ApiDocResource,
-                org.onosproject.rest.resources.ApplicationsWebResource,
-                org.onosproject.rest.resources.ComponentConfigWebResource,
-                org.onosproject.rest.resources.NetworkConfigWebResource,
-                org.onosproject.rest.resources.ClusterWebResource,
-                org.onosproject.rest.resources.DevicesWebResource,
-                org.onosproject.rest.resources.LinksWebResource,
-                org.onosproject.rest.resources.HostsWebResource,
-                org.onosproject.rest.resources.IntentsWebResource,
-                org.onosproject.rest.resources.FlowsWebResource,
-                org.onosproject.rest.resources.TopologyWebResource,
-                org.onosproject.rest.resources.ConfigWebResource,
-                org.onosproject.rest.resources.PathsWebResource,
-                org.onosproject.rest.resources.StatisticsWebResource
-            </param-value>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.onosproject.rest.resources.CoreWebApplication</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>
diff --git a/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
index 33ee931..ddbf197 100644
--- a/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
@@ -15,13 +15,12 @@
  */
 package org.onosproject.rest;
 
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.util.Collections;
-import java.util.HashSet;
-
-import javax.ws.rs.core.MediaType;
-
+import com.eclipsesource.json.JsonArray;
+import com.eclipsesource.json.JsonObject;
+import com.eclipsesource.json.JsonValue;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.client.WebResource;
 import org.hamcrest.Description;
 import org.hamcrest.Matchers;
 import org.hamcrest.TypeSafeMatcher;
@@ -44,24 +43,16 @@
 import org.onosproject.net.intent.IntentState;
 import org.onosproject.net.intent.Key;
 import org.onosproject.net.intent.MockIdGenerator;
+import org.onosproject.rest.resources.CoreWebApplication;
 
-import com.eclipsesource.json.JsonArray;
-import com.eclipsesource.json.JsonObject;
-import com.eclipsesource.json.JsonValue;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
+import javax.ws.rs.core.MediaType;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.util.Collections;
+import java.util.HashSet;
 
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.Matchers.*;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 import static org.onosproject.net.intent.IntentTestsMocks.MockIntent;
@@ -76,6 +67,10 @@
     private static final ApplicationId APP_ID = new DefaultApplicationId(1, "test");
     private IdGenerator mockGenerator;
 
+    public IntentsResourceTest() {
+        super(CoreWebApplication.class);
+    }
+
     private class MockResource implements NetworkResource {
         int id;
 
diff --git a/web/api/src/test/java/org/onosproject/rest/ResourceTest.java b/web/api/src/test/java/org/onosproject/rest/ResourceTest.java
index d88b84a6..3308f3c 100644
--- a/web/api/src/test/java/org/onosproject/rest/ResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/ResourceTest.java
@@ -18,6 +18,7 @@
 import java.io.IOException;
 import java.net.ServerSocket;
 
+import com.sun.jersey.spi.container.servlet.ServletContainer;
 import com.sun.jersey.test.framework.AppDescriptor;
 import com.sun.jersey.test.framework.JerseyTest;
 import com.sun.jersey.test.framework.WebAppDescriptor;
@@ -28,6 +29,23 @@
 public class ResourceTest extends JerseyTest {
 
     /**
+     * Creates a new web-resource test.
+     */
+    public ResourceTest() {
+        super();
+    }
+
+    /**
+     * Creates a new web-resource test initialized according to the specified
+     * web application class.
+     */
+    protected ResourceTest(Class<?> webAppClass) {
+        super(new WebAppDescriptor.Builder("javax.ws.rs.Application",
+                                           webAppClass.getCanonicalName())
+                      .servletClass(ServletContainer.class).build());
+    }
+
+    /**
      * Assigns an available port for the test.
      *
      * @param defaultPort If a port cannot be determined, this one is used.
diff --git a/web/api/src/test/java/org/onosproject/rest/exceptions/ExceptionMapperTest.java b/web/api/src/test/java/org/onosproject/rest/exceptions/ExceptionMapperTest.java
deleted file mode 100644
index 779966a..0000000
--- a/web/api/src/test/java/org/onosproject/rest/exceptions/ExceptionMapperTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.rest.exceptions;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Set of tests for the various exception mappers.
- */
-public class ExceptionMapperTest {
-
-    @Test
-    public void emptyMessage() {
-        RuntimeException exception = new NullPointerException();
-        ServerErrorMapper mapper = new ServerErrorMapper();
-        Object response = mapper.toResponse(exception).getEntity();
-        assertTrue("incorrect response",
-                   response.toString().contains("ExceptionMapperTest.emptyMessage("));
-    }
-}
\ No newline at end of file
diff --git a/web/api/src/test/java/org/onosproject/rest/resources/NetworkConfigWebResourceTest.java b/web/api/src/test/java/org/onosproject/rest/resources/NetworkConfigWebResourceTest.java
index 2b341af..40470d9 100644
--- a/web/api/src/test/java/org/onosproject/rest/resources/NetworkConfigWebResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/resources/NetworkConfigWebResourceTest.java
@@ -189,6 +189,10 @@
         }
     }
 
+    public NetworkConfigWebResourceTest() {
+        super(CoreWebApplication.class);
+    }
+
     /**
      * Sets up mocked config service.
      */