From f5bc0671d4c3364f39b38941ee8c91d7148c6efb Mon Sep 17 00:00:00 2001 From: Matheus Cruz Date: Wed, 2 Sep 2026 00:24:49 -0300 Subject: [PATCH] Skip body building when HTTP call body is absent Signed-off-by: Matheus Cruz --- .../executors/http/HttpExecutorBuilder.java | 6 ++++-- .../impl/test/HTTPWorkflowDefinitionTest.java | 21 +++++++++++++++++++ .../call-http-post-no-body.yaml | 12 +++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 impl/test/src/test/resources/workflows-samples/call-http-post-no-body.yaml diff --git a/impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/HttpExecutorBuilder.java b/impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/HttpExecutorBuilder.java index 50693a5ee..5433a3432 100644 --- a/impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/HttpExecutorBuilder.java +++ b/impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/HttpExecutorBuilder.java @@ -140,8 +140,10 @@ private RequestExecutor buildRequestExecutor() { case HttpMethod.POST: case HttpMethod.PUT: case HttpMethod.PATCH: - return new WithBodyRequestExecutor( - httpMethod, redirect, auth, definition.application(), body); + return body != null + ? new WithBodyRequestExecutor( + httpMethod, redirect, auth, definition.application(), body) + : new WithoutBodyRequestExecutor(httpMethod, redirect, auth); case HttpMethod.DELETE: case HttpMethod.HEAD: case HttpMethod.OPTIONS: diff --git a/impl/test/src/test/java/io/serverlessworkflow/impl/test/HTTPWorkflowDefinitionTest.java b/impl/test/src/test/java/io/serverlessworkflow/impl/test/HTTPWorkflowDefinitionTest.java index 6521074cd..e21f53e1e 100644 --- a/impl/test/src/test/java/io/serverlessworkflow/impl/test/HTTPWorkflowDefinitionTest.java +++ b/impl/test/src/test/java/io/serverlessworkflow/impl/test/HTTPWorkflowDefinitionTest.java @@ -324,6 +324,27 @@ void callHttpPost_should_return_created_firstName() throws Exception { }); } + @Test + void callHttpPost_without_body_should_not_throw() throws Exception { + mockServer.enqueue(new MockResponse(204, Headers.of(), "")); + + assertDoesNotThrow( + () -> + appl.workflowDefinition( + readWorkflowFromClasspath("workflows-samples/call-http-post-no-body.yaml")) + .instance(Map.of()) + .start() + .join()); + + RecordedRequest recordedRequest = mockServer.takeRequest(); + SoftAssertions.assertSoftly( + softly -> { + softly.assertThat(recordedRequest.getMethod()).isEqualTo("POST"); + softly.assertThat(recordedRequest.getUrl()).asString().contains("/api/v1/authors"); + softly.assertThat(recordedRequest.getBodySize()).isEqualTo(0); + }); + } + @Test void testCallHttpDelete() throws IOException, InterruptedException { mockServer.enqueue(new MockResponse(204, Headers.of(), "")); diff --git a/impl/test/src/test/resources/workflows-samples/call-http-post-no-body.yaml b/impl/test/src/test/resources/workflows-samples/call-http-post-no-body.yaml new file mode 100644 index 000000000..770e1e2bb --- /dev/null +++ b/impl/test/src/test/resources/workflows-samples/call-http-post-no-body.yaml @@ -0,0 +1,12 @@ +document: + dsl: 1.0.0-alpha1 + namespace: test + name: call-http-post-no-body + version: 1.0.0 +do: + - postAuthors: + call: http + with: + method: post + endpoint: + uri: http://localhost:9876/api/v1/authors \ No newline at end of file