-
-
Notifications
You must be signed in to change notification settings - Fork 176
Java Client
Akram El Assas edited this page Jul 18, 2025
·
2 revisions
- Install Java JDK
Here is a sample Java client WexflowClient.java
:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class WexflowClient {
private static final String BASE_URL = "http://localhost:8000/api/v1";
private static final String USERNAME = "admin";
private static final String PASSWORD = "wexflow2018";
private static final int WORKFLOW_ID = 41;
public static void main(String[] args) {
try {
String token = login(USERNAME, PASSWORD);
String jobId = startWorkflow(token, WORKFLOW_ID);
System.out.println("Workflow " + WORKFLOW_ID + " started successfully. Job ID: " + jobId);
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
private static String login(String username, String password) throws Exception {
URL url = new URL(BASE_URL + "/login");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
String jsonInputString = String.format(
"{\"username\":\"%s\",\"password\":\"%s\",\"stayConnected\":false}",
username, password);
try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input);
}
int code = conn.getResponseCode();
if (code != 200) {
throw new RuntimeException("Login failed: HTTP " + code);
}
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "utf-8"));
StringBuilder response = new StringBuilder();
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
// Response JSON format: { "access_token": "..." }
String json = response.toString();
String token = parseAccessToken(json);
if (token == null) {
throw new RuntimeException("No access_token found in response");
}
return token;
}
private static String startWorkflow(String token, int workflowId) throws Exception {
URL url = new URL(BASE_URL + "/start?w=" + workflowId);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Bearer " + token);
conn.setDoOutput(true);
int code = conn.getResponseCode();
if (code != 200) {
throw new RuntimeException("Start workflow failed: HTTP " + code);
}
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "utf-8"));
StringBuilder response = new StringBuilder();
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
return response.toString();
}
// Simple method to extract access_token from JSON response
private static String parseAccessToken(String json) {
// This is a naive parse, for production use a JSON library like Jackson or Gson
String tokenKey = "\"access_token\":\"";
int start = json.indexOf(tokenKey);
if (start == -1) return null;
start += tokenKey.length();
int end = json.indexOf("\"", start);
if (end == -1) return null;
return json.substring(start, end);
}
}
To run the client, use the following command:
javac WexflowClient.java
java WexflowClient
Copyright © Akram El Assas. All rights reserved.
- Installing
- HTTPS/SSL
- Screenshots
- Docker
- Configuration
- Persistence Providers
- Getting Started
- Android App
- Local Variables
- Global Variables
- REST Variables
- Functions
- Cron Scheduling
- Command Line Interface (CLI)
- REST API Reference
- Samples
- Logging
- Custom Tasks
- Debugging
-
Built-in Tasks
- File system tasks
- Encryption tasks
- Compression tasks
- Iso tasks
- Speech tasks
- Hashing tasks
- Process tasks
- Network tasks
- XML tasks
- SQL tasks
- WMI tasks
- Image tasks
- Audio and video tasks
- Email tasks
- Workflow tasks
- Social media tasks
- Waitable tasks
- Reporting tasks
- Web tasks
- Script tasks
- JSON and YAML tasks
- Entities tasks
- Flowchart tasks
- Approval tasks
- Notification tasks
- SMS tasks
- Run from Source