Do not provide response body when apply-object is successful
When `replication.maxApiPayloadSize` is set to a significant
value(for example 100mb) returning full json payload as a
part of the HTTP response can impact the performance.
To avoid sending the payload back to the client skip response
body and return just the http status code.
Bug: Issue 289700653
Change-Id: Ic0c343c1971cb9cefbcbf067033338b953d05bef
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectAction.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectAction.java
index b3379f2..72f0266 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectAction.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectAction.java
@@ -102,7 +102,7 @@
input.getRevisionData(),
input.getLabel(),
input.getEventCreatedOn());
- return Response.created(input);
+ return Response.created();
} catch (MissingParentObjectException e) {
repLog.error(
"Apply object API *FAILED* from {} for {}:{} - {}",
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectsAction.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectsAction.java
index dd155d4..817ea00 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectsAction.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectsAction.java
@@ -102,7 +102,7 @@
input.getRevisionsData(),
input.getLabel(),
input.getEventCreatedOn());
- return Response.created(input);
+ return Response.created();
} catch (MissingParentObjectException e) {
repLog.error(
"Apply object API *FAILED* from {} for {}:{} - {}",
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java
index d18ebc0..d646cfb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java
@@ -182,23 +182,23 @@
}
@SuppressWarnings("unchecked")
- private Response<Map<String, Object>> doApplyObject(HttpServletRequest httpRequest)
+ private Response<String> doApplyObject(HttpServletRequest httpRequest)
throws RestApiException, IOException, PermissionBackendException {
RevisionInput input = readJson(httpRequest, TypeLiteral.get(RevisionInput.class));
IdString id = getProjectName(httpRequest).get();
ProjectResource projectResource = projectsCollection.parse(TopLevelResource.INSTANCE, id);
- return (Response<Map<String, Object>>) applyObjectAction.apply(projectResource, input);
+ return (Response<String>) applyObjectAction.apply(projectResource, input);
}
@SuppressWarnings("unchecked")
- private Response<Map<String, Object>> doApplyObjects(HttpServletRequest httpRequest)
+ private Response<String> doApplyObjects(HttpServletRequest httpRequest)
throws RestApiException, IOException, PermissionBackendException {
RevisionsInput input = readJson(httpRequest, TypeLiteral.get(RevisionsInput.class));
IdString id = getProjectName(httpRequest).get();
ProjectResource projectResource = projectsCollection.parse(TopLevelResource.INSTANCE, id);
- return (Response<Map<String, Object>>) applyObjectsAction.apply(projectResource, input);
+ return (Response<String>) applyObjectsAction.apply(projectResource, input);
}
@SuppressWarnings("unchecked")
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectActionTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectActionTest.java
index 6ef5b2a..7ae3a78 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectActionTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectActionTest.java
@@ -124,12 +124,12 @@
@SuppressWarnings("cast")
@Test
- public void shouldReturnSourceUrlAndrefNameAsAResponseBody() throws Exception {
+ public void shouldReturnEmptyResponseBody() throws Exception {
RevisionInput inputParams =
new RevisionInput(label, refName, DUMMY_EVENT_TIMESTAMP, createSampleRevisionData());
Response<?> response = applyObjectAction.apply(projectResource, inputParams);
- assertThat((RevisionInput) response.value()).isEqualTo(inputParams);
+ assertThat((String) response.value()).isEmpty();
}
@Test(expected = BadRequestException.class)