ONOS-887 - Return a 404 status when a URL specifies a bad resource

Change-Id: I145ae65076d54ec50f7627a50307c975df8f2c0a
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
new file mode 100644
index 0000000..1c4135e
--- /dev/null
+++ b/web/api/src/main/java/org/onosproject/rest/exceptions/NotFoundMapper.java
@@ -0,0 +1,32 @@
+/*
+ * 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 com.sun.jersey.api.NotFoundException;
+
+/**
+ * Mapper for api not found exceptions to the NOT_FOUND response code.
+ */
+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
index 43e9542..3767cd2 100644
--- a/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java
+++ b/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java
@@ -18,7 +18,7 @@
 import javax.ws.rs.core.Response;
 
 /**
- * Mapper for service not found exceptions to the NOT_FOUND response code.
+ * Mapper for service not found exceptions to the INTERNAL_SERVER_ERROR response code.
  */
 public class ServerErrorMapper extends AbstractMapper<RuntimeException> {
     @Override
diff --git a/web/api/src/main/webapp/WEB-INF/web.xml b/web/api/src/main/webapp/WEB-INF/web.xml
index e0e4737..389ad94 100644
--- a/web/api/src/main/webapp/WEB-INF/web.xml
+++ b/web/api/src/main/webapp/WEB-INF/web.xml
@@ -32,6 +32,7 @@
             <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.JsonBodyWriter,
 
diff --git a/web/api/src/test/java/org/onosproject/rest/BadRequestTest.java b/web/api/src/test/java/org/onosproject/rest/BadRequestTest.java
new file mode 100644
index 0000000..1e5e7c4
--- /dev/null
+++ b/web/api/src/test/java/org/onosproject/rest/BadRequestTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import org.junit.Test;
+
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.client.WebResource;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * Unit tests for bad REST requests.
+ */
+public class BadRequestTest extends ResourceTest {
+    @Test
+    public void badUrl() {
+        WebResource rs = resource();
+        try {
+            rs.path("ThisIsABadURL").get(String.class);
+            fail("Fetch of non-existent URL did not throw an exception");
+        } catch (UniformInterfaceException ex) {
+            assertThat(ex.getMessage(),
+                    containsString("returned a response status of 404 Not Found"));
+        }
+    }
+}
diff --git a/web/pom.xml b/web/pom.xml
index a5e3c47..bd6e5fd 100644
--- a/web/pom.xml
+++ b/web/pom.xml
@@ -122,7 +122,7 @@
                             org.slf4j,
                             org.osgi.framework,
                             javax.ws.rs,javax.ws.rs.core,javax.ws.rs.ext,
-                            com.sun.jersey.api.core,
+                            com.sun.jersey.api,
                             com.sun.jersey.spi.container.servlet,
                             com.sun.jersey.server.impl.container.servlet,
                             com.fasterxml.jackson.databind,