This is an automated email from the ASF dual-hosted git repository.

dominikriemer pushed a commit to branch 
4669-nullpointerexception-when-using-custom-adapter-after-deploying-extension
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to 
refs/heads/4669-nullpointerexception-when-using-custom-adapter-after-deploying-extension
 by this push:
     new 0efe27666b fix: Make transformation script endpoint backwards 
compatible
0efe27666b is described below

commit 0efe27666b73f45075f08564840fcf0402ddc50c
Author: Dominik Riemer <[email protected]>
AuthorDate: Tue Jun 30 17:52:02 2026 +0200

    fix: Make transformation script endpoint backwards compatible
---
 .../TransformationScriptLanguageResource.java      | 43 +++++++++++++------
 .../TransformationScriptLanguageResourceTest.java  | 49 ++++++++++++++++++++++
 2 files changed, 79 insertions(+), 13 deletions(-)

diff --git 
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/connect/TransformationScriptLanguageResource.java
 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/connect/TransformationScriptLanguageResource.java
index 47230151d3..3cca45c77e 100644
--- 
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/connect/TransformationScriptLanguageResource.java
+++ 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/connect/TransformationScriptLanguageResource.java
@@ -24,7 +24,9 @@ import 
org.apache.streampipes.manager.execution.endpoint.ExtensionsServiceEndpoi
 import org.apache.streampipes.model.connect.ScriptMetadata;
 import org.apache.streampipes.model.connect.adapter.AdapterDescription;
 import org.apache.streampipes.rest.security.AuthConstants;
+import 
org.apache.streampipes.model.extensions.svcdiscovery.SpServiceRegistration;
 import org.apache.streampipes.svcdiscovery.SpServiceDiscovery;
+import org.apache.streampipes.svcdiscovery.api.ISpServiceDiscovery;
 import org.apache.streampipes.svcdiscovery.api.model.DefaultSpServiceTypes;
 import org.apache.streampipes.svcdiscovery.api.model.SpServiceUrlProvider;
 
@@ -36,31 +38,39 @@ import 
org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
+import java.util.stream.Stream;
 
 @RestController
 @RequestMapping("/api/v2/connect/master/script-languages")
 public class TransformationScriptLanguageResource {
 
+  private final ISpServiceDiscovery serviceDiscovery;
+
+  public TransformationScriptLanguageResource() {
+    this(SpServiceDiscovery.getServiceDiscovery());
+  }
+
+  TransformationScriptLanguageResource(ISpServiceDiscovery serviceDiscovery) {
+    this.serviceDiscovery = serviceDiscovery;
+  }
+
   @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
   @PreAuthorize(AuthConstants.HAS_WRITE_ADAPTER_PRIVILEGE)
   public List<ScriptMetadata> getAll(@RequestBody AdapterDescription 
adapterDescription) throws
                                                                                
          NoServiceEndpointsAvailableException {
     var languagesSupportedByCore = 
TransformationEngines.INSTANCE.getAvailableEngineMetadata();
-    var matchingServices = SpServiceDiscovery.getServiceDiscovery()
-                                             .getService(
-                                                 DefaultSpServiceTypes.EXT, 
true,
-                                                 
ExtensionsServiceEndpointUtils.getDesiredServiceTags(
-                                                     
adapterDescription.getAppId(),
-                                                     
SpServiceUrlProvider.ADAPTER,
-                                                     
adapterDescription.getDeploymentConfiguration()
-                                                                       
.getDesiredServiceTags()
-                                                 )
-                                             );
+    var matchingServices = serviceDiscovery.getService(
+        DefaultSpServiceTypes.EXT, true,
+        ExtensionsServiceEndpointUtils.getDesiredServiceTags(
+            adapterDescription.getAppId(),
+            SpServiceUrlProvider.ADAPTER,
+            adapterDescription.getDeploymentConfiguration()
+                              .getDesiredServiceTags()
+        )
+    );
 
     if (!matchingServices.isEmpty()) {
-      return matchingServices.get(0)
-                             .getSupportedScriptLanguages()
-                             .stream()
+      return getSupportedScriptLanguages(matchingServices.get(0))
                              .filter(metadata -> languagesSupportedByCore
                                  .stream()
                                  .anyMatch(coreLanguage -> 
coreLanguage.language()
@@ -73,4 +83,11 @@ public class TransformationScriptLanguageResource {
     }
 
   }
+
+  private Stream<ScriptMetadata> getSupportedScriptLanguages(
+      SpServiceRegistration matchingService
+  ) {
+    var supportedScriptLanguages = 
matchingService.getSupportedScriptLanguages();
+    return supportedScriptLanguages == null ? Stream.empty() : 
supportedScriptLanguages.stream();
+  }
 }
diff --git 
a/streampipes-rest/src/test/java/org/apache/streampipes/rest/impl/connect/TransformationScriptLanguageResourceTest.java
 
b/streampipes-rest/src/test/java/org/apache/streampipes/rest/impl/connect/TransformationScriptLanguageResourceTest.java
new file mode 100644
index 0000000000..95153a8b52
--- /dev/null
+++ 
b/streampipes-rest/src/test/java/org/apache/streampipes/rest/impl/connect/TransformationScriptLanguageResourceTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.rest.impl.connect;
+
+import org.apache.streampipes.model.connect.adapter.AdapterDescription;
+import 
org.apache.streampipes.model.extensions.svcdiscovery.SpServiceRegistration;
+import org.apache.streampipes.svcdiscovery.api.ISpServiceDiscovery;
+import org.apache.streampipes.svcdiscovery.api.model.DefaultSpServiceTypes;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class TransformationScriptLanguageResourceTest {
+
+  @Test
+  void shouldIgnoreMissingScriptLanguageMetadataFromOlderExtensionServices() 
throws Exception {
+    var serviceDiscovery = mock(ISpServiceDiscovery.class);
+    when(serviceDiscovery.getService(eq(DefaultSpServiceTypes.EXT), eq(true), 
anyList()))
+        .thenReturn(List.of(new SpServiceRegistration()));
+
+    var result = new TransformationScriptLanguageResource(serviceDiscovery)
+        .getAll(new AdapterDescription());
+
+    assertTrue(result.isEmpty());
+  }
+}

Reply via email to