From b46c9fb932498804e5ba2469720062870333e1d6 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Wed, 16 Jan 2013 08:28:37 +0100 Subject: [PATCH] Support AcceptsCreate for ChildCollection If a RestCollection implements AcceptsCreate the create method should be invoked when the parse method throws a ResourceNotFoundException. This was only the case for a top level RestCollection but not for a ChildCollection. Change-Id: Idbf2bd1cbff64b515713e0e76f0f75e4e710b2c8 Signed-off-by: Edwin Kempin --- .../gerrit/httpd/restapi/RestApiServlet.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java index 715300ac3b..f3b1188a8e 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java @@ -212,8 +212,25 @@ public class RestApiServlet extends HttpServlet { view = c.list(); break; } else { - rsrc = c.parse(rsrc, path.remove(0)); - view = view(c, req.getMethod(), path); + String id = path.remove(0); + try { + rsrc = c.parse(rsrc, id); + view = null; + } catch (ResourceNotFoundException e) { + if (c instanceof AcceptsCreate + && ("POST".equals(req.getMethod()) + || "PUT".equals(req.getMethod()))) { + @SuppressWarnings("unchecked") + AcceptsCreate ac = (AcceptsCreate) c; + view = ac.create(rsrc, id); + status = SC_CREATED; + } else { + throw e; + } + } + if (view == null) { + view = view(c, req.getMethod(), path); + } } checkAccessAnnotations(view.getClass()); }