-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
flawmop
committed
Jan 1, 2025
1 parent
25bcf9a
commit 261d362
Showing
3 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/insilicosoft/portal/svc/simulationinvoke/service/InvocationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.insilicosoft.portal.svc.simulationinvoke.service; | ||
|
||
import com.insilicosoft.portal.svc.simulationinvoke.event.SimulationMessage; | ||
|
||
public interface InvocationService { | ||
|
||
/** | ||
* Invoke a simulation. | ||
* | ||
* @param simulationMessage Simulation to invoke. | ||
*/ | ||
void invoke(SimulationMessage simulationMessage); | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
.../java/com/insilicosoft/portal/svc/simulationinvoke/service/RestInvocationServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.insilicosoft.portal.svc.simulationinvoke.service; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestClient; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.insilicosoft.portal.svc.simulationinvoke.event.SimulationMessage; | ||
|
||
@Service | ||
public class RestInvocationServiceImpl implements InvocationService { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(RestInvocationServiceImpl.class); | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private final RestClient restClient; | ||
|
||
public RestInvocationServiceImpl(final RestClient restClient) { | ||
this.restClient = restClient; | ||
} | ||
|
||
@Override | ||
public void invoke(SimulationMessage simulationMessage) { | ||
logger.debug("~invoke() : Called for {}", simulationMessage); | ||
String body = ""; | ||
try { | ||
body = objectMapper.writeValueAsString(simulationMessage); | ||
} catch (JsonProcessingException e) { | ||
body = "{ 'error': '" + e.getMessage() + "' }"; | ||
} | ||
restClient.post().contentType(MediaType.APPLICATION_JSON).body(body).retrieve().toBodilessEntity(); | ||
} | ||
|
||
} |