diff --git a/kahpp-spring-autoconfigure/src/main/java/dev/vox/platform/kahpp/configuration/http/AbstractHttpCall.java b/kahpp-spring-autoconfigure/src/main/java/dev/vox/platform/kahpp/configuration/http/AbstractHttpCall.java index aa40d8b..a92e857 100644 --- a/kahpp-spring-autoconfigure/src/main/java/dev/vox/platform/kahpp/configuration/http/AbstractHttpCall.java +++ b/kahpp-spring-autoconfigure/src/main/java/dev/vox/platform/kahpp/configuration/http/AbstractHttpCall.java @@ -39,10 +39,14 @@ public abstract class AbstractHttpCall implements HttpCall, Conditional { @NotBlank private transient String path; + // This path could change due to the placeholder + private String actualPath; + protected AbstractHttpCall(String name, Map config) { this.name = name; if (config.containsKey("path")) { this.path = config.get("path").toString(); + this.actualPath = path; } if (config.containsKey("method")) { @@ -79,7 +83,7 @@ public String getName() { public Either call(KaHPPRecord record) { ResponseHandler responseHandler = this.responseHandler; - return Try.of(() -> apiClient.sendRequest(method, path, record.getValue().toString())) + return Try.of(() -> apiClient.sendRequest(method, actualPath, record.getValue().toString())) .mapTry(responseHandler::handle) .toEither(); } @@ -94,7 +98,7 @@ public Either call(KaHPPRecord record, JacksonRuntime j LOGGER.warn("No value found inside the record for this placeholder {}", m.group(0)); return Either.left(new RuntimeException("Placeholder value not found")); } - path = path.replace(m.group(0), value); + actualPath = path.replace(m.group(0), value); } return call(record); } diff --git a/kahpp-spring-autoconfigure/src/test/java/dev/vox/platform/kahpp/unit/configuration/http/SimpleHttpCallTest.java b/kahpp-spring-autoconfigure/src/test/java/dev/vox/platform/kahpp/unit/configuration/http/SimpleHttpCallTest.java index 0832d6d..0383f87 100644 --- a/kahpp-spring-autoconfigure/src/test/java/dev/vox/platform/kahpp/unit/configuration/http/SimpleHttpCallTest.java +++ b/kahpp-spring-autoconfigure/src/test/java/dev/vox/platform/kahpp/unit/configuration/http/SimpleHttpCallTest.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import dev.vox.platform.kahpp.configuration.RecordAction; import dev.vox.platform.kahpp.configuration.TransformRecord; import dev.vox.platform.kahpp.configuration.http.HttpCall; @@ -35,6 +36,7 @@ class SimpleHttpCallTest { private ApiClient apiClient; private final JacksonRuntime jacksonRuntime = new JacksonRuntime(); + private static final JsonMapper JSON_MAPPER = new JsonMapper(); @BeforeAll static void setupMockServer() { @@ -170,6 +172,20 @@ void shouldReplacePathWithValue() throws IOException { assertTrue(afterCall.isRight()); assertThat(afterCall.get()).isExactlyInstanceOf(TransformRecord.class); assertThat(((TransformRecord) afterCall.get()).getDataSource().toString()).isEqualTo("{}"); + + JsonNode extraKey = JSON_MAPPER.createObjectNode().put("extra", "record"); + JsonNode extraValue = + JSON_MAPPER + .createObjectNode() + .set("payload", JSON_MAPPER.createObjectNode().put("id", "extraCall")); + KaHPPMockServer.mockHttpResponse( + HTTP_CALL_PATH + "/extraCall", extraValue.toString(), 200, "{}"); + + Either extraCall = + httpCall.call(KaHPPRecord.build(extraKey, extraValue, 1584352842124L), jacksonRuntime); + assertTrue(extraCall.isRight()); + assertThat(extraCall.get()).isExactlyInstanceOf(TransformRecord.class); + assertThat(((TransformRecord) extraCall.get()).getDataSource().toString()).isEqualTo("{}"); } @Test