-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActivateDeactivateIntegration.java
49 lines (39 loc) · 1.96 KB
/
ActivateDeactivateIntegration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ActivateDeactivateIntegration {
public static void main(String[] args) {
// Get input parameters from command line arguments
String instanceUrl = args[0];
String integrationIdentifier = args[1];
String action = args[2];
String username = args[3];
String password = args[4];
// JSON payload for activation
String activatePayload = "{\"status\": \"ACTIVATE\"}";
// JSON payload for configuration
String configurePayload = "{\"status\": \"CONFIGURED\"}";
// Determine the JSON payload based on the action
String jsonPayload = action.equals("ACTIVATE") ? activatePayload : configurePayload;
// Escape special characters in JSON
String escapedJsonPayload = jsonPayload.replace("\"", "\\\"");
// Curl command
String curlCommand = "curl -X POST --user " + username + ":" + password + " --header \"Content-Type: application/json\" --header \"X-HTTP-Method-Override: PATCH\" -d \"" + escapedJsonPayload + "\" -d 'enableAsyncActivationMode=true' \"" + instanceUrl + "/ic/api/integration/v1/integrations/" + integrationIdentifier + "\"";
try {
// Execute curl command
Process process = Runtime.getRuntime().exec(curlCommand);
// Read the output of the curl command
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
// Wait for the process to complete
int exitCode = process.waitFor();
// Print the exit code
System.out.println("Curl command executed with exit code: " + exitCode);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}