Skip to content

Commit f77cac6

Browse files
authored
Add partial implementation for redirect and improve tests for HTTP calls (#1013)
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
1 parent 5e0916c commit f77cac6

19 files changed

+533
-83
lines changed

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/AbstractHttpExecutorBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ protected static RequestSupplier buildRequestSupplier(
4444
return new WithoutBodyRequestSupplier(Invocation.Builder::delete, application, redirect);
4545
case HttpMethod.HEAD:
4646
return new WithoutBodyRequestSupplier(Invocation.Builder::head, application, redirect);
47-
case HttpMethod.OPTIONS:
48-
return new WithoutBodyRequestSupplier(Invocation.Builder::options, application, redirect);
4947
case HttpMethod.PATCH:
5048
return new WithBodyRequestSupplier(
51-
(request, entity) -> request.method("patch", entity), application, body, redirect);
49+
(request, entity) -> request.method("PATCH", entity), application, body, redirect);
50+
case HttpMethod.OPTIONS:
51+
return new WithoutBodyRequestSupplier(Invocation.Builder::options, application, redirect);
5252
case HttpMethod.GET:
5353
default:
5454
return new WithoutBodyRequestSupplier(Invocation.Builder::get, application, redirect);

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/AbstractRequestSupplier.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package io.serverlessworkflow.impl.executors.http;
1717

18+
import static jakarta.ws.rs.core.Response.Status.Family.REDIRECTION;
19+
import static jakarta.ws.rs.core.Response.Status.Family.SUCCESSFUL;
20+
1821
import io.serverlessworkflow.impl.TaskContext;
1922
import io.serverlessworkflow.impl.WorkflowContext;
2023
import io.serverlessworkflow.impl.WorkflowError;
@@ -36,6 +39,7 @@ public AbstractRequestSupplier(boolean redirect) {
3639
public WorkflowModel apply(
3740
Builder request, WorkflowContext workflow, TaskContext task, WorkflowModel model) {
3841
HttpModelConverter converter = HttpConverterResolver.converter(workflow, task);
42+
3943
Response response = invokeRequest(request, converter, workflow, task, model);
4044
validateStatus(task, response, converter);
4145
return workflow
@@ -46,7 +50,9 @@ public WorkflowModel apply(
4650
}
4751

4852
private void validateStatus(TaskContext task, Response response, HttpModelConverter converter) {
49-
if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) {
53+
Family statusFamily = response.getStatusInfo().getFamily();
54+
55+
if (statusFamily != SUCCESSFUL || (!this.redirect && statusFamily == REDIRECTION)) {
5056
throw new WorkflowException(
5157
converter
5258
.errorFromResponse(WorkflowError.communication(response.getStatus(), task), response)

0 commit comments

Comments
 (0)