Skip to content

Instantly share code, notes, and snippets.

@berndruecker
Last active October 19, 2022 18:18
Show Gist options
  • Save berndruecker/48176bc20b576381963b21d26dc7975f to your computer and use it in GitHub Desktop.
Save berndruecker/48176bc20b576381963b21d26dc7975f to your computer and use it in GitHub Desktop.
// Part of the runtime that provides webhook endpoints
@PostMapping("/inbound/{context}")
public ResponseEntity<ProcessInstanceEvent> inbound(
@PathVariable String context,
@RequestBody Map<String, Object> body,
@RequestHeader Map<String, String> headers) {
if (!registry.containsContextPath(context)) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "No webhook found for context: " + context);
}
WebhookConnectorProperties connectorProperties = registry.getWebhookConnectorByContextPath(context);
boolean valid = validateSecret(connectorProperties, webhookContext);
if (!valid) {
return ResponseEntity.status(400).build();
}
Map<String, Object> variables = extractVariables(connectorProperties, webhookContext);
ProcessInstanceEvent processInstanceEvent = zeebeClient
.newCreateInstanceCommand()
.bpmnProcessId(connectorProperties.bpmnProcessId())
.version(connectorProperties.version())
.variables(variables)
.send()
.join(); // TODO: Switch to rective HTTP client
return ResponseEntity.status(HttpStatus.CREATED).body(processInstanceEvent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment