Ray Milkey

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

Change-Id: I145ae65076d54ec50f7627a50307c975df8f2c0a
/*
* 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;
}
}
......@@ -18,7 +18,7 @@ package org.onosproject.rest.exceptions;
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
......
......@@ -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,
......
/*
* 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"));
}
}
}
......@@ -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,
......