Skip to content

Commit

Permalink
Pausing while investigating DELETE with body
Browse files Browse the repository at this point in the history
  • Loading branch information
georgweiss committed Sep 4, 2024
1 parent 74341b5 commit 317f4b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,12 +114,12 @@ public Node getNode(String uniqueNodeId) {

@Override
public List<Node> getCompositeSnapshotReferencedNodes(String uniqueNodeId) {
return List.of();
return getCall("/composite-snapshot/" + uniqueNodeId + "/nodes", new TypeReference<>(){});
}

@Override
public List<SnapshotItem> getCompositeSnapshotItems(String uniqueNodeId) {
return List.of();
return getCall("/composite-snapshot/" + uniqueNodeId + "/items", new TypeReference<>(){});
}

@Override
Expand Down Expand Up @@ -149,7 +150,22 @@ public Node updateNode(Node nodeToUpdate, boolean customTimeForMigration) {

@Override
public void deleteNodes(List<String> 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<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ public List<Node> 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<String> nodeIds) {
deleteNodesAsPost(nodeIds);
}

/**
* Deletes all {@link Node}s contained in the provided list.
* <br>
Expand All @@ -144,10 +157,9 @@ public List<Node> 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<String> nodeIds) {
public void deleteNodesAsPost(@RequestBody List<String> nodeIds) {
nodeDAO.deleteNodes(nodeIds);
}

Expand Down

0 comments on commit 317f4b1

Please sign in to comment.