From 317f4b14858562c2277e61ab5a1e6620cc4e3de7 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Wed, 4 Sep 2024 14:13:26 +0200 Subject: [PATCH] Pausing while investigating DELETE with body --- .../client/SaveAndRestoreClientImpl.java | 22 ++++++++++++++++--- .../web/controllers/NodeController.java | 18 ++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java index beb7cb7308..ac2ac9fef8 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; import org.phoebus.applications.saveandrestore.SaveAndRestoreClientException; @@ -113,12 +114,12 @@ public Node getNode(String uniqueNodeId) { @Override public List getCompositeSnapshotReferencedNodes(String uniqueNodeId) { - return List.of(); + return getCall("/composite-snapshot/" + uniqueNodeId + "/nodes", new TypeReference<>(){}); } @Override public List getCompositeSnapshotItems(String uniqueNodeId) { - return List.of(); + return getCall("/composite-snapshot/" + uniqueNodeId + "/items", new TypeReference<>(){}); } @Override @@ -149,7 +150,22 @@ public Node updateNode(Node nodeToUpdate, boolean customTimeForMigration) { @Override public void deleteNodes(List nodeIds) { - + try { + String s = objectMapper.writeValueAsString(nodeIds); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(Preferences.jmasarServiceUrl + "/node/delete")) + .POST(HttpRequest.BodyPublishers.ofString(s)) + .header("Content-Type", "application/json") + .header("Authorization", getBasicAuthenticationHeader()) + .build(); + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + if (response.statusCode() != 200) { + String message = response.body(); + throw new SaveAndRestoreClientException("Failed : HTTP error code : " + response.statusCode() + ", error message: " + message); + } + } catch (Exception e) { + throw new RuntimeException(e); + } } @Override diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/NodeController.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/NodeController.java index 33882d3145..b75eff2a0f 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/NodeController.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/NodeController.java @@ -128,6 +128,19 @@ public List getChildNodes(@PathVariable final String uniqueNodeId) { return nodeDAO.getChildNodes(uniqueNodeId); } + /** + * This is deprecated, replaced by {@link #deleteNodesAsPost(List)}. Reason for deprecation is that + * the native {@link java.net.http.HttpClient} does not support a body for DELETE requests. + * @param nodeIds + */ + @Deprecated + @SuppressWarnings("unused") + @DeleteMapping(value = "/node", produces = JSON) + @PreAuthorize("@authorizationHelper.mayDelete(#nodeIds, #root)") + public void deleteNodes(@RequestBody List nodeIds) { + deleteNodesAsPost(nodeIds); + } + /** * Deletes all {@link Node}s contained in the provided list. *
@@ -144,10 +157,9 @@ public List getChildNodes(@PathVariable final String uniqueNodeId) { * * @param nodeIds List of {@link Node} ids to remove. */ - @SuppressWarnings("unused") - @DeleteMapping(value = "/node", produces = JSON) + @PostMapping(value = "/node/delete", produces = JSON) @PreAuthorize("@authorizationHelper.mayDelete(#nodeIds, #root)") - public void deleteNodes(@RequestBody List nodeIds) { + public void deleteNodesAsPost(@RequestBody List nodeIds) { nodeDAO.deleteNodes(nodeIds); }