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 <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-01-16 08:28:37 +01:00
committed by Edwin Kempin
parent 89136bc832
commit b46c9fb932

View File

@@ -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<RestResource> ac = (AcceptsCreate<RestResource>) c;
view = ac.create(rsrc, id);
status = SC_CREATED;
} else {
throw e;
}
}
if (view == null) {
view = view(c, req.getMethod(), path);
}
}
checkAccessAnnotations(view.getClass());
}