Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit c1c4234

Browse files
committed
#319 Tweaking configuration of PreviewInterceptor
1 parent f8d634a commit c1c4234

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/main/java/com/marklogic/rest/util/PreviewInterceptor.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.http.client.ClientHttpResponse;
2222
import org.springframework.web.client.DefaultResponseErrorHandler;
2323

24+
import java.io.ByteArrayInputStream;
2425
import java.io.IOException;
2526
import java.io.InputStream;
2627
import java.util.EnumSet;
@@ -117,11 +118,11 @@ protected JsonNode buildJsonPatch(ObjectNode existingResource, String payload) t
117118
modifyPayloadBeforePreview(payloadResource);
118119

119120
ObjectNode merged = JsonNodeUtil.mergeObjectNodes(existingResource, payloadResource);
120-
EnumSet<DiffFlags> flags = DiffFlags.dontNormalizeOpIntoMoveAndCopy().clone();
121+
EnumSet<DiffFlags> flags = EnumSet.of(DiffFlags.OMIT_VALUE_ON_REMOVE, DiffFlags.OMIT_MOVE_OPERATION, DiffFlags.OMIT_COPY_OPERATION, DiffFlags.ADD_ORIGINAL_VALUE_ON_REPLACE);
121122
return JsonDiff.asJson(existingResource, merged, flags);
122123
}
123124

124-
protected void includeJsonPatchInReport(HttpRequest request, ObjectNode existingResource, JsonNode jsonPatch) throws IOException {
125+
protected void includeJsonPatchInReport(HttpRequest request, ObjectNode existingResource, JsonNode jsonPatch) {
125126
ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
126127
if (jsonPatch instanceof ArrayNode && jsonPatch.size() > 0) {
127128
ObjectNode result = mapper.createObjectNode();
@@ -179,6 +180,15 @@ protected void modifyPayloadBeforePreview(ObjectNode payload) {
179180
protected ClientHttpResponse previewPost(HttpRequest request, byte[] bytes) throws IOException {
180181
ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
181182
ObjectNode result = mapper.createObjectNode();
183+
184+
if (request.getURI() != null && request.getURI().toString().endsWith("/manage/v3")) {
185+
String message = "Previewing POST calls to /manage/v3 are not yet supported";
186+
result.set("message", new TextNode(message));
187+
results.add(result);
188+
logger.info(message);
189+
return newFakeResponse();
190+
}
191+
182192
result.set("message", new TextNode("Will create new resource at: " + request.getURI()));
183193

184194
String payload = new String(bytes).trim();
@@ -228,7 +238,8 @@ public void close() {
228238

229239
@Override
230240
public InputStream getBody() {
231-
return null;
241+
// Need to return something besides null, which can cause null pointer exceptions
242+
return new ByteArrayInputStream(new byte[]{});
232243
}
233244

234245
@Override

0 commit comments

Comments
 (0)