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

amichair pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-rsa.git

commit 120e82869c2a87e1af39af047c31b106ebdf206d
Author: Amichai Rothman <[email protected]>
AuthorDate: Mon Mar 30 16:17:38 2026 +0300

    ARIES-2220 Fix EndpointDescriptionBundleParser not supporting multiple 
paths in header
---
 .../local/EndpointDescriptionBundleParser.java     | 25 +++++++++++-----
 .../local/EndpointDescriptionBundleParserTest.java | 35 +++++++++++++++++-----
 2 files changed, 45 insertions(+), 15 deletions(-)

diff --git 
a/discovery/local/src/main/java/org/apache/aries/rsa/discovery/local/EndpointDescriptionBundleParser.java
 
b/discovery/local/src/main/java/org/apache/aries/rsa/discovery/local/EndpointDescriptionBundleParser.java
index 6ea325d3..5528036e 100644
--- 
a/discovery/local/src/main/java/org/apache/aries/rsa/discovery/local/EndpointDescriptionBundleParser.java
+++ 
b/discovery/local/src/main/java/org/apache/aries/rsa/discovery/local/EndpointDescriptionBundleParser.java
@@ -20,10 +20,12 @@ package org.apache.aries.rsa.discovery.local;
 
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.aries.rsa.discovery.endpoint.EndpointDescriptionParserImpl;
 import org.osgi.framework.Bundle;
@@ -56,10 +58,15 @@ public final class EndpointDescriptionBundleParser {
         return endpoints;
     }
 
-    private Collection<URL> getEndpointDescriptionURLs(Bundle b) {
-        String path = getRemoteServicesDir(b);
+    private static Collection<URL> getEndpointDescriptionURLs(Bundle b) {
+        return getRemoteServicesPaths(b).stream()
+            .map(path -> findEntries(b, path))
+            .flatMap(Collection::stream)
+            .collect(Collectors.toList());
+    }
 
-        // Split path into dir and file pattern
+    private static Collection<URL> findEntries(Bundle b, String path) {
+        // split path into dir and file pattern
         String dir;
         String pattern;
         int i = path.lastIndexOf('/');
@@ -67,7 +74,7 @@ public final class EndpointDescriptionBundleParser {
             dir = path.substring(0, path.length() - 1);
             pattern = "*.xml";
         } else if (i >= 0) {
-            dir = path.substring(0, i);
+            dir = i == 0 ? "/" : path.substring(0, i);
             pattern = path.substring(i + 1);
         } else {
             dir = "";
@@ -78,9 +85,13 @@ public final class EndpointDescriptionBundleParser {
         return urls == null ? Collections.emptyList() : Collections.list(urls);
     }
 
-    private static String getRemoteServicesDir(Bundle b) {
-        Object header = b.getHeaders().get(REMOTE_SERVICES_HEADER_NAME);
-        return (header == null) ? REMOTE_SERVICES_DIRECTORY : 
header.toString();
+    private static Collection<String> getRemoteServicesPaths(Bundle b) {
+        String header = b.getHeaders().get(REMOTE_SERVICES_HEADER_NAME);
+        return (header == null)
+            ? Collections.singletonList(REMOTE_SERVICES_DIRECTORY)
+            : Arrays.stream(header.split("\\s*,\\s*"))
+                .filter(p -> !p.trim().isEmpty())
+                .collect(Collectors.toList());
     }
 
 }
diff --git 
a/discovery/local/src/test/java/org/apache/aries/rsa/discovery/local/EndpointDescriptionBundleParserTest.java
 
b/discovery/local/src/test/java/org/apache/aries/rsa/discovery/local/EndpointDescriptionBundleParserTest.java
index 29f31c8d..bc98a920 100644
--- 
a/discovery/local/src/test/java/org/apache/aries/rsa/discovery/local/EndpointDescriptionBundleParserTest.java
+++ 
b/discovery/local/src/test/java/org/apache/aries/rsa/discovery/local/EndpointDescriptionBundleParserTest.java
@@ -46,22 +46,29 @@ import static org.junit.Assert.*;
 
 public class EndpointDescriptionBundleParserTest {
 
-    private Bundle createBundleContaining(URL ed1URL) {
+    private Bundle createBundleContaining(URL... urls) {
         Bundle b = EasyMock.createNiceMock(Bundle.class);
-        EasyMock.expect(b.findEntries(
-            EasyMock.eq("OSGI-INF/remote-service"),
-            EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
-                Collections.enumeration(Arrays.asList(ed1URL))).anyTimes();
+        String header = "";
+        for (URL url : urls) {
+            boolean first = url == urls[0];
+            String s = url.toString();
+            int i = s.lastIndexOf('/');
+            String path = first ? "OSGI-INF/remote-service" : "/";
+            String pattern = first ? "*.xml" : s.substring(i + 1);
+            header += (header.isEmpty() ? path + "/" : ", " + path + pattern);
+            EasyMock.expect(b.findEntries(EasyMock.eq(path), 
EasyMock.eq(pattern), EasyMock.anyBoolean()))
+                
.andReturn(Collections.enumeration(Arrays.asList(url))).anyTimes();
+        }
         Dictionary<String, String> headers = new Hashtable<>();
-        headers.put("Remote-Service", "OSGI-INF/remote-service/");
-        EasyMock.expect(b.getHeaders()).andReturn(headers).anyTimes();
+        headers.put("Remote-Service", header);
+        EasyMock.expect(b.getHeaders()).andReturn(headers);
         EasyMock.replay(b);
         return b;
     }
 
     @Test
     public void testNoRemoteServicesXMLFiles() {
-        Bundle b = createBundleContaining(null);
+        Bundle b = createBundleContaining();
 
         List<EndpointDescription> rsElements = new 
EndpointDescriptionBundleParser().getAllEndpointDescriptions(b);
         assertEquals(0, rsElements.size());
@@ -159,6 +166,18 @@ public class EndpointDescriptionBundleParserTest {
                                    
EndpointDescriptionBundleParserTest.normXML((String) l.get(0)));
     }
 
+    @Test
+    public void testTwoPaths() {
+        URL ed1URL = getClass().getResource("/ed1.xml");
+        URL ed2URL = getClass().getResource("/ed1.xml");
+
+        Bundle b = createBundleContaining(ed1URL, ed2URL);
+
+        List<EndpointDescription> endpoints = new 
EndpointDescriptionBundleParser().getAllEndpointDescriptions(b);
+        assertEquals(8, endpoints.size());
+        assertEquals(endpoints.get(0), endpoints.get(4));
+    }
+
     public static String stripProlog(String s) {
         return s.replaceAll("<\\?(.*?)\\?>", "");
     }

Reply via email to