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;
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;
* 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"
+ * ]
+ * }
*
* </pre>
*
public class StaticRoutingNorthbound {
private String username;
+ private QueryContext queryContext;
+
+ @Context
+ public void setQueryContext(ContextResolver<QueryContext> queryCtxResolver) {
+ if (queryCtxResolver != null) {
+ queryContext = queryCtxResolver.getContext(QueryContext.class);
+ }
+ }
@Context
public void setSecurityContext(SecurityContext context) {
* 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>
* </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"
+ * }
+ * ]
+ * }
* </pre>
*/
@Path("/{containerName}/routes")
@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)){
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;
}
/**
* 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>
* <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"
+ * }
*
* </pre>
*/
* 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"
+ * }
* </pre>
*/
@Path("/{containerName}/route/{route}")