Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ With the SDK you can:

* Read workflow JSON and YAML definitions
* Write workflow definitions in JSON and YAML formats.
* Test your workflow definitions using the reference implementation.
* Test your workflow definitions using the reference implementation from `impl`
- Reuse execution components from `common/` while developing your own implementation.


## Status
Expand Down Expand Up @@ -72,10 +73,15 @@ implementation("cloud.openworkflow.sdk:openworkflow-api:RELEASE_VERSION")
## How to Use

There are, roughly speaking, two kind of users of this SDK:

* Those ones interested on using the provided runtime reference implementation to execute workflow definitions.
* Those ones interested on implementing their own runtime using Java.
* Those ones interested on using the provided runtime reference implementation.

## Reference implementation

The reference implementation provides a ready-to-use runtime that supports the Open Workflow Specification. It includes a workflow execution engine, validation utilities, and illustrative examples to help you quickly test and deploy your workflows. For details on usage, configuration, and supported features, see [readme](impl/README.md).

### Implementing your own runtime
## Implementing your own runtime

For those ones interested on implementing their own runtime, this SDK provides an easy way to load an in memory representation of a given workflow definition.
This in-memory representation consists of a hierarchy of POJOS directly generated from the Open Workflow specification [schema](api/src/main/resources/schema/workflow.yaml), which ensures the internal representation is aligned with the specification schema. The root of the hierarchy is `cloud.openworkflow.sdk.api.types.Workflow` class
Expand Down Expand Up @@ -122,7 +128,7 @@ try (InputStream in = new FileInputStream("simple.yaml")) {
}
```

For additional reading helper methods, including the one to read a workflow definition from classpath, check [WorkflowReader](api/src/main/java/org/openworkflow/sdk/api/WorkflowReader.java) class.
For additional reading helper methods, including the one to read a workflow definition from classpath, check [WorkflowReader](api/src/main/java/cloud/openworkflow/sdk/api/WorkflowReader.java) class.

### Writing workflow definition to a JSON/YAML target

Expand All @@ -135,17 +141,15 @@ try (OutputStream out = new FileOutputStream("simple.json")) {
}

```
For additional writing helper methods, check [WorkflowWriter](api/src/main/java/org/openworkflow/sdk/api/WorkflowWriter.java) class.
For additional writing helper methods, check [WorkflowWriter](api/src/main/java/cloud/openworkflow/sdk/api/WorkflowWriter.java) class.

#### Jackson dependency

The `openworkflow-api` module depends heavily on Jackson for loading file content into an in-memory POJO. For users who use a JSON handling library other than Jackson, the `openworkflow-types` module contains Java POJOs generated from the OpenWorkflow schema without any Jackson annotations. Using this module as a dependency, they can build a reader/writer module equivalent to `openworkflow-api` with their preferred JSON library.

### Reference implementation

The reference implementation provides a ready-to-use runtime that supports the Open Workflow Specification. It includes a workflow execution engine, validation utilities, and illustrative examples to help you quickly test and deploy your workflows. For details on usage, configuration, and supported features, see [readme](impl/README.md).

### Reusing Common Libraries

The SDK provides standalone modules under `common/` that can be used independently by other workflow engine implementations. For more details, check the README.MD of each module.

## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fopen-workflow-specification%2Fsdk-java.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fopen-workflow-specification%2Fsdk-java?ref=badge_large)
Expand Down
43 changes: 43 additions & 0 deletions common/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Common API

## Introduction

This module provides core interfaces and utilities that can be reused by other workflow engine implementations. It contains foundational abstractions for service prioritization and ordering.

## Dependency

```xml
<dependency>
<groupId>cloud.openworkflow.sdk</groupId>
<artifactId>openworkflow-common-api</artifactId>
<version>8.0.0-SNAPSHOT</version>
</dependency>
```

## Usage Example

```java
import cloud.openworkflow.sdk.common.ServicePriority;

public class MyService implements ServicePriority<MyService> {

@Override
public int priority() {
return 500; // Higher priority than default (1000)
}

public static void main(String[] args) {
MyService service1 = new MyService();
MyService service2 = new MyService() {
@Override
public int priority() {
return 1500;
}
};

// Compare services by priority
int comparison = service1.compareTo(service2);
System.out.println("Service1 has higher priority: " + (comparison < 0));
}
}
```
23 changes: 23 additions & 0 deletions common/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cloud.openworkflow.sdk</groupId>
<artifactId>openworkflow-common</artifactId>
<version>8.0.0-SNAPSHOT</version>
</parent>
<artifactId>openworkflow-common-api</artifactId>
<name>Open Workflow :: Common API</name>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cloud.openworkflow.sdk.impl;
package cloud.openworkflow.sdk.common;

public interface ServicePriority<T extends ServicePriority<T>> extends Comparable<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package cloud.openworkflow.sdk.impl;

import cloud.openworkflow.sdk.common.ServicePriority;

public class LowestPriority implements ServicePriority<LowestPriority> {
public int priority() {
return DEFAULT_PRIORITY + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
*/
package cloud.openworkflow.sdk.impl;

import cloud.openworkflow.sdk.common.ServicePriority;

public class MediumPriority implements ServicePriority<MediumPriority> {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cloud.openworkflow.sdk.impl.http;
package cloud.openworkflow.sdk.impl;

import cloud.openworkflow.sdk.impl.WorkflowApplication;
import java.net.http.HttpClient;
import java.net.http.HttpClient.Redirect;
import static org.assertj.core.api.Assertions.assertThat;

public class DefaultHttpRequestBuilderFactory implements WorkflowHttpRequestFactory {
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;

private HttpClient client = HttpClient.newBuilder().followRedirects(Redirect.NORMAL).build();
class PriorityTest {

@Override
public WorkflowHttpRequest request(WorkflowApplication app, WorkflowHttpRequestInfo httpInfo) {
return new DefaultHttpRequest(app, client, httpInfo);
}
@Test
void testOrder() {

TopPriority top = new TopPriority();
MediumPriority medium = new MediumPriority();
LowestPriority lowest = new LowestPriority();

@Override
public void close() {
client.close();
List list = new ArrayList<>(Arrays.asList(medium, lowest, top));
Collections.sort(list);
assertThat(list).containsExactly(top, medium, lowest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package cloud.openworkflow.sdk.impl;

import cloud.openworkflow.sdk.common.ServicePriority;

public class TopPriority implements ServicePriority<TopPriority> {
public int priority() {
return DEFAULT_PRIORITY - 1;
Expand Down
48 changes: 48 additions & 0 deletions common/http-jakarta/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# HTTP Transport with Jakarta REST

## Introduction

This module provides a Jakarta REST (formerly JAX-RS) implementation of the HTTP transport interface that other workflow engine implementations can reuse. It enables HTTP execution using Jakarta REST clients without requiring the full workflow engine.

## Dependency

```xml
<dependency>
<groupId>cloud.openworkflow.sdk</groupId>
<artifactId>openworkflow-common-http-jakarta</artifactId>
<version>8.0.0-SNAPSHOT</version>
</dependency>
```

**Runtime Requirement**: A Jakarta REST implementation is required. Common providers include Jersey (Reference Implementation) or RESTEasy (JBoss/Red Hat).

## Usage Example

```java
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import java.util.concurrent.TimeUnit;
import cloud.openworkflow.sdk.http.*;
import cloud.openworkflow.sdk.http.jakarta.*;

// Create and configure Jakarta REST client
Client client = ClientBuilder.newBuilder()
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();

// Create transport with Jakarta REST client
WorkflowHttpTransport<byte[]> transport =
new JakartaHttpTransport<>(client, JakartaHttpTransport.BYTES);

// Execute requests
CompletableFuture<WorkflowHttpResponse<byte[]>> response =
transport.execute(request);

// Remember to close the client at shutdown
client.close();
```

**Important**: The client must be managed by the application and closed at shutdown. `WorkflowHttpResponse` implements `AutoCloseable` and must be closed using try-with-resources.

**Limitation**: `WorkflowHttpResponse.request()` returns `Optional.empty()` as Jakarta REST does not portably expose the final request after redirects.
45 changes: 45 additions & 0 deletions common/http-jakarta/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cloud.openworkflow.sdk</groupId>
<artifactId>openworkflow-common</artifactId>
<version>8.0.0-SNAPSHOT</version>
</parent>
<artifactId>openworkflow-common-http-jakarta</artifactId>
<name>Open Workflow :: HTTP Client :: Jakarta</name>
<dependencies>
<dependency>
<groupId>cloud.openworkflow.sdk</groupId>
<artifactId>openworkflow-common-http</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cloud.openworkflow.sdk.impl.jakarta.http;
package cloud.openworkflow.sdk.http.jakarta;

import cloud.openworkflow.sdk.impl.WorkflowDecorator;
import cloud.openworkflow.sdk.common.ServicePriority;
import jakarta.ws.rs.client.Invocation;
import java.util.function.Consumer;

/**
* Interface for decorating HTTP requests with additional modifications. Note that TaskContext might
* be null
*/
public interface HttpRequestDecorator extends WorkflowDecorator<Invocation.Builder> {}
/** Interface for decorating HTTP requests with additional modifications */
public interface JakartaHttpRequestDecorator
extends Consumer<Invocation.Builder>, ServicePriority<JakartaHttpRequestDecorator> {}
Loading