X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fstaticrouting%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwarding%2Fstaticrouting%2Fnorthbound%2FStaticRoutingNorthbound.java;h=20f6cb40a56cb812fa5370a5dd01cc6bf2ef85e8;hb=refs%2Fchanges%2F10%2F7610%2F5;hp=07f125dae3f79a8428d7609a18c1f4194b2553a1;hpb=1415e57c132459f962afcc976da3b72c28a5702b;p=controller.git diff --git a/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java b/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java index 07f125dae3..20f6cb40a5 100644 --- a/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java +++ b/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java @@ -15,17 +15,17 @@ import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; -import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; import javax.ws.rs.core.UriInfo; -import javax.xml.bind.JAXBElement; +import javax.ws.rs.ext.ContextResolver; import org.codehaus.enunciate.jaxrs.ResponseCode; import org.codehaus.enunciate.jaxrs.StatusCodes; @@ -39,6 +39,7 @@ import org.opendaylight.controller.northbound.commons.exception.NotAcceptableExc import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException; import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException; +import org.opendaylight.controller.northbound.commons.query.QueryContext; import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils; import org.opendaylight.controller.sal.authorization.Privilege; import org.opendaylight.controller.sal.utils.GlobalConstants; @@ -57,7 +58,12 @@ import org.opendaylight.controller.sal.utils.Status; * HTTP/1.1 200 OK * Content-Type: application/json * - * {"staticRoute":{"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"}} + * { "staticRoute":[ + * "name":"route-1", + * "prefix":"10.10.1.0/24", + * "nextHop":"1.1.1.1" + * ] + * } * * * @@ -71,6 +77,14 @@ import org.opendaylight.controller.sal.utils.Status; public class StaticRoutingNorthbound { private String username; + private QueryContext queryContext; + + @Context + public void setQueryContext(ContextResolver queryCtxResolver) { + if (queryCtxResolver != null) { + queryContext = queryCtxResolver.getContext(QueryContext.class); + } + } @Context public void setSecurityContext(SecurityContext context) { @@ -114,9 +128,9 @@ public class StaticRoutingNorthbound { * Example: * * Request URL: - * GET http://localhost:8080/controller/nb/v2/staticroute/default/routes + * http://localhost:8080/controller/nb/v2/staticroute/default/routes * - * Response in XML: + * Response body in XML: * <list> * <staticRoute> * <name>route-1</name> @@ -125,9 +139,16 @@ public class StaticRoutingNorthbound { * </staticRoute> * </list> * - * Response in JSON: - * {"staticRoute":{"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"}} - * + * Response body in JSON: + * { + * "staticRoute": [ + * { + * "name": "route-1", + * "prefix": "10.10.1.0/24", + * "nextHop": "1.1.1.1" + * } + * ] + * } * */ @Path("/{containerName}/routes") @@ -138,7 +159,8 @@ public class StaticRoutingNorthbound { @ResponseCode(code = 200, condition = "Operation successful"), @ResponseCode(code = 404, condition = "The containerName passed was not found") }) public StaticRoutes getStaticRoutes( - @PathParam("containerName") String containerName) { + @PathParam("containerName") String containerName, + @QueryParam("_q") String queryString) { if(!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)){ @@ -146,7 +168,12 @@ public class StaticRoutingNorthbound { UnauthorizedException("User is not authorized to perform this operation on container " + containerName); } - return new StaticRoutes(getStaticRoutesInternal(containerName)); + StaticRoutes result = new StaticRoutes(getStaticRoutesInternal(containerName)); + if (queryString != null) { + queryContext.createQuery(queryString, StaticRoutes.class) + .filter(result, StaticRoute.class); + } + return result; } /** @@ -160,9 +187,9 @@ public class StaticRoutingNorthbound { * Example: * * Request URL: - * GET http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 + * http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 * - * Response in XML: + * Response body in XML: * * <staticRoute> * <name>route-1</name> @@ -170,8 +197,12 @@ public class StaticRoutingNorthbound { * <nextHop>1.1.1.1</nextHop> * </staticRoute> * - * Response in JSON: - * {"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"} + * Response body in JSON: + * { + * "name":"route-1", + * "prefix":"10.10.1.0/24", + * "nextHop":"1.1.1.1" + * } * * */ @@ -216,11 +247,20 @@ public class StaticRoutingNorthbound { * Example: * * Request URL: - * PUT http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 - * - * Request payload in JSON: - * {"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"} + * http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 * + * Request body in XML: + * <staticRoute> + * <name>route-1</name> + * <prefix>10.10.1.0/24</prefix> + * <nextHop>1.1.1.1</nextHop> + * </staticRoute> + * Request body in JSON: + * { + * "name":"route-1", + * "prefix":"10.10.1.0/24", + * "nextHop":"1.1.1.1" + * } * */ @Path("/{containerName}/route/{route}")