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/AbstractMapper.java b/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java
deleted file mode 100644
index 0d9d94d..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.exceptions;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
-
-import static com.google.common.base.Strings.isNullOrEmpty;
-
-/**
- * Base exception mapper implementation.
- */
-public abstract class AbstractMapper<E extends Throwable> implements ExceptionMapper<E> {
-
-    /**
-     * Holds the current exception for use in subclasses.
-     */
-    protected Throwable error;
-
-    /**
-     * Returns the response status to be given when the exception occurs.
-     *
-     * @return response status
-     */
-    protected abstract Response.Status responseStatus();
-
-    @Override
-    public Response toResponse(E exception) {
-        error = exception;
-        return response(responseStatus(), exception).build();
-    }
-
-    /**
-     * Produces a response builder primed with the supplied status code
-     * and JSON entity with the status code and exception message.
-     *
-     * @param status    response status
-     * @param exception exception to encode
-     * @return response builder
-     */
-    protected Response.ResponseBuilder response(Response.Status status,
-                                                Throwable exception) {
-        error = exception;
-        ObjectMapper mapper = new ObjectMapper();
-        String message = messageFrom(exception);
-        ObjectNode result = mapper.createObjectNode()
-                .put("code", status.getStatusCode())
-                .put("message", message);
-        return Response.status(status).entity(result.toString());
-    }
-
-    /**
-     * Produces a response message from the supplied exception. Either it will
-     * use the exception message, if there is one, or it will use the top
-     * stack-frame message.
-     *
-     * @param exception exception from which to produce a message
-     * @return response message
-     */
-    protected String messageFrom(Throwable exception) {
-        if (isNullOrEmpty(exception.getMessage())) {
-            StackTraceElement[] trace = exception.getStackTrace();
-            return trace.length == 0 ? "Unknown error" : trace[0].toString();
-        }
-        return exception.getMessage();
-    }
-
-}
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/BadRequestMapper.java b/web/api/src/main/java/org/onosproject/rest/exceptions/BadRequestMapper.java
deleted file mode 100644
index 89b1368..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/BadRequestMapper.java
+++ /dev/null
@@ -1,32 +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 javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-import java.io.IOException;
-
-/**
- * Mapper for IO exceptions to the BAD_REQUEST response code.
- */
-@Provider
-public class BadRequestMapper extends AbstractMapper<IOException> {
-    @Override
-    protected Response.Status responseStatus() {
-        return Response.Status.BAD_REQUEST;
-    }
-}
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/EntityNotFoundMapper.java b/web/api/src/main/java/org/onosproject/rest/exceptions/EntityNotFoundMapper.java
deleted file mode 100644
index 9e42a56..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/EntityNotFoundMapper.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.exceptions;
-
-import org.onlab.util.ItemNotFoundException;
-
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Mapper for service not found exceptions to the NOT_FOUND response code.
- */
-@Provider
-public class EntityNotFoundMapper extends AbstractMapper<ItemNotFoundException> {
-    @Override
-    protected Response.Status responseStatus() {
-        return Response.Status.NOT_FOUND;
-    }
-}
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java b/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java
deleted file mode 100644
index 2d7a1ea..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.exceptions;
-
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Mapper for illegal argument exceptions to the BAD_REQUEST response code.
- */
-@Provider
-public class IllegalArgumentExceptionMapper extends AbstractMapper<IllegalArgumentException> {
-    @Override
-    protected Response.Status responseStatus() {
-        return Response.Status.BAD_REQUEST;
-    }
-}
-
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalStateExceptionMapper.java b/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalStateExceptionMapper.java
deleted file mode 100644
index a9f977c..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalStateExceptionMapper.java
+++ /dev/null
@@ -1,31 +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 javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Mapper for illegal state exceptions to the BAD_REQUEST response code.
- */
-@Provider
-public class IllegalStateExceptionMapper extends AbstractMapper<IllegalStateException> {
-    @Override
-    protected Response.Status responseStatus() {
-        return Response.Status.CONFLICT;
-    }
-}
-
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/NotFoundMapper.java b/web/api/src/main/java/org/onosproject/rest/exceptions/NotFoundMapper.java
deleted file mode 100644
index 2bf3614..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/NotFoundMapper.java
+++ /dev/null
@@ -1,34 +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 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.
- */
-@Provider
-public class NotFoundMapper extends AbstractMapper<NotFoundException> {
-
-    @Override
-    protected Response.Status responseStatus() {
-        return Response.Status.NOT_FOUND;
-    }
-
-}
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java b/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java
deleted file mode 100644
index 778750e..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.exceptions;
-
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-import org.slf4j.Logger;
-
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Mapper for service not found exceptions to the INTERNAL_SERVER_ERROR response code.
- */
-@Provider
-public class ServerErrorMapper extends AbstractMapper<RuntimeException> {
-    private static final Logger log = getLogger(ServerErrorMapper.class);
-    @Override
-    protected Response.Status responseStatus() {
-        log.warn("Unhandled REST exception", error);
-        return Response.Status.INTERNAL_SERVER_ERROR;
-    }
-}
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/ServiceNotFoundMapper.java b/web/api/src/main/java/org/onosproject/rest/exceptions/ServiceNotFoundMapper.java
deleted file mode 100644
index 69e5508..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/ServiceNotFoundMapper.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.exceptions;
-
-import org.onlab.osgi.ServiceNotFoundException;
-
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Mapper for service not found exceptions to the SERVICE_UNAVAILABLE response code.
- */
-@Provider
-public class ServiceNotFoundMapper extends AbstractMapper<ServiceNotFoundException> {
-    @Override
-    protected Response.Status responseStatus() {
-        return Response.Status.SERVICE_UNAVAILABLE;
-    }
-}
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/WebApplicationExceptionMapper.java b/web/api/src/main/java/org/onosproject/rest/exceptions/WebApplicationExceptionMapper.java
deleted file mode 100644
index 86d8434..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/WebApplicationExceptionMapper.java
+++ /dev/null
@@ -1,45 +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 javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Exception mapper for WebApplicationExceptions.
- */
-@Provider
-public class WebApplicationExceptionMapper extends AbstractMapper<WebApplicationException> {
-
-    /**
-     * Extracts and returns the response from a WebApplicationException.
-     *
-     * @param e WebApplicationException that was thrown
-     * @return precomputed Response from the exception
-     */
-    @Override
-    public Response toResponse(WebApplicationException e) {
-        return e.getResponse();
-    }
-
-    @Override
-    public Response.Status responseStatus() {
-        // This should never be called because this class overrides toResponse()
-        throw new UnsupportedOperationException(
-                "responseStatus() for a WebApplicationException should never be called");
-    }
-}
diff --git a/web/api/src/main/java/org/onosproject/rest/exceptions/package-info.java b/web/api/src/main/java/org/onosproject/rest/exceptions/package-info.java
deleted file mode 100644
index 6b581bc..0000000
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2014 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.
- */
-
-/**
- * Various exception mappers to map errors to proper response status codes.
- */
-package org.onosproject.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.
      */