This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch
4120-add-custom-header-configuration-to-http-stream-adapter
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to
refs/heads/4120-add-custom-header-configuration-to-http-stream-adapter by this
push:
new 8d40f132dd fix(#4120): Add bearer token authentication options to
HttpStreamProtocol
8d40f132dd is described below
commit 8d40f132ddb787a45ec07d4606548c96fe6a420e
Author: Philipp Zehnder <[email protected]>
AuthorDate: Mon Jan 26 17:00:27 2026 +0100
fix(#4120): Add bearer token authentication options to HttpStreamProtocol
---
.../iiot/IIoTAdaptersExtensionModuleExport.java | 4 +-
.../migration/HttpStreamProtocolMigrationV1.java | 63 ++++++++++++++++++++++
.../iiot/protocol/stream/HttpStreamProtocol.java | 27 +++++++---
.../strings.en | 11 ++++
4 files changed, 98 insertions(+), 7 deletions(-)
diff --git
a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/IIoTAdaptersExtensionModuleExport.java
b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/IIoTAdaptersExtensionModuleExport.java
index 4fbdc74ead..cf1069e94a 100644
---
a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/IIoTAdaptersExtensionModuleExport.java
+++
b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/IIoTAdaptersExtensionModuleExport.java
@@ -21,6 +21,7 @@ package org.apache.streampipes.connect.iiot;
import org.apache.streampipes.connect.iiot.adapters.oi4.Oi4Adapter;
import
org.apache.streampipes.connect.iiot.adapters.oi4.migration.Oi4AdapterMigrationV1;
import
org.apache.streampipes.connect.iiot.adapters.simulator.machine.MachineDataSimulatorAdapter;
+import
org.apache.streampipes.connect.iiot.migration.HttpStreamProtocolMigrationV1;
import
org.apache.streampipes.connect.iiot.migration.MachineDataSimulatorMigrationV1;
import org.apache.streampipes.connect.iiot.protocol.stream.FileReplayAdapter;
import org.apache.streampipes.connect.iiot.protocol.stream.HttpServerProtocol;
@@ -54,6 +55,7 @@ public class IIoTAdaptersExtensionModuleExport implements
IExtensionModuleExport
public List<IModelMigrator<?, ?>> migrators() {
return List.of(
new Oi4AdapterMigrationV1(),
- new MachineDataSimulatorMigrationV1());
+ new MachineDataSimulatorMigrationV1(),
+ new HttpStreamProtocolMigrationV1());
}
}
diff --git
a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/migration/HttpStreamProtocolMigrationV1.java
b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/migration/HttpStreamProtocolMigrationV1.java
new file mode 100644
index 0000000000..f09fcc3052
--- /dev/null
+++
b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/migration/HttpStreamProtocolMigrationV1.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.connect.iiot.migration;
+
+import org.apache.streampipes.connect.iiot.protocol.stream.HttpStreamProtocol;
+import
org.apache.streampipes.extensions.api.extractor.IStaticPropertyExtractor;
+import org.apache.streampipes.extensions.api.migration.IAdapterMigrator;
+import org.apache.streampipes.model.connect.adapter.AdapterDescription;
+import org.apache.streampipes.model.extensions.svcdiscovery.SpServiceTagPrefix;
+import org.apache.streampipes.model.migration.MigrationResult;
+import org.apache.streampipes.model.migration.ModelMigratorConfig;
+import org.apache.streampipes.sdk.StaticProperties;
+import org.apache.streampipes.sdk.helpers.Alternatives;
+import org.apache.streampipes.sdk.helpers.Labels;
+
+public class HttpStreamProtocolMigrationV1 implements IAdapterMigrator {
+
+ private static final String AUTH_MODE = "auth-mode";
+ private static final String AUTH_NONE = "auth-none";
+ private static final String AUTH_BEARER = "auth-bearer";
+ private static final String BEARER_TOKEN = "bearer-token";
+
+ @Override
+ public ModelMigratorConfig config() {
+ return new ModelMigratorConfig(
+ HttpStreamProtocol.ID,
+ SpServiceTagPrefix.ADAPTER,
+ 0,
+ 1
+ );
+ }
+
+ @Override
+ public MigrationResult<AdapterDescription> migrate(AdapterDescription
element,
+ IStaticPropertyExtractor
extractor) throws RuntimeException {
+ element.getConfig().add(
+ StaticProperties.alternatives(
+ Labels.withId(AUTH_MODE),
+ Alternatives.from(Labels.withId(AUTH_NONE), true),
+ Alternatives.from(
+ Labels.withId(AUTH_BEARER),
+
StaticProperties.stringFreeTextProperty(Labels.withId(BEARER_TOKEN)))
+ )
+ );
+ return MigrationResult.success(element);
+ }
+}
diff --git
a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpStreamProtocol.java
b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpStreamProtocol.java
index 87d945428a..47bf4d0921 100644
---
a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpStreamProtocol.java
+++
b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/HttpStreamProtocol.java
@@ -34,7 +34,9 @@ import
org.apache.streampipes.extensions.management.connect.adapter.parser.Parse
import
org.apache.streampipes.extensions.management.connect.adapter.util.PollingSettings;
import org.apache.streampipes.model.connect.guess.SampleData;
import org.apache.streampipes.model.extensions.ExtensionAssetType;
+import org.apache.streampipes.sdk.StaticProperties;
import org.apache.streampipes.sdk.builder.adapter.AdapterConfigurationBuilder;
+import org.apache.streampipes.sdk.helpers.Alternatives;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
@@ -54,6 +56,10 @@ public class HttpStreamProtocol implements
StreamPipesAdapter, IPullAdapter {
private static final String URL_PROPERTY = "url";
private static final String INTERVAL_PROPERTY = "interval";
+ private static final String AUTH_MODE = "auth-mode";
+ private static final String AUTH_NONE = "auth-none";
+ private static final String AUTH_BEARER = "auth-bearer";
+ private static final String BEARER_TOKEN = "bearer-token";
private String url;
private String accessToken;
@@ -71,9 +77,12 @@ public class HttpStreamProtocol implements
StreamPipesAdapter, IPullAdapter {
this.url = extractor.singleValueParameter(URL_PROPERTY, String.class);
int interval = extractor.singleValueParameter(INTERVAL_PROPERTY,
Integer.class);
this.pollingSettings = PollingSettings.from(TimeUnit.SECONDS, interval);
- // TODO change access token to an optional parameter
-// String accessToken =
extractor.singleValue(ACCESS_TOKEN_PROPERTY);
- this.accessToken = "";
+ String selectedAuthMode =
extractor.selectedAlternativeInternalId(AUTH_MODE);
+ if (AUTH_BEARER.equals(selectedAuthMode)) {
+ this.accessToken = extractor.singleValueParameter(BEARER_TOKEN,
String.class);
+ } else {
+ this.accessToken = null;
+ }
}
private InputStream getDataFromEndpoint() throws ParseException {
@@ -83,7 +92,7 @@ public class HttpStreamProtocol implements
StreamPipesAdapter, IPullAdapter {
.connectTimeout(1000)
.socketTimeout(100000);
- if (this.accessToken != null && !this.accessToken.equals("")) {
+ if (this.accessToken != null && !this.accessToken.isEmpty()) {
request.setHeader("Authorization", "Bearer " + this.accessToken);
}
@@ -105,12 +114,18 @@ public class HttpStreamProtocol implements
StreamPipesAdapter, IPullAdapter {
@Override
public IAdapterConfiguration declareConfig() {
return AdapterConfigurationBuilder
- .create(ID, 0, HttpStreamProtocol::new)
+ .create(ID, 1, HttpStreamProtocol::new)
.withSupportedParsers(Parsers.defaultParsers())
.withAssets(ExtensionAssetType.DOCUMENTATION, ExtensionAssetType.ICON)
.withLocales(Locales.EN)
.requiredTextParameter(Labels.withId(URL_PROPERTY))
.requiredIntegerParameter(Labels.withId(INTERVAL_PROPERTY))
+ .requiredAlternatives(
+ Labels.withId(AUTH_MODE),
+ Alternatives.from(Labels.withId(AUTH_NONE), true),
+ Alternatives.from(
+ Labels.withId(AUTH_BEARER),
+
StaticProperties.stringFreeTextProperty(Labels.withId(BEARER_TOKEN))))
.buildConfiguration();
}
@@ -128,7 +143,7 @@ public class HttpStreamProtocol implements
StreamPipesAdapter, IPullAdapter {
@Override
public void onAdapterStopped(IAdapterParameterExtractor extractor,
- IAdapterRuntimeContext adapterRuntimeContext)
throws AdapterException {
+ IAdapterRuntimeContext adapterRuntimeContext) {
this.pullAdapterScheduler.shutdown();
}
diff --git
a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/resources/org.apache.streampipes.connect.iiot.protocol.stream.http/strings.en
b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/resources/org.apache.streampipes.connect.iiot.protocol.stream.http/strings.en
index ac361ccaa3..4b2db9c15d 100644
---
a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/resources/org.apache.streampipes.connect.iiot.protocol.stream.http/strings.en
+++
b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/resources/org.apache.streampipes.connect.iiot.protocol.stream.http/strings.en
@@ -25,4 +25,15 @@ url.description=Example: http(s)://test-server.com
interval.title=Interval [sec]
interval.description=Example: 5 (Polling interval in seconds)
+auth-mode.title=Authentication
+auth-mode.description=Select authentication mode
+
+auth-none.title=None
+auth-none.description=No authentication
+
+auth-bearer.title=Bearer token
+auth-bearer.description=Use a bearer token for authentication
+
+bearer-token.title=Bearer token
+bearer-token.description=Paste the bearer token