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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ With the SDK you can:
* Test your workflow definitions using the reference implementation.


## Three ways to use the SDK

- Use the generated Java models to read and write specification documents in your own implementation.
- Run workflows with the customizable reference engine, standalone or embedded in an application.
- Reuse execution components from `common/` in another workflow engine, without creating SDK workflow contexts. For example, use `openworkflow-common-openapi` to bind an operation and prepare its request, then send it with `openworkflow-common-http` (JDK) or `openworkflow-common-http-jakarta`.

Common OpenAPI consumers can supply a `UnifiedOpenAPIReader` of their own. To use the SDK's JSON/YAML Jackson reader, add `cloud.openworkflow.sdk:openworkflow-impl-openapi` at the same SDK version; this optional reader retains its SDK implementation dependencies. See the [HTTP example](common/http/README.md) and [OpenAPI example](common/openapi/README.md). Production dependencies point from the reference implementation to common components. gRPC reorganization is handled separately.

## Status

| Latest Releases | Conformance to spec version |
Expand Down Expand Up @@ -122,7 +130,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,7 +143,7 @@ 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

Expand Down
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
@@ -0,0 +1,146 @@
/*
* Copyright 2020-Present The Open Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cloud.openworkflow.sdk.http.jakarta;

import cloud.openworkflow.sdk.http.*;
import jakarta.ws.rs.core.Response;
import java.util.*;

/**
* Buffered native entity supports both provider conversion and original raw bytes. Caller closes.
*/
public class JakartaHttpResponse implements HttpResponse {
private final Response response;
private final HttpBodyConverter converter;

public JakartaHttpResponse(Response response, HttpBodyConverter converter) {
this.response = Objects.requireNonNull(response);
this.converter = Objects.requireNonNull(converter);
try {
if (response.hasEntity() && !response.bufferEntity())
throw new IllegalStateException(
"Native entity cannot be buffered for repeatable raw access");
} catch (RuntimeException | Error e) {
closeAfterFailure(e);
throw e;
}
}

public int status() {
return response.getStatus();
}

public byte[] body() {
return response.hasEntity() ? response.readEntity(byte[].class).clone() : new byte[0];
}

public Map<String, List<Object>> headers() {
return response.getHeaders();
}

@Override
public Map<String, List<String>> stringHeaders() {
return new HttpResponseData(status(), response.getStringHeaders(), new byte[0]).headers();
}

@Override
public String firstHeader(String name) {
var values = response.getStringHeaders().get(name);
return values == null || values.isEmpty() ? null : values.getFirst();
}

@Override
public String getHeader(String name) {
return response.getHeaderString(name);
}

@Override
public byte[] contentAsByteArray() {
return response.hasEntity() ? response.readEntity(byte[].class) : new byte[0];
}

@Override
public OptionalLong lastModified() {
var date = response.getLastModified();
return date == null ? OptionalLong.empty() : OptionalLong.of(date.getTime());
}

@Override
public String reasonPhrase() {
return response.getStatusInfo().getReasonPhrase();
}

@Override
public String errorDetails() {
try {
return response.readEntity(String.class);
} catch (jakarta.ws.rs.ProcessingException ex) {
return ex.getMessage();
}
}

public <T> Optional<T> nativeResponse(Class<T> type) {
return type.isInstance(response) ? Optional.of(type.cast(response)) : Optional.empty();
}

public <T> Optional<T> getBodyAsObject(Class<T> type) {
try {
return converter.convert(this, type);
} catch (RuntimeException | Error e) {
closeAfterFailure(e);
throw e;
}
}

private void closeAfterFailure(Throwable error) {
try {
response.close();
} catch (RuntimeException | Error cleanup) {
if (cleanup != error) error.addSuppressed(cleanup);
}
}

public void close() {
response.close();
}

@Override
public byte[] responseAsByteArray() {
// Preserve the SDK's existing raw formatter heuristic; this is not protocol metadata.
return HttpResponses.responseAsByteArray(this, legacyHttp2RawFormat());
}

private static final Collection<String> FORBIDDEN_HTTP2_HEADERS_LOWERCASE =
Arrays.asList("connection", "keep-alive", "proxy-connection", "transfer-encoding", "upgrade");

private boolean legacyHttp2RawFormat() {
for (String str : response.getHeaders().keySet()) {
if (containsUpperCase(str) || FORBIDDEN_HTTP2_HEADERS_LOWERCASE.contains(str.toLowerCase())) {
return false;
}
}
return true;
}

private boolean containsUpperCase(String str) {
for (int i = 0; i < str.length(); i++) {
if (Character.isUpperCase(str.charAt(i))) {
return true;
}
}
return false;
}
}
Loading