From bdbb1a367030e5a041e31fdebf27aea76317df02 Mon Sep 17 00:00:00 2001 From: Serhii Titenko Date: Mon, 2 Nov 2026 16:17:34 +0200 Subject: [PATCH 1/2] Accept the response header prefix in any case in HTTP integrations Downlink metadata keys starting with "header:" (as the request headers are passed to the downlink converter) are now returned as response headers, not only keys starting with "Header:". --- .../integration/HttpIntegrationTest.java | 60 +++++++++++++++++++ .../http/basic/BasicHttpIntegration.java | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/application/src/test/java/org/thingsboard/server/service/integration/HttpIntegrationTest.java b/application/src/test/java/org/thingsboard/server/service/integration/HttpIntegrationTest.java index f4bcf1738e..0c2ee70028 100644 --- a/application/src/test/java/org/thingsboard/server/service/integration/HttpIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/service/integration/HttpIntegrationTest.java @@ -20,6 +20,8 @@ import org.springframework.context.annotation.Primary; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.ResultActions; import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.EventInfo; @@ -30,9 +32,14 @@ import org.thingsboard.server.common.data.event.LifeCycleEventFilter; import org.thingsboard.server.common.data.integration.IntegrationType; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; +import org.thingsboard.server.common.data.msg.TbMsgType; import org.thingsboard.server.common.data.secret.Secret; +import org.thingsboard.server.common.msg.TbMsg; +import org.thingsboard.server.common.msg.TbMsgMetaData; +import org.thingsboard.server.common.msg.queue.TbCallback; import org.thingsboard.server.dao.secret.SecretService; import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.gen.transport.TransportProtos; import org.thingsboard.server.service.cache.DefaultIntegrationExecutorTenantProfileCache; import org.thingsboard.server.service.cache.IntegrationExecutorTenantProfileCache; @@ -314,6 +321,59 @@ public class HttpIntegrationTest extends AbstractIntegrationTest { }); } + @Test + public void testResponseHeadersFromDownlinkMetadata_thenHeaderPrefixIsCaseInsensitive() throws Exception { + loginTenantAdmin(); + + ObjectNode uplinkConfiguration = JacksonUtil.newObjectNode(); + uplinkConfiguration.put("scriptLang", "TBEL"); + uplinkConfiguration.put("decoder", "return {};"); + uplinkConfiguration.put("tbelDecoder", "return {deviceName: 'http_device', deviceType: 'http', telemetry: {test: 1}};"); + createConverter(HTTP_UPLINK_CONVERTER_NAME, ConverterType.UPLINK, uplinkConfiguration); + + ObjectNode downlinkConfiguration = JacksonUtil.newObjectNode(); + downlinkConfiguration.put("scriptLang", "TBEL"); + downlinkConfiguration.put("encoder", "return {};"); + downlinkConfiguration.put("tbelEncoder", "return {contentType: 'JSON', data: JSON.stringify(msg), " + + "metadata: {'Header:X-Upper-Case': 'upper', 'header:X-Lower-Case': 'lower'}};"); + createConverter("Test downlink converter", ConverterType.DOWNLINK, downlinkConfiguration); + + createIntegration("Test HTTP integration", IntegrationType.HTTP); + enableIntegration(); + waitUntilIntegrationStarted(tenantId, integration.getId()); + + Device device = new Device(); + device.setName("http_device"); + device.setType("http"); + device = doPost("/api/device", device, Device.class); + + TbMsg downlink = TbMsg.newMsg() + .type(TbMsgType.ATTRIBUTES_UPDATED) + .originator(device.getId()) + .copyMetaData(new TbMsgMetaData()) + .data("{\"uploadFrequency\":60}") + .build(); + downlinkService.onRuleEngineDownlinkMsg(tenantId, integration.getId(), TransportProtos.IntegrationDownlinkMsgProto.newBuilder() + .setTenantIdLSB(tenantId.getId().getLeastSignificantBits()) + .setTenantIdMSB(tenantId.getId().getMostSignificantBits()) + .setIntegrationIdLSB(integration.getId().getId().getLeastSignificantBits()) + .setIntegrationIdMSB(integration.getId().getId().getMostSignificantBits()) + .setDataProto(TbMsg.toProto(downlink)) + .build(), TbCallback.EMPTY); + + MvcResult response = await("uplink response with the pending downlink") + .atMost(TIMEOUT, TimeUnit.SECONDS) + .until(() -> postUplink().andReturn(), result -> result.getResponse().getStatus() == 200); + + Assert.assertEquals("{\"uploadFrequency\":60}", response.getResponse().getContentAsString()); + Assert.assertEquals("upper", response.getResponse().getHeader("X-Upper-Case")); + Assert.assertEquals("lower", response.getResponse().getHeader("X-Lower-Case")); + } + + private ResultActions postUplink() throws Exception { + return doPostAsync("/api/v1/integrations/http/{routingKey}", TEST_DATA, TimeUnit.SECONDS.toMillis(TIMEOUT), integration.getRoutingKey()); + } + private void createIntegration(boolean isDevice) throws Exception { loginTenantAdmin(); diff --git a/common/integration/http-integrations/src/main/java/org/thingsboard/integration/http/basic/BasicHttpIntegration.java b/common/integration/http-integrations/src/main/java/org/thingsboard/integration/http/basic/BasicHttpIntegration.java index 3f28be6ef5..84831c87a9 100644 --- a/common/integration/http-integrations/src/main/java/org/thingsboard/integration/http/basic/BasicHttpIntegration.java +++ b/common/integration/http-integrations/src/main/java/org/thingsboard/integration/http/basic/BasicHttpIntegration.java @@ -137,7 +137,7 @@ public class BasicHttpIntegration> extends Abstr boolean contentTypePresent = false; for (Entry kv : downlink.getMetadata().entrySet()) { - if (kv.getKey().startsWith(HEADER)) { + if (kv.getKey().regionMatches(true, 0, HEADER, 0, HEADER.length())) { String headerName = kv.getKey().substring(HEADER.length()); responseHeaders.add(headerName, kv.getValue()); if (headerName.equalsIgnoreCase("Content-Type")) { From 2893cdc6324739de22ed69d0d0f590067dc882b1 Mon Sep 17 00:00:00 2001 From: Serhii Titenko Date: Tue, 3 Nov 2026 11:30:12 +0200 Subject: [PATCH 2/2] Inline the uplink request in the response headers test --- .../integration/HttpIntegrationTest.java | 80 +++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/service/integration/HttpIntegrationTest.java b/application/src/test/java/org/thingsboard/server/service/integration/HttpIntegrationTest.java index 0c2ee70028..136f9dfe1e 100644 --- a/application/src/test/java/org/thingsboard/server/service/integration/HttpIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/service/integration/HttpIntegrationTest.java @@ -20,8 +20,6 @@ import org.springframework.context.annotation.Primary; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.ResultActions; import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.EventInfo; @@ -285,42 +283,6 @@ public class HttpIntegrationTest extends AbstractIntegrationTest { Assert.assertEquals("Converter debug rate limits reached!", events.get(0).getBody().get("error").asText()); } - @Test - public void testUpdateSecretUsedInIntegration_thenReceiveIntegrationLifecycleEvent() throws Exception { - createIntegration(true); - - cleanUpEvents(integration.getId(), new LifeCycleEventFilter()); - Awaitility - .await() - .alias("Get cleaned up integration events") - .atMost(TIMEOUT, TimeUnit.SECONDS) - .until(() -> { - PageData events = getEvents(tenantId, integration.getId()); - return events.getData().isEmpty(); - }); - - // should trigger new update event - Secret secret = secretService.findSecretByName(tenantId, LOCALHOST); - secret.setValue("updated"); - secretService.saveSecret(tenantId, secret); - - Awaitility - .await() - .alias("Get integration events") - .atMost(TIMEOUT, TimeUnit.SECONDS) - .until(() -> { - PageData events = getEvents(tenantId, integration.getId()); - if (events.getData().isEmpty()) { - return false; - } - - EventInfo event = events.getData().stream().max(Comparator.comparingLong(EventInfo::getCreatedTime)).orElse(null); - return event != null - && "UPDATED".equals(event.getBody().get("event").asText()) - && "true".equals(event.getBody().get("success").asText()); - }); - } - @Test public void testResponseHeadersFromDownlinkMetadata_thenHeaderPrefixIsCaseInsensitive() throws Exception { loginTenantAdmin(); @@ -361,17 +323,51 @@ public class HttpIntegrationTest extends AbstractIntegrationTest { .setDataProto(TbMsg.toProto(downlink)) .build(), TbCallback.EMPTY); - MvcResult response = await("uplink response with the pending downlink") + var response = await("uplink response with the pending downlink") .atMost(TIMEOUT, TimeUnit.SECONDS) - .until(() -> postUplink().andReturn(), result -> result.getResponse().getStatus() == 200); + .until(() -> doPostAsync("/api/v1/integrations/http/{routingKey}", TEST_DATA, + TimeUnit.SECONDS.toMillis(TIMEOUT), integration.getRoutingKey()).andReturn(), + result -> result.getResponse().getStatus() == 200); Assert.assertEquals("{\"uploadFrequency\":60}", response.getResponse().getContentAsString()); Assert.assertEquals("upper", response.getResponse().getHeader("X-Upper-Case")); Assert.assertEquals("lower", response.getResponse().getHeader("X-Lower-Case")); } - private ResultActions postUplink() throws Exception { - return doPostAsync("/api/v1/integrations/http/{routingKey}", TEST_DATA, TimeUnit.SECONDS.toMillis(TIMEOUT), integration.getRoutingKey()); + @Test + public void testUpdateSecretUsedInIntegration_thenReceiveIntegrationLifecycleEvent() throws Exception { + createIntegration(true); + + cleanUpEvents(integration.getId(), new LifeCycleEventFilter()); + Awaitility + .await() + .alias("Get cleaned up integration events") + .atMost(TIMEOUT, TimeUnit.SECONDS) + .until(() -> { + PageData events = getEvents(tenantId, integration.getId()); + return events.getData().isEmpty(); + }); + + // should trigger new update event + Secret secret = secretService.findSecretByName(tenantId, LOCALHOST); + secret.setValue("updated"); + secretService.saveSecret(tenantId, secret); + + Awaitility + .await() + .alias("Get integration events") + .atMost(TIMEOUT, TimeUnit.SECONDS) + .until(() -> { + PageData events = getEvents(tenantId, integration.getId()); + if (events.getData().isEmpty()) { + return false; + } + + EventInfo event = events.getData().stream().max(Comparator.comparingLong(EventInfo::getCreatedTime)).orElse(null); + return event != null + && "UPDATED".equals(event.getBody().get("event").asText()) + && "true".equals(event.getBody().get("success").asText()); + }); } private void createIntegration(boolean isDevice) throws Exception {