From: Alessandro Boch Date: Tue, 20 Aug 2013 23:36:45 +0000 (-0700) Subject: Enhancements to common.northbound X-Git-Tag: releasepom-0.1.0~190^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=094f267fa6b824cd11e449f105370d20e413f66f Enhancements to common.northbound - Added BadRequest and NotImplemented exceptions Change-Id: I9a021ddd103c16122c39626e9cca044bd8a33ea6 Signed-off-by: Alessandro Boch --- diff --git a/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/RestMessages.java b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/RestMessages.java index ebe36a9d78..668efbc7ee 100644 --- a/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/RestMessages.java +++ b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/RestMessages.java @@ -9,17 +9,13 @@ package org.opendaylight.controller.northbound.commons; public enum RestMessages { - SUCCESS("Success"), NOCONTAINER("Container does not exist"), NOFLOWSPEC( - "Flow Spec does not exist"), NOSUBNET("Subnet does not exist"), NOSTATICROUTE( - "Static Route does not exist"), NOHOST("Host does not exist"), NOFLOW( - "Flow does not exist"), NONODE("Node does not exist"), NOPOLICY( - "Policy does not exist"), NORESOURCE("Resource does not exist"), RESOURCECONFLICT( - "Operation failed due to Resource Conflict"), NODEFAULT( - "Container default is not a custom container"), DEFAULTDISABLED( + SUCCESS("Success"), NOCONTAINER("Container does not exist"), NOSUBNET("Subnet does not exist"), NOSTATICROUTE( + "Static Route does not exist"), NOHOST("Host does not exist"), NOFLOW("Flow does not exist"), NONODE( + "Node does not exist"), NOPOLICY("Policy does not exist"), NORESOURCE("Resource does not exist"), RESOURCECONFLICT( + "Operation failed due to Resource Conflict"), NODEFAULT("Container default is not a custom container"), DEFAULTDISABLED( "Container(s) are configured. Container default is not operational"), NOTALLOWEDONDEFAULT( - "Container default is a static resource, no modification allowed on it"), UNKNOWNACTION( - "Unknown action"), INVALIDJSON("JSON message is invalid"), INVALIDADDRESS( - "invalid InetAddress"), AVAILABLESOON( + "Container default is a static resource, no modification allowed on it"), UNKNOWNACTION("Unknown action"), INVALIDJSON( + "JSON message is invalid"), INVALIDADDRESS("invalid InetAddress"), AVAILABLESOON( "Resource is not implemented yet"), INTERNALERROR("Internal Error"), SERVICEUNAVAILABLE( "Service is not available. Could be down for maintanence"), INVALIDDATA( "Data is invalid or conflicts with URI"); @@ -30,6 +26,7 @@ public enum RestMessages { message = msg; } + @Override public String toString() { return message; } diff --git a/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/BadRequestException.java b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/BadRequestException.java new file mode 100644 index 0000000000..c1b832d3c6 --- /dev/null +++ b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/BadRequestException.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.northbound.commons.exception; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * Status Code 400 (Bad Request) + * + * The request could not be understood by the server due to malformed syntax. + * The client SHOULD NOT repeat the request without modifications. + */ +public class BadRequestException extends WebApplicationException { + private static final long serialVersionUID = 1L; + + public BadRequestException(String string) { + super(Response.status(Response.Status.BAD_REQUEST).entity(string).type(MediaType.TEXT_PLAIN).build()); + } +} diff --git a/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/NotImplemented.java b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/NotImplemented.java new file mode 100644 index 0000000000..16d0cd6e29 --- /dev/null +++ b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/NotImplemented.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.northbound.commons.exception; + +import javax.ws.rs.core.Response; + +/** + * Implementation of StatusType for error 501 as in: + * http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6 + */ +public class NotImplemented implements Response.StatusType { + @Override + public int getStatusCode() { + return 501; + } + + @Override + public String getReasonPhrase() { + return "Not Implemented"; + } + + @Override + public Response.Status.Family getFamily() { + return Response.Status.Family.SERVER_ERROR; + } +} \ No newline at end of file diff --git a/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/NotImplementedException.java b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/NotImplementedException.java new file mode 100644 index 0000000000..5c931d2b47 --- /dev/null +++ b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/NotImplementedException.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.northbound.commons.exception; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * Status Code 501 (Not Implemented) + * + * The server does not support the functionality required to fulfill the + * request. This is the appropriate response when the server does not recognize + * the request method and is not capable of supporting it for any resource. + */ +public class NotImplementedException extends WebApplicationException { + private static final long serialVersionUID = 1L; + + public NotImplementedException(String string) { + super(Response.status(new NotImplemented()).entity(string).type(MediaType.TEXT_PLAIN).build()); + } +}