diff --git a/impl/pom.xml b/impl/pom.xml
index 32ee86a..3907fb7 100644
--- a/impl/pom.xml
+++ b/impl/pom.xml
@@ -8,6 +8,7 @@
serverlessworkflow-impl
3.1.9
+ 1.0.1
@@ -25,6 +26,11 @@
jersey-media-json-jackson
${version.org.glassfish.jersey}
+
+ net.thisptr
+ jackson-jq
+ ${version.net.thisptr}
+
org.junit.jupiter
junit-jupiter-api
diff --git a/impl/src/main/java/io/serverlessworkflow/impl/AbstractTaskExecutor.java b/impl/src/main/java/io/serverlessworkflow/impl/AbstractTaskExecutor.java
index f377b3f..1318160 100644
--- a/impl/src/main/java/io/serverlessworkflow/impl/AbstractTaskExecutor.java
+++ b/impl/src/main/java/io/serverlessworkflow/impl/AbstractTaskExecutor.java
@@ -21,9 +21,11 @@
public abstract class AbstractTaskExecutor implements TaskExecutor {
protected final T task;
+ protected final ExpressionFactory exprFactory;
- protected AbstractTaskExecutor(T task) {
+ protected AbstractTaskExecutor(T task, ExpressionFactory exprFactory) {
this.task = task;
+ this.exprFactory = exprFactory;
}
@Override
diff --git a/impl/src/main/java/io/serverlessworkflow/impl/DefaultTaskExecutorFactory.java b/impl/src/main/java/io/serverlessworkflow/impl/DefaultTaskExecutorFactory.java
index 806a320..fab07d8 100644
--- a/impl/src/main/java/io/serverlessworkflow/impl/DefaultTaskExecutorFactory.java
+++ b/impl/src/main/java/io/serverlessworkflow/impl/DefaultTaskExecutorFactory.java
@@ -18,23 +18,32 @@
import io.serverlessworkflow.api.types.CallTask;
import io.serverlessworkflow.api.types.Task;
import io.serverlessworkflow.api.types.TaskBase;
+import io.serverlessworkflow.impl.jq.JQExpressionFactory;
public class DefaultTaskExecutorFactory implements TaskExecutorFactory {
- protected DefaultTaskExecutorFactory() {}
+ private final ExpressionFactory exprFactory;
- private static TaskExecutorFactory instance = new DefaultTaskExecutorFactory();
+ private static TaskExecutorFactory instance =
+ new DefaultTaskExecutorFactory(JQExpressionFactory.get());
public static TaskExecutorFactory get() {
return instance;
}
- public TaskExecutor extends TaskBase> getTaskExecutor(Task task) {
+ public static TaskExecutorFactory get(ExpressionFactory factory) {
+ return new DefaultTaskExecutorFactory(factory);
+ }
+ protected DefaultTaskExecutorFactory(ExpressionFactory exprFactory) {
+ this.exprFactory = exprFactory;
+ }
+
+ public TaskExecutor extends TaskBase> getTaskExecutor(Task task) {
if (task.getCallTask() != null) {
CallTask callTask = task.getCallTask();
if (callTask.getCallHTTP() != null) {
- return new HttpExecutor(callTask.getCallHTTP());
+ return new HttpExecutor(callTask.getCallHTTP(), exprFactory);
}
}
throw new UnsupportedOperationException(task.get().getClass().getName() + " not supported yet");
diff --git a/impl/src/main/java/io/serverlessworkflow/impl/Expression.java b/impl/src/main/java/io/serverlessworkflow/impl/Expression.java
new file mode 100644
index 0000000..b5bbfc0
--- /dev/null
+++ b/impl/src/main/java/io/serverlessworkflow/impl/Expression.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2020-Present The Serverless 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 io.serverlessworkflow.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+public interface Expression {
+ JsonNode eval(JsonNode input);
+}
diff --git a/impl/src/main/java/io/serverlessworkflow/impl/ExpressionFactory.java b/impl/src/main/java/io/serverlessworkflow/impl/ExpressionFactory.java
new file mode 100644
index 0000000..8f9c1dd
--- /dev/null
+++ b/impl/src/main/java/io/serverlessworkflow/impl/ExpressionFactory.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2020-Present The Serverless 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 io.serverlessworkflow.impl;
+
+public interface ExpressionFactory {
+
+ Expression getExpression(String expression);
+}
diff --git a/impl/src/main/java/io/serverlessworkflow/impl/ExpressionUtils.java b/impl/src/main/java/io/serverlessworkflow/impl/ExpressionUtils.java
new file mode 100644
index 0000000..4500093
--- /dev/null
+++ b/impl/src/main/java/io/serverlessworkflow/impl/ExpressionUtils.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2020-Present The Serverless 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 io.serverlessworkflow.impl;
+
+public class ExpressionUtils {
+
+ private static final String EXPR_PREFIX = "${";
+ private static final String EXPR_SUFFIX = "}";
+
+ private ExpressionUtils() {}
+
+ public static String trimExpr(String expr) {
+ expr = expr.trim();
+ if (expr.startsWith(EXPR_PREFIX)) {
+ expr = trimExpr(expr, EXPR_PREFIX, EXPR_SUFFIX);
+ }
+ return expr.trim();
+ }
+
+ private static String trimExpr(String expr, String prefix, String suffix) {
+ expr = expr.substring(prefix.length());
+ if (expr.endsWith(suffix)) {
+ expr = expr.substring(0, expr.length() - suffix.length());
+ }
+ return expr;
+ }
+}
diff --git a/impl/src/main/java/io/serverlessworkflow/impl/HttpExecutor.java b/impl/src/main/java/io/serverlessworkflow/impl/HttpExecutor.java
index 203ca15..e2c2c42 100644
--- a/impl/src/main/java/io/serverlessworkflow/impl/HttpExecutor.java
+++ b/impl/src/main/java/io/serverlessworkflow/impl/HttpExecutor.java
@@ -18,7 +18,10 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import io.serverlessworkflow.api.types.CallHTTP;
+import io.serverlessworkflow.api.types.Endpoint;
+import io.serverlessworkflow.api.types.EndpointUri;
import io.serverlessworkflow.api.types.HTTPArguments;
+import io.serverlessworkflow.api.types.UriTemplate;
import io.serverlessworkflow.api.types.WithHTTPHeaders;
import io.serverlessworkflow.api.types.WithHTTPQuery;
import jakarta.ws.rs.HttpMethod;
@@ -27,40 +30,33 @@
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation.Builder;
import jakarta.ws.rs.client.WebTarget;
+import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.function.Function;
public class HttpExecutor extends AbstractTaskExecutor {
private static final Client client = ClientBuilder.newClient();
- public HttpExecutor(CallHTTP task) {
- super(task);
+ private final Function targetSupplier;
+
+ public HttpExecutor(CallHTTP task, ExpressionFactory factory) {
+ super(task, factory);
+ this.targetSupplier = getTargetSupplier(task.getWith().getEndpoint());
}
@Override
protected JsonNode internalExecute(JsonNode node) {
HTTPArguments httpArgs = task.getWith();
- // missing checks
- String uri =
- httpArgs
- .getEndpoint()
- .getEndpointConfiguration()
- .getUri()
- .getLiteralEndpointURI()
- .getLiteralUriTemplate();
- WebTarget target = client.target(uri);
WithHTTPQuery query = httpArgs.getQuery();
+ WebTarget target = targetSupplier.apply(node);
if (query != null) {
for (Entry entry : query.getAdditionalProperties().entrySet()) {
target = target.queryParam(entry.getKey(), entry.getValue());
}
}
- Builder request =
- target
- .resolveTemplates(
- JsonUtils.mapper().convertValue(node, new TypeReference