Merge "Use HTTP 201, 204 response codes in REST API"

This commit is contained in:
Shawn O. Pearce
2012-11-28 11:54:42 -08:00
committed by Gerrit Code Review
11 changed files with 168 additions and 51 deletions

View File

@@ -43,6 +43,7 @@ import com.google.gerrit.extensions.restapi.AcceptsCreate;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.BinaryResult;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.PutInput;
@@ -237,11 +238,20 @@ public class RestApiServlet extends HttpServlet {
throw new ResourceNotFoundException();
}
if (result instanceof Response) {
@SuppressWarnings("rawtypes")
Response r = (Response) result;
status = r.statusCode();
}
res.setStatus(status);
if (result instanceof BinaryResult) {
replyBinaryResult(req, res, (BinaryResult) result);
} else {
replyJson(req, res, config, result);
if (result != Response.none()) {
result = Response.unwrap(result);
if (result instanceof BinaryResult) {
replyBinaryResult(req, res, (BinaryResult) result);
} else {
replyJson(req, res, config, result);
}
}
} catch (AuthException e) {
replyError(res, SC_FORBIDDEN, e.getMessage());