diff options
author | CNlucius <lukai1@huawei.com> | 2016-09-13 11:40:12 +0800 |
---|---|---|
committer | CNlucius <lukai1@huawei.com> | 2016-09-13 11:41:53 +0800 |
commit | b731e2f1dd0972409b136aebc7b463dd72c9cfad (patch) | |
tree | 5107d7d80c19ad8076c2c97c2b5ef8d1cf3ab903 /framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions | |
parent | ee93993458266114c29271a481ef9ce7ce621b2a (diff) |
ONOSFW-171
O/S-SFC-ONOS scenario documentation
Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365
Signed-off-by: CNlucius <lukai1@huawei.com>
Diffstat (limited to 'framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions')
10 files changed, 0 insertions, 377 deletions
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java deleted file mode 100644 index 0d9d94d3..00000000 --- a/framework/src/onos/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/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/BadRequestMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/BadRequestMapper.java deleted file mode 100644 index 89b13685..00000000 --- a/framework/src/onos/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/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/EntityNotFoundMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/EntityNotFoundMapper.java deleted file mode 100644 index 9e42a56e..00000000 --- a/framework/src/onos/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/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalArgumentExceptionMapper.java deleted file mode 100644 index 2d7a1eae..00000000 --- a/framework/src/onos/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/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalStateExceptionMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/IllegalStateExceptionMapper.java deleted file mode 100644 index a9f977ce..00000000 --- a/framework/src/onos/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/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/NotFoundMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/NotFoundMapper.java deleted file mode 100644 index 2bf3614d..00000000 --- a/framework/src/onos/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/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java deleted file mode 100644 index 778750e6..00000000 --- a/framework/src/onos/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/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/ServiceNotFoundMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/ServiceNotFoundMapper.java deleted file mode 100644 index 69e55088..00000000 --- a/framework/src/onos/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/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/WebApplicationExceptionMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/WebApplicationExceptionMapper.java deleted file mode 100644 index 86d8434f..00000000 --- a/framework/src/onos/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/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/package-info.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/package-info.java deleted file mode 100644 index 6b581bc7..00000000 --- a/framework/src/onos/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; |