Skip to content

Commit 3414d77

Browse files
committed
Apply pull request suggestions
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
1 parent 7fa5461 commit 3414d77

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,22 @@ public WorkflowModel apply(
4040
Builder request, WorkflowContext workflow, TaskContext task, WorkflowModel model) {
4141
HttpModelConverter converter = HttpConverterResolver.converter(workflow, task);
4242

43-
if (!redirect) {
44-
request.property("jersey.config.client.followRedirects", false);
45-
}
46-
4743
Response response = invokeRequest(request, converter, workflow, task, model);
48-
validateStatus(task, response);
44+
validateStatus(task, response, converter);
4945
return workflow
5046
.definition()
5147
.application()
5248
.modelFactory()
5349
.fromAny(response.readEntity(converter.responseType()));
5450
}
5551

56-
private void validateStatus(TaskContext task, Response response) {
52+
private void validateStatus(TaskContext task, Response response, HttpModelConverter converter) {
5753
Family statusFamily = response.getStatusInfo().getFamily();
58-
boolean isSuccess = statusFamily.equals(SUCCESSFUL);
59-
boolean isRedirect = statusFamily.equals(REDIRECTION);
60-
boolean valid = redirect ? (isSuccess || isRedirect) : isSuccess;
6154

62-
if (!valid) {
63-
String expectedRange = redirect ? "200-399" : "200-299";
55+
if (statusFamily != SUCCESSFUL || (!this.redirect && statusFamily == REDIRECTION)) {
6456
throw new WorkflowException(
65-
WorkflowError.communication(
66-
response.getStatus(),
67-
task,
68-
String.format(
69-
"The property 'redirect' is set to %s but received status %d (%s); expected status in the %s range",
70-
redirect,
71-
response.getStatus(),
72-
response.getStatusInfo().getReasonPhrase(),
73-
expectedRange))
57+
converter
58+
.errorFromResponse(WorkflowError.communication(response.getStatus(), task), response)
7459
.build());
7560
}
7661
}

impl/test/src/test/java/io/serverlessworkflow/impl/test/HTTPWorkflowDefinitionTest.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.junit.jupiter.api.AfterEach;
3636
import org.junit.jupiter.api.BeforeAll;
3737
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Disabled;
3839
import org.junit.jupiter.api.Test;
3940

4041
public class HTTPWorkflowDefinitionTest {
@@ -415,6 +416,27 @@ void testOptionsCall() throws IOException, InterruptedException {
415416
}
416417

417418
@Test
419+
@Disabled(
420+
value =
421+
"See the following discussion: https://github.com/serverlessworkflow/sdk-java/pull/1013/files#r2562919102")
422+
void testPatchCall() throws IOException, InterruptedException {
423+
mockServer.enqueue(new MockResponse(204, Headers.of(), ""));
424+
appl.workflowDefinition(readWorkflowFromClasspath("workflows-samples/call-http-patch.yaml"))
425+
.instance(Map.of())
426+
.start()
427+
.join();
428+
429+
RecordedRequest recordedRequest = mockServer.takeRequest();
430+
SoftAssertions.assertSoftly(
431+
softly -> {
432+
softly.assertThat(recordedRequest.getMethod()).isEqualTo("PATCH");
433+
softly.assertThat(recordedRequest.getUrl().toString()).contains("/users/1");
434+
});
435+
}
436+
437+
@Test
438+
@Disabled(
439+
"See the following discussion: https://github.com/serverlessworkflow/sdk-java/pull/1013/files#r2566152233")
418440
void testRedirect_should_throws_when_redirect_is_false_and_response_status_is_not_2xx() {
419441
mockServer.enqueue(
420442
new MockResponse(301, Headers.of("Location", "http://localhost:9876/redirected"), ""));
@@ -429,8 +451,6 @@ void testRedirect_should_throws_when_redirect_is_false_and_response_status_is_no
429451
.instance(Map.of())
430452
.start()
431453
.join());
432-
assertThat(exception.getCause().getMessage())
433-
.contains(
434-
"The property 'redirect' is set to false but received status 301 (Redirection); expected status in the 200-299 range");
454+
assertThat(exception.getCause().getMessage()).contains("status=301");
435455
}
436456
}

0 commit comments

Comments
 (0)