Skip to content

Commit

Permalink
Json conversion for moteur rest fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hippolyteblot committed Nov 29, 2024
1 parent 108c221 commit 14ed884
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
package fr.insalyon.creatis.vip.application.server.business.simulation;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.insalyon.creatis.vip.application.client.view.monitor.SimulationStatus;
import fr.insalyon.creatis.vip.application.server.business.util.ProxyUtil;
import fr.insalyon.creatis.vip.core.server.business.BusinessException;
Expand All @@ -49,6 +51,8 @@
import java.util.Base64;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

import static org.springframework.http.MediaType.APPLICATION_JSON;

/**
Expand All @@ -69,10 +73,18 @@ public RestServiceEngine(Server server) {
this.server = server;
}


private static class RestWorkflow {
@JsonProperty("workflow")
String workflow;

@JsonProperty("inputs")
String inputs;

@JsonProperty("proxy")
String proxy;

@JsonProperty("settings")
String settings;

public RestWorkflow(String workflow, String inputs, String proxy, String settings) {
Expand Down Expand Up @@ -110,10 +122,13 @@ public String launch(String addressWS, String workflow, String inputs, String se
.defaultHeaders(headers -> headers.setBasicAuth("user", server.getMoteurServerPassword()))
.build();

ObjectMapper mapper = new ObjectMapper();
String jsonBody = mapper.writeValueAsString(restWorkflow);

return restClient.post()
.uri("/submit")
.contentType(APPLICATION_JSON)
.body(restWorkflow)
.body(jsonBody)
.retrieve()
.body(String.class);
} catch (HttpServerErrorException | HttpClientErrorException e) {
Expand All @@ -122,6 +137,9 @@ public String launch(String addressWS, String workflow, String inputs, String se
} catch (RestClientException e) {
logger.error("REST client error while fetching workflow status", e);
throw new BusinessException("REST client error while fetching workflow status", e);
} catch (JsonProcessingException e) {
logger.error("Error serializing RestWorkflow to JSON", e);
throw new BusinessException("Error serializing RestWorkflow to JSON", e);
}
}

Expand Down

0 comments on commit 14ed884

Please sign in to comment.