|
21 | 21 | import org.springframework.http.client.ClientHttpResponse;
|
22 | 22 | import org.springframework.web.client.DefaultResponseErrorHandler;
|
23 | 23 |
|
| 24 | +import java.io.ByteArrayInputStream; |
24 | 25 | import java.io.IOException;
|
25 | 26 | import java.io.InputStream;
|
26 | 27 | import java.util.EnumSet;
|
@@ -117,11 +118,11 @@ protected JsonNode buildJsonPatch(ObjectNode existingResource, String payload) t
|
117 | 118 | modifyPayloadBeforePreview(payloadResource);
|
118 | 119 |
|
119 | 120 | 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); |
121 | 122 | return JsonDiff.asJson(existingResource, merged, flags);
|
122 | 123 | }
|
123 | 124 |
|
124 |
| - protected void includeJsonPatchInReport(HttpRequest request, ObjectNode existingResource, JsonNode jsonPatch) throws IOException { |
| 125 | + protected void includeJsonPatchInReport(HttpRequest request, ObjectNode existingResource, JsonNode jsonPatch) { |
125 | 126 | ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
|
126 | 127 | if (jsonPatch instanceof ArrayNode && jsonPatch.size() > 0) {
|
127 | 128 | ObjectNode result = mapper.createObjectNode();
|
@@ -179,6 +180,15 @@ protected void modifyPayloadBeforePreview(ObjectNode payload) {
|
179 | 180 | protected ClientHttpResponse previewPost(HttpRequest request, byte[] bytes) throws IOException {
|
180 | 181 | ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
|
181 | 182 | 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 | + |
182 | 192 | result.set("message", new TextNode("Will create new resource at: " + request.getURI()));
|
183 | 193 |
|
184 | 194 | String payload = new String(bytes).trim();
|
@@ -228,7 +238,8 @@ public void close() {
|
228 | 238 |
|
229 | 239 | @Override
|
230 | 240 | 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[]{}); |
232 | 243 | }
|
233 | 244 |
|
234 | 245 | @Override
|
|
0 commit comments