conductor-oss / conductor-oss/conductor
HTTP 401 Unauthorized when using Synchronous Workflow Execution API in v3.23.0
- Dominant language
- Java
- Stars
- 32.2k
- Forks
- 1k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 41
Description
Since upgrading from v3.21.22 to v3.23.0, I am encountering a `401 Unauthorized` error when attempting to use the newly available synchronous workflow execution endpoint
(`/api/workflow/execute/{name}/{version}`).
Previously, as version 3.21.22 did not have a built-in synchronous API, I implemented a custom wrapper using polling which continues to work perfectly in the current environment. However, switching to the native execution endpoint results in a 401 response
Below is the code of custom wrapper.
```java
@PostMapping(value = "/sync/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary =
"Start a new workflow. Returns the final workflow object")
public WorkflowModelSync startWorkflowSync(
@PathVariable("name") String name,
@RequestParam(value = "version", required = false) Integer version,
@RequestParam(value = "correlationId", required = false) String correlationId,
@RequestParam(value = "priority", defaultValue = "0", required = false) int priority,
@RequestParam(value = "waitForCompletion", defaultValue = "false", required = false) boolean waitForCompletion,
@RequestParam(value = "timeoutSeconds", defaultValue = "30", required = false) int timeoutSeconds,
@RequestBody Map input) throws InterruptedException {
String workflowId = workflowService.startWorkflow(name, version, correlationId, priority, input);
WorkflowModel model = waitForCompletion(workflowId, waitForCompletion, timeoutSeconds);
return WorkflowModelSync.builder()
.status(model.getStatus())
.workflowId(model.getWorkflowId())
.variables(model.getVariables())
.output(model.getOutput())
.build();
}
public WorkflowModel waitForCompletion(String workflowId,
boolean waitForCompletionFlag,
int timeoutSeconds)
throws InterruptedException {
// If caller does NOT want to wait, return immediately
if (!waitForCompletionFlag) {
return workflowExecutor.getWorkflow(workflowId, false);
}
long deadline = System.currentTimeMillis() + (timeoutSeconds * 1000L);
while (System.currentTimeMillis() < deadline) {
WorkflowModel workflow =
workflowExecutor.getWorkflow(workflowId, false);
if (workflow.getStatus().isTerminal()) {
return workflow;
}
Thread.sleep(500); // polling interval
}
throw new RuntimeException(
"Workflow " + workflowId + " timed out after "
+ timeoutSeconds + " seconds"
);
}
```
1) The Request causing the failure (v3.23.0 native):
```bash
curl --location '/api/conductor/workflow/execute/read_user/1?waitForSeconds=60' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ' \
--data-raw '{
"input": {
"id": 24
}
}'
```
Error
```HTML
HTTP Status 401 – Unauthorized
body {
font-family: Tahoma, Arial, sans-serif;
}
h1,
h2,
h3,
b {
color: white;
background-color: #525D76;
}
h1 {
font-size: 22px;
}
h2 {
font-size: 16px;
}
h3 {
font-size: 14px;
}
p {
font-size: 12px;
}
a {
color: black;
}
.line {
height: 1px;
background-color: #525D76;
border: none;
}
HTTP Status 401 – Unauthorized
```
The Request that works (Custom Wrapper):
```bash
curl --location '/api/conductor/workflow/sync/read_user?version=1&waitForCompletion=true&timeoutSeconds=60' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ' \
--data-raw '{
"id": 24
}'
```
Output
```json
{
"status": "COMPLETED",
"workflowId": "d1e6d168-964c-482f-b1b9-96190cbc3160",
"variables": {},
"output": {}
}
```
Additional Info:
An API Gateway handles security/authentication and routes traffic:
/api/conductor/** $\rightarrow$ /api/**.
Expected Behavior:
The synchronous execution API should process the workflow and return the output upon completion, similar to the behavior of a custom polling implementation.
Actual Behavior:
The server returns an HTML response: HTTP Status 401 – Unauthorized.
**Please help me to solve the issue.**
Contributor guide
Assessment
This issue has not been assessed yet.