Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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;

/**
* Parent interface for decorating object requests with additional modifications.<br>
* It is expected that this class is inherited by specializations that indicate the type to be
* decorated.
*
* <p>Children interfaces should be loaded via ServiceLoader and are sorted by priority in ascending
* order (lower priority numbers executed first).
*
* @see ServicePriority
*/
public interface WorkflowDecorator<T> extends ServicePriority {

/**
* Decorates an object with information extracted from the workflow and task context
*
* @param decorated
* @param workflowContext
* @param taskContext
*/
void decorate(T decorated, WorkflowContext workflowContext, TaskContext taskContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,7 @@
package io.serverlessworkflow.impl.events;

import io.cloudevents.core.builder.CloudEventBuilder;
import io.serverlessworkflow.impl.ServicePriority;
import io.serverlessworkflow.impl.TaskContext;
import io.serverlessworkflow.impl.WorkflowContext;
import io.serverlessworkflow.impl.WorkflowDecorator;

/**
* Interface for decorating {@link CloudEventBuilder} objects.
*
* <p>Implementations should be loaded via ServiceLoader and are sorted by priority in ascending
* order (lower priority numbers executed first). Decorators are applied in sequence, where later
* decorators can override configurations set by earlier decorators.
*
* @see ServicePriority
*/
public interface EmittedEventDecorator extends ServicePriority {

void decorate(
CloudEventBuilder ceBuilder, WorkflowContext workflowContext, TaskContext taskContext);
}
/** Interface for decorating {@link CloudEventBuilder} objects. */
public interface EmittedEventDecorator extends WorkflowDecorator<CloudEventBuilder> {}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import jakarta.ws.rs.client.Invocation.Builder;
import jakarta.ws.rs.client.WebTarget;
import java.net.URI;
import java.util.List;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
Expand All @@ -38,7 +38,7 @@ public class HttpExecutor implements CallableTask {
private final Optional<WorkflowValueResolver<Map<String, Object>>> headersMap;
private final Optional<WorkflowValueResolver<Map<String, Object>>> queryMap;
private final RequestExecutor requestFunction;
private final List<RequestDecorator> requestDecorators;
private final Collection<HttpRequestDecorator> requestDecorators;

HttpExecutor(
WorkflowValueResolver<URI> uriSupplier,
Expand All @@ -52,7 +52,7 @@ public class HttpExecutor implements CallableTask {
this.requestFunction = requestFunction;
this.pathSupplier = pathSupplier;
this.requestDecorators =
ServiceLoader.load(RequestDecorator.class).stream()
ServiceLoader.load(HttpRequestDecorator.class).stream()
.map(ServiceLoader.Provider::get)
.sorted()
.toList();
Expand All @@ -75,11 +75,7 @@ public CompletableFuture<WorkflowModel> apply(
target = target.queryParam(entry.getKey(), entry.getValue());
}
Builder request = target.request();

for (RequestDecorator requestDecorator : requestDecorators) {
requestDecorator.decorate(request, workflow, taskContext);
}

requestDecorators.forEach(d -> d.decorate(request, workflow, taskContext));
headersMap.ifPresent(h -> h.apply(workflow, taskContext, input).forEach(request::header));
return CompletableFuture.supplyAsync(
() -> requestFunction.apply(request, uri, workflow, taskContext, input),
Expand Down
Original file line number Diff line number Diff line change
@@ -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.executors.http;

import io.serverlessworkflow.impl.WorkflowDecorator;
import jakarta.ws.rs.client.Invocation;

/** Interface for decorating HTTP requests with additional modifications. */
public interface HttpRequestDecorator extends WorkflowDecorator<Invocation.Builder> {}

This file was deleted.