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 8ea947438b..2e56ba0075 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 @@ -211,8 +211,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()); }