You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by am...@apache.org on 2026/05/01 07:19:36 UTC
(aries-rsa) branch master updated (13856357 -> 0aa3c39f)
This is an automated email from the ASF dual-hosted git repository.
amichair pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/aries-rsa.git
from 13856357 Bump com.sun.xml.bind:jaxb-osgi from 4.0.5 to 4.0.7 (#84)
new 6733bbd9 ARIES-2203 Fix EventProducer exception invoking one RemoteServiceAdminListener prevents all other listeners from receiving event
new 3477bdf7 Refactor EventAdminSender to decouple methods
new e5bd3cc8 ARIES-2204 Fix EventAdmin event properties not spec-compliant
new e7e2d295 Replace constant name lookup map with switch statement
new 3bc2c85a ARIES-2205 Fix EventAdminSender.notifyEventAdmins potential NPE and leaked service reference
new d924b2c3 ARIES-2206 Delete redundant eapub module (EventAdmin publishing is already implemented in rsa core module's EventAdminSender)
new 0aa3c39f Add EventAdminSenderTest (based on deleted eapub module test)
The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
eapub/Readme.md | 3 -
eapub/bnd.bnd | 18 ---
eapub/pom.xml | 45 ------
.../java/org/apache/aries/rsa/eapub/Activator.java | 39 ------
.../apache/aries/rsa/eapub/EventAdminHelper.java | 151 ---------------------
features/src/main/resources/features.xml | 1 -
pom.xml | 1 -
.../aries/rsa/core/event/EventAdminSender.java | 135 ++++++++++++------
.../apache/aries/rsa/core/event/EventProducer.java | 2 +
.../aries/rsa/core/event/EventAdminSenderTest.java | 52 ++++---
10 files changed, 119 insertions(+), 328 deletions(-)
delete mode 100644 eapub/Readme.md
delete mode 100644 eapub/bnd.bnd
delete mode 100644 eapub/pom.xml
delete mode 100644 eapub/src/main/java/org/apache/aries/rsa/eapub/Activator.java
delete mode 100644 eapub/src/main/java/org/apache/aries/rsa/eapub/EventAdminHelper.java
rename eapub/src/test/java/org/apache/aries/rsa/eapub/EventAdminHelperTest.java => rsa/src/test/java/org/apache/aries/rsa/core/event/EventAdminSenderTest.java (84%)
(aries-rsa) 04/07: Replace constant name lookup map with switch statement
Posted by am...@apache.org.
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 e7e2d295b4356f6c342726d2631ad28ed414748b
Author: Amichai Rothman <am...@apache.org>
AuthorDate: Fri May 1 01:09:03 2026 +0300
Replace constant name lookup map with switch statement
---
.../aries/rsa/core/event/EventAdminSender.java | 31 +++++++++++++---------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
index 9c8ce797..ce65cd75 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
@@ -37,22 +37,11 @@ import org.osgi.service.remoteserviceadmin.ImportReference;
import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
public class EventAdminSender {
- private HashMap<Integer, String> typeToTopic;
+
private BundleContext context;
public EventAdminSender(BundleContext context) {
this.context = context;
- typeToTopic = new HashMap<>();
- typeToTopic.put(RemoteServiceAdminEvent.EXPORT_ERROR, "EXPORT_ERROR");
- typeToTopic.put(RemoteServiceAdminEvent.EXPORT_REGISTRATION, "EXPORT_REGISTRATION");
- typeToTopic.put(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, "EXPORT_UNREGISTRATION");
- typeToTopic.put(RemoteServiceAdminEvent.EXPORT_UPDATE, "EXPORT_UPDATE");
- typeToTopic.put(RemoteServiceAdminEvent.EXPORT_WARNING, "EXPORT_WARNING");
- typeToTopic.put(RemoteServiceAdminEvent.IMPORT_ERROR, "IMPORT_ERROR");
- typeToTopic.put(RemoteServiceAdminEvent.IMPORT_REGISTRATION, "IMPORT_REGISTRATION");
- typeToTopic.put(RemoteServiceAdminEvent.IMPORT_UNREGISTRATION, "IMPORT_UNREGISTRATION");
- typeToTopic.put(RemoteServiceAdminEvent.IMPORT_UPDATE, "IMPORT_UPDATE");
- typeToTopic.put(RemoteServiceAdminEvent.IMPORT_WARNING, "IMPORT_WARNING");
}
private void notifyEventAdmins(Event event) {
@@ -70,12 +59,28 @@ public class EventAdminSender {
}
public void send(RemoteServiceAdminEvent rsae) {
- String type = typeToTopic.get(rsae.getType());
+ String type = getTypeName(rsae.getType());
String topic = "org/osgi/service/remoteserviceadmin/" + type;
Map<String, Object> props = createProps(rsae);
Event event = new Event(topic, props);
notifyEventAdmins(event);
}
+
+ private static String getTypeName(int type) {
+ switch (type) {
+ case RemoteServiceAdminEvent.EXPORT_ERROR: return "EXPORT_ERROR";
+ case RemoteServiceAdminEvent.EXPORT_REGISTRATION: return "EXPORT_REGISTRATION";
+ case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION: return "EXPORT_UNREGISTRATION";
+ case RemoteServiceAdminEvent.EXPORT_UPDATE: return "EXPORT_UPDATE";
+ case RemoteServiceAdminEvent.EXPORT_WARNING: return "EXPORT_WARNING";
+ case RemoteServiceAdminEvent.IMPORT_ERROR: return "IMPORT_ERROR";
+ case RemoteServiceAdminEvent.IMPORT_REGISTRATION: return "IMPORT_REGISTRATION";
+ case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION: return "IMPORT_UNREGISTRATION";
+ case RemoteServiceAdminEvent.IMPORT_UPDATE: return "IMPORT_UPDATE";
+ case RemoteServiceAdminEvent.IMPORT_WARNING: return "IMPORT_WARNING";
+ default: return "UNKNOWN_REMOTE_EVENT";
+ }
+ }
private static <K, V> void putIfNotNull(Map<K, V> map, K key, V val) {
if (val != null) {
(aries-rsa) 06/07: ARIES-2206 Delete redundant eapub module (EventAdmin publishing is already implemented in rsa core module's EventAdminSender)
Posted by am...@apache.org.
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 d924b2c3b05101958b2d89321e71c32df78b1843
Author: Amichai Rothman <am...@apache.org>
AuthorDate: Thu Apr 30 01:58:56 2026 +0300
ARIES-2206 Delete redundant eapub module (EventAdmin publishing is already implemented in rsa core module's EventAdminSender)
---
eapub/Readme.md | 3 -
eapub/bnd.bnd | 18 --
eapub/pom.xml | 45 -----
.../java/org/apache/aries/rsa/eapub/Activator.java | 39 ----
.../apache/aries/rsa/eapub/EventAdminHelper.java | 151 ----------------
.../aries/rsa/eapub/EventAdminHelperTest.java | 196 ---------------------
features/src/main/resources/features.xml | 1 -
pom.xml | 1 -
8 files changed, 454 deletions(-)
diff --git a/eapub/Readme.md b/eapub/Readme.md
deleted file mode 100644
index 5fd3dbf9..00000000
--- a/eapub/Readme.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Remote Service Admin EventAdmin Publisher
-
-Is used to publish EventAdmin events for Remote Service Admin events notifications.
diff --git a/eapub/bnd.bnd b/eapub/bnd.bnd
deleted file mode 100644
index c8925571..00000000
--- a/eapub/bnd.bnd
+++ /dev/null
@@ -1,18 +0,0 @@
-
-# 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.
-Bundle-Activator: org.apache.aries.rsa.eapub.Activator
diff --git a/eapub/pom.xml b/eapub/pom.xml
deleted file mode 100644
index 04738044..00000000
--- a/eapub/pom.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version='1.0' encoding='UTF-8' ?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.aries.rsa</groupId>
- <artifactId>org.apache.aries.rsa.parent</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- <relativePath>../parent/pom.xml</relativePath>
- </parent>
- <artifactId>org.apache.aries.rsa.eapub</artifactId>
- <packaging>jar</packaging>
- <name>Aries Remote Service Admin Event Publisher</name>
- <description>The Remote Service Event Admin Publisher</description>
-
- <properties>
- <topDirectoryLocation>..</topDirectoryLocation>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.aries.rsa</groupId>
- <artifactId>org.apache.aries.rsa.spi</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
-</project>
\ No newline at end of file
diff --git a/eapub/src/main/java/org/apache/aries/rsa/eapub/Activator.java b/eapub/src/main/java/org/apache/aries/rsa/eapub/Activator.java
deleted file mode 100644
index e1a8df5c..00000000
--- a/eapub/src/main/java/org/apache/aries/rsa/eapub/Activator.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.aries.rsa.eapub;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;
-
-public class Activator implements BundleActivator {
-
- private ServiceRegistration<RemoteServiceAdminListener> registration;
-
- public void start(BundleContext bundlecontext) throws Exception {
- registration = bundlecontext.registerService(
- RemoteServiceAdminListener.class, new EventAdminHelper(bundlecontext), null);
- }
-
- public void stop(BundleContext context) throws Exception {
- registration.unregister();
- }
-
-}
diff --git a/eapub/src/main/java/org/apache/aries/rsa/eapub/EventAdminHelper.java b/eapub/src/main/java/org/apache/aries/rsa/eapub/EventAdminHelper.java
deleted file mode 100644
index 88c19be6..00000000
--- a/eapub/src/main/java/org/apache/aries/rsa/eapub/EventAdminHelper.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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.aries.rsa.eapub;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.Version;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.service.remoteserviceadmin.EndpointDescription;
-import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
-import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class EventAdminHelper implements RemoteServiceAdminListener {
-
- private static final Logger LOG = LoggerFactory.getLogger(EventAdminHelper.class);
-
- private BundleContext bctx;
-
- public EventAdminHelper(BundleContext bc) {
- bctx = bc;
- }
-
- private Event createEvent(Map<String, Object> props, String type) {
- String topic = "org/osgi/service/remoteserviceadmin/" + type;
- props.put("bundle", bctx.getBundle());
- props.put("bundle.id", bctx.getBundle().getBundleId());
- props.put("bundle.symbolicname", bctx.getBundle().getSymbolicName());
-
- String version = bctx.getBundle().getHeaders().get("Bundle-Version");
- Version v = version != null ? new Version(version) : Version.emptyVersion;
- setIfNotNull(props, "bundle.version", v);
-
- return new Event(topic, props);
- }
-
- @Override
- public void remoteAdminEvent(RemoteServiceAdminEvent rsae) {
- String topic = remoteServiceAdminEventTypeToString(rsae.getType());
-
- Map<String, Object> props = new HashMap<>();
- setIfNotNull(props, "cause", rsae.getException());
-
- EndpointDescription endpoint = null;
- if (rsae.getImportReference() != null) {
- endpoint = rsae.getImportReference().getImportedEndpoint();
- setIfNotNull(props, "import.registration", endpoint);
- } else if (rsae.getExportReference() != null) {
- endpoint = rsae.getExportReference().getExportedEndpoint();
- setIfNotNull(props, "export.registration", endpoint);
- }
-
- if (endpoint != null) {
- setIfNotNull(props, "service.remote.id", endpoint.getServiceId());
- setIfNotNull(props, "service.remote.uuid", endpoint.getFrameworkUUID());
- setIfNotNull(props, "service.remote.uri", endpoint.getId());
- setIfNotNull(props, "objectClass", endpoint.getInterfaces().toArray(new String[0]));
- setIfNotNull(props, "service.imported.configs", endpoint.getConfigurationTypes());
- }
- props.put("timestamp", System.currentTimeMillis());
- props.put("event", rsae);
-
- Event event = createEvent(props, topic);
- notifyEventAdmins(topic, event);
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private void notifyEventAdmins(String topic, Event event) {
- ServiceReference[] refs = null;
- try {
- refs = bctx.getAllServiceReferences(EventAdmin.class.getName(), null);
- } catch (InvalidSyntaxException e) {
- LOG.error("Failed to get EventAdmin: {}", e.getMessage(), e);
- }
-
- if (refs != null) {
- LOG.debug("Publishing event to {} EventAdmins; Topic:[{}]", refs.length, topic);
- for (ServiceReference serviceReference : refs) {
- EventAdmin eventAdmin = (EventAdmin) bctx.getService(serviceReference);
- try {
- eventAdmin.postEvent(event);
- } finally {
- if (eventAdmin != null) {
- bctx.ungetService(serviceReference);
- }
- }
- }
- }
- }
-
- private <K, V> void setIfNotNull(Map<K, V> map, K key, V val) {
- if (val != null) {
- map.put(key, val);
- }
- }
-
- private static String remoteServiceAdminEventTypeToString(int type) {
- String retval;
- switch (type) {
- case RemoteServiceAdminEvent.EXPORT_ERROR:
- retval = "EXPORT_ERROR";
- break;
- case RemoteServiceAdminEvent.EXPORT_REGISTRATION:
- retval = "EXPORT_REGISTRATION";
- break;
- case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION:
- retval = "EXPORT_UNREGISTRATION";
- break;
- case RemoteServiceAdminEvent.EXPORT_WARNING:
- retval = "EXPORT_WARNING";
- break;
- case RemoteServiceAdminEvent.IMPORT_ERROR:
- retval = "IMPORT_ERROR";
- break;
- case RemoteServiceAdminEvent.IMPORT_REGISTRATION:
- retval = "IMPORT_REGISTRATION";
- break;
- case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION:
- retval = "IMPORT_UNREGISTRATION";
- break;
- case RemoteServiceAdminEvent.IMPORT_WARNING:
- retval = "IMPORT_WARNING";
- break;
- default:
- retval = "UNKNOWN_EVENT";
- }
- return retval;
- }
-}
diff --git a/eapub/src/test/java/org/apache/aries/rsa/eapub/EventAdminHelperTest.java b/eapub/src/test/java/org/apache/aries/rsa/eapub/EventAdminHelperTest.java
deleted file mode 100644
index 0965b164..00000000
--- a/eapub/src/test/java/org/apache/aries/rsa/eapub/EventAdminHelperTest.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * 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.aries.rsa.eapub;
-
-import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.UUID;
-
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
-import org.junit.Assert;
-import org.junit.Test;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.Version;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.service.remoteserviceadmin.EndpointDescription;
-import org.osgi.service.remoteserviceadmin.ExportReference;
-import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
-
-@SuppressWarnings({"rawtypes", "unchecked"})
-public class EventAdminHelperTest {
-
- @Test
- public void testPublishNotification() throws Exception {
- final EndpointDescription epd = EasyMock.createNiceMock(EndpointDescription.class);
- EasyMock.expect(epd.getServiceId()).andReturn(Long.MAX_VALUE).anyTimes();
- final String uuid = UUID.randomUUID().toString();
- EasyMock.expect(epd.getFrameworkUUID()).andReturn(uuid).anyTimes();
- EasyMock.expect(epd.getId()).andReturn("foo://bar").anyTimes();
- final List<String> interfaces = Arrays.asList("org.foo.Bar", "org.boo.Far");
- EasyMock.expect(epd.getInterfaces()).andReturn(interfaces).anyTimes();
- EasyMock.expect(epd.getConfigurationTypes()).andReturn(Arrays.asList("org.apache.cxf.ws")).anyTimes();
- EasyMock.replay(epd);
- final ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
- EasyMock.replay(sref);
- final ExportReference er = EasyMock.createNiceMock(ExportReference.class);
- EasyMock.expect(er.getExportedEndpoint()).andReturn(epd).anyTimes();
- EasyMock.expect(er.getExportedService()).andReturn(sref).anyTimes();
- EasyMock.replay(er);
-
- final Bundle bundle = EasyMock.createNiceMock(Bundle.class);
- EasyMock.expect(bundle.getBundleId()).andReturn(42L).anyTimes();
- EasyMock.expect(bundle.getSymbolicName()).andReturn("test.bundle").anyTimes();
- Dictionary<String, String> headers = new Hashtable<>();
- headers.put("Bundle-Version", "1.2.3.test");
- EasyMock.expect(bundle.getHeaders()).andReturn(headers).anyTimes();
- EasyMock.replay(bundle);
-
- EventAdmin ea = EasyMock.createNiceMock(EventAdmin.class);
- ea.postEvent(EasyMock.anyObject());
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
- @Override
- public Object answer() throws Throwable {
- Event event = (Event) EasyMock.getCurrentArguments()[0];
-
- Assert.assertEquals("org/osgi/service/remoteserviceadmin/EXPORT_REGISTRATION", event.getTopic());
- Assert.assertSame(bundle, event.getProperty("bundle"));
- Assert.assertEquals(42L, event.getProperty("bundle.id"));
- Assert.assertEquals("test.bundle", event.getProperty("bundle.symbolicname"));
- Assert.assertEquals(new Version(1, 2, 3, "test"), event.getProperty("bundle.version"));
- Assert.assertNull(event.getProperty("cause"));
- Assert.assertEquals(epd, event.getProperty("export.registration"));
-
- Assert.assertEquals(Long.MAX_VALUE, event.getProperty("service.remote.id"));
- Assert.assertEquals(uuid, event.getProperty("service.remote.uuid"));
- Assert.assertEquals("foo://bar", event.getProperty("service.remote.uri"));
- Assert.assertArrayEquals(interfaces.toArray(new String[]{}),
- (String[]) event.getProperty("objectClass"));
-
- Assert.assertNotNull(event.getProperty("timestamp"));
-
- RemoteServiceAdminEvent rsae = (RemoteServiceAdminEvent) event.getProperty("event");
- Assert.assertNull(rsae.getException());
- Assert.assertEquals(RemoteServiceAdminEvent.EXPORT_REGISTRATION, rsae.getType());
- Assert.assertSame(bundle, rsae.getSource());
- ExportReference er = rsae.getExportReference();
- Assert.assertSame(epd, er.getExportedEndpoint());
- Assert.assertSame(sref, er.getExportedService());
-
- return null;
- }
- });
- EasyMock.replay(ea);
-
- ServiceReference eaSref = EasyMock.createNiceMock(ServiceReference.class);
- EasyMock.replay(eaSref);
-
- BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.expect(bc.getBundle()).andReturn(bundle).anyTimes();
- EasyMock.expect(bc.getAllServiceReferences(EventAdmin.class.getName(), null))
- .andReturn(new ServiceReference[] {eaSref}).anyTimes();
- EasyMock.expect(bc.getService(eaSref)).andReturn(ea).anyTimes();
- EasyMock.replay(bc);
-
- RemoteServiceAdminEvent event = new RemoteServiceAdminEvent(
- RemoteServiceAdminEvent.EXPORT_REGISTRATION,
- bundle,
- er,
- null
- );
- new EventAdminHelper(bc).remoteAdminEvent(event);
- EasyMock.verify(epd, sref, er, ea, eaSref, bc);
- }
-
- @Test
- public void testPublishErrorNotification() throws Exception {
- final EndpointDescription epd = EasyMock.createNiceMock(EndpointDescription.class);
- EasyMock.expect(epd.getInterfaces()).andReturn(Arrays.asList("org.foo.Bar")).anyTimes();
- EasyMock.replay(epd);
- final ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
- EasyMock.replay(sref);
- final ExportReference er = EasyMock.createNiceMock(ExportReference.class);
- EasyMock.expect(er.getExportedEndpoint()).andReturn(epd).anyTimes();
- EasyMock.expect(er.getExportedService()).andReturn(sref).anyTimes();
- EasyMock.replay(er);
-
- final Bundle bundle = EasyMock.createNiceMock(Bundle.class);
- EasyMock.expect(bundle.getBundleId()).andReturn(42L).anyTimes();
- EasyMock.expect(bundle.getSymbolicName()).andReturn("test.bundle").anyTimes();
- EasyMock.expect(bundle.getHeaders()).andReturn(new Hashtable<>()).anyTimes();
- EasyMock.replay(bundle);
-
- final Exception exportException = new Exception();
-
- EventAdmin ea = EasyMock.createNiceMock(EventAdmin.class);
- ea.postEvent(EasyMock.anyObject());
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
- @Override
- public Object answer() throws Throwable {
- Event event = (Event) EasyMock.getCurrentArguments()[0];
-
- Assert.assertEquals("org/osgi/service/remoteserviceadmin/EXPORT_ERROR", event.getTopic());
- Assert.assertSame(bundle, event.getProperty("bundle"));
- Assert.assertEquals(42L, event.getProperty("bundle.id"));
- Assert.assertEquals("test.bundle", event.getProperty("bundle.symbolicname"));
- Assert.assertEquals(new Version("0"), event.getProperty("bundle.version"));
- Assert.assertSame(exportException, event.getProperty("cause"));
- Assert.assertEquals(epd, event.getProperty("export.registration"));
- Assert.assertArrayEquals(new String[]{"org.foo.Bar"},
- (String[]) event.getProperty("objectClass"));
-
- RemoteServiceAdminEvent rsae = (RemoteServiceAdminEvent) event.getProperty("event");
- Assert.assertSame(exportException, rsae.getException());
- Assert.assertEquals(RemoteServiceAdminEvent.EXPORT_ERROR, rsae.getType());
- Assert.assertSame(bundle, rsae.getSource());
- ExportReference er = rsae.getExportReference();
- Assert.assertSame(epd, er.getExportedEndpoint());
- Assert.assertSame(sref, er.getExportedService());
-
- return null;
- }
- });
- EasyMock.replay(ea);
-
- ServiceReference eaSref = EasyMock.createNiceMock(ServiceReference.class);
- EasyMock.replay(eaSref);
-
- BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-
- EasyMock.expect(bc.getBundle()).andReturn(bundle).anyTimes();
- EasyMock.expect(bc.getAllServiceReferences(EventAdmin.class.getName(), null))
- .andReturn(new ServiceReference[] {eaSref}).anyTimes();
- EasyMock.expect(bc.getService(eaSref)).andReturn(ea).anyTimes();
- EasyMock.replay(bc);
-
- RemoteServiceAdminEvent event = new RemoteServiceAdminEvent(
- RemoteServiceAdminEvent.EXPORT_ERROR,
- bundle,
- er,
- exportException
- );
- new EventAdminHelper(bc).remoteAdminEvent(event);
- EasyMock.verify(epd, sref, er, ea, eaSref, bc);
- }
-}
diff --git a/features/src/main/resources/features.xml b/features/src/main/resources/features.xml
index b2abff4d..3c98c196 100644
--- a/features/src/main/resources/features.xml
+++ b/features/src/main/resources/features.xml
@@ -26,7 +26,6 @@
<bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.core/${project.version}</bundle>
<bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.topology-manager/${project.version}</bundle>
<bundle>mvn:org.apache.aries.rsa.discovery/org.apache.aries.rsa.discovery.command/${project.version}</bundle>
- <bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.eapub/${project.version}</bundle>
</feature>
<feature name="aries-rsa-provider-tcp" version="${project.version}">
diff --git a/pom.xml b/pom.xml
index 108f9cc7..0762c969 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,6 @@
<module>parent</module>
<module>spi</module>
<module>rsa</module>
- <module>eapub</module>
<module>topology-manager</module>
<module>provider</module>
<module>discovery</module>
(aries-rsa) 07/07: Add EventAdminSenderTest (based on deleted eapub module test)
Posted by am...@apache.org.
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 0aa3c39f1472fb82d8bcf49ffeac6cfcdc986ce1
Author: Amichai Rothman <am...@apache.org>
AuthorDate: Thu Apr 30 02:02:39 2026 +0300
Add EventAdminSenderTest (based on deleted eapub module test)
---
.../aries/rsa/core/event/EventAdminSenderTest.java | 194 +++++++++++++++++++++
1 file changed, 194 insertions(+)
diff --git a/rsa/src/test/java/org/apache/aries/rsa/core/event/EventAdminSenderTest.java b/rsa/src/test/java/org/apache/aries/rsa/core/event/EventAdminSenderTest.java
new file mode 100644
index 00000000..554fb24d
--- /dev/null
+++ b/rsa/src/test/java/org/apache/aries/rsa/core/event/EventAdminSenderTest.java
@@ -0,0 +1,194 @@
+/*
+ * 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.aries.rsa.core.event;
+
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.ExportReference;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
+
+import java.util.*;
+
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class EventAdminSenderTest {
+
+ @Test
+ public void testPublishNotification() throws Exception {
+ final EndpointDescription epd = EasyMock.createNiceMock(EndpointDescription.class);
+ EasyMock.expect(epd.getServiceId()).andReturn(Long.MAX_VALUE).anyTimes();
+ final String uuid = UUID.randomUUID().toString();
+ EasyMock.expect(epd.getFrameworkUUID()).andReturn(uuid).anyTimes();
+ EasyMock.expect(epd.getId()).andReturn("foo://bar").anyTimes();
+ final List<String> interfaces = Arrays.asList("org.foo.Bar", "org.boo.Far");
+ EasyMock.expect(epd.getInterfaces()).andReturn(interfaces).anyTimes();
+ EasyMock.expect(epd.getConfigurationTypes()).andReturn(Arrays.asList("org.apache.cxf.ws")).anyTimes();
+ EasyMock.replay(epd);
+ final ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
+ EasyMock.replay(sref);
+ final ExportReference er = EasyMock.createNiceMock(ExportReference.class);
+ EasyMock.expect(er.getExportedEndpoint()).andReturn(epd).anyTimes();
+ EasyMock.expect(er.getExportedService()).andReturn(sref).anyTimes();
+ EasyMock.replay(er);
+
+ final Bundle bundle = EasyMock.createNiceMock(Bundle.class);
+ EasyMock.expect(bundle.getBundleId()).andReturn(42L).anyTimes();
+ EasyMock.expect(bundle.getSymbolicName()).andReturn("test.bundle").anyTimes();
+ Dictionary<String, String> headers = new Hashtable<>();
+ headers.put("Bundle-Version", "1.2.3.test");
+ EasyMock.expect(bundle.getHeaders()).andReturn(headers).anyTimes();
+ EasyMock.replay(bundle);
+
+ EventAdmin ea = EasyMock.createNiceMock(EventAdmin.class);
+ ea.postEvent(EasyMock.anyObject());
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
+ public Object answer() {
+ Event event = (Event) EasyMock.getCurrentArguments()[0];
+
+ Assert.assertEquals("org/osgi/service/remoteserviceadmin/EXPORT_REGISTRATION", event.getTopic());
+ Assert.assertSame(bundle, event.getProperty("bundle"));
+ Assert.assertEquals(42L, event.getProperty("bundle.id"));
+ Assert.assertEquals("test.bundle", event.getProperty("bundle.symbolicname"));
+ Assert.assertEquals(new Version(1, 2, 3, "test"), event.getProperty("bundle.version"));
+ Assert.assertNull(event.getProperty("exception"));
+ Assert.assertNull(event.getProperty("exception.message"));
+ Assert.assertNull(event.getProperty("exception.class"));
+
+ Assert.assertEquals(Long.MAX_VALUE, event.getProperty("endpoint.service.id"));
+ Assert.assertEquals(uuid, event.getProperty("endpoint.framework.uuid"));
+ Assert.assertEquals("foo://bar", event.getProperty("endpoint.id"));
+ Assert.assertArrayEquals(interfaces.toArray(new String[]{}), (String[]) event.getProperty("objectClass"));
+ Assert.assertEquals(epd.getConfigurationTypes(), event.getProperty("service.imported.configs"));
+
+ Assert.assertNotNull(event.getProperty("timestamp"));
+ Assert.assertTrue((Long)event.getProperty("timestamp") <= System.currentTimeMillis());
+ Assert.assertTrue((Long)event.getProperty("timestamp") > System.currentTimeMillis() - 30000);
+
+ RemoteServiceAdminEvent rsae = (RemoteServiceAdminEvent) event.getProperty("event");
+ Assert.assertNull(rsae.getException());
+ Assert.assertEquals(RemoteServiceAdminEvent.EXPORT_REGISTRATION, rsae.getType());
+ Assert.assertSame(bundle, rsae.getSource());
+ ExportReference er = rsae.getExportReference();
+ Assert.assertSame(epd, er.getExportedEndpoint());
+ Assert.assertSame(sref, er.getExportedService());
+
+ return null;
+ }
+ });
+ EasyMock.replay(ea);
+
+ ServiceReference eaSref = EasyMock.createNiceMock(ServiceReference.class);
+ EasyMock.replay(eaSref);
+
+ BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+ EasyMock.expect(bc.getBundle()).andReturn(bundle).anyTimes();
+ EasyMock.expect(bc.getServiceReference(EventAdmin.class)).andReturn(eaSref).anyTimes();
+ EasyMock.expect(bc.getService(eaSref)).andReturn(ea).anyTimes();
+ EasyMock.replay(bc);
+
+ RemoteServiceAdminEvent event = new RemoteServiceAdminEvent(
+ RemoteServiceAdminEvent.EXPORT_REGISTRATION,
+ bundle,
+ er,
+ null
+ );
+ new EventAdminSender(bc).send(event);
+ EasyMock.verify(epd, sref, er, ea, eaSref, bc);
+ }
+
+ @Test
+ public void testPublishErrorNotification() throws Exception {
+ final EndpointDescription epd = EasyMock.createNiceMock(EndpointDescription.class);
+ EasyMock.expect(epd.getInterfaces()).andReturn(Arrays.asList("org.foo.Bar")).anyTimes();
+ EasyMock.replay(epd);
+ final ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
+ EasyMock.replay(sref);
+ final ExportReference er = EasyMock.createNiceMock(ExportReference.class);
+ EasyMock.expect(er.getExportedEndpoint()).andReturn(epd).anyTimes();
+ EasyMock.expect(er.getExportedService()).andReturn(sref).anyTimes();
+ EasyMock.replay(er);
+
+ final Bundle bundle = EasyMock.createNiceMock(Bundle.class);
+ EasyMock.expect(bundle.getBundleId()).andReturn(42L).anyTimes();
+ EasyMock.expect(bundle.getSymbolicName()).andReturn("test.bundle").anyTimes();
+ EasyMock.expect(bundle.getHeaders()).andReturn(new Hashtable<>()).anyTimes();
+ EasyMock.replay(bundle);
+
+ final Exception exportException = new Exception();
+
+ EventAdmin ea = EasyMock.createNiceMock(EventAdmin.class);
+ ea.postEvent(EasyMock.anyObject());
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
+ public Object answer() {
+ Event event = (Event) EasyMock.getCurrentArguments()[0];
+
+ Assert.assertEquals("org/osgi/service/remoteserviceadmin/EXPORT_ERROR", event.getTopic());
+ Assert.assertSame(bundle, event.getProperty("bundle"));
+ Assert.assertEquals(42L, event.getProperty("bundle.id"));
+ Assert.assertEquals("test.bundle", event.getProperty("bundle.symbolicname"));
+ Assert.assertEquals(new Version("0"), event.getProperty("bundle.version"));
+ Assert.assertSame(exportException, event.getProperty("exception"));
+ Assert.assertSame(exportException.getMessage(), event.getProperty("exception.message"));
+ Assert.assertSame(exportException.getClass().getName(), event.getProperty("exception.class"));
+ Assert.assertEquals(epd.getConfigurationTypes(), event.getProperty("service.imported.configs"));
+ Assert.assertArrayEquals(new String[]{"org.foo.Bar"}, (String[]) event.getProperty("objectClass"));
+
+ RemoteServiceAdminEvent rsae = (RemoteServiceAdminEvent) event.getProperty("event");
+ Assert.assertSame(exportException, rsae.getException());
+ Assert.assertEquals(RemoteServiceAdminEvent.EXPORT_ERROR, rsae.getType());
+ Assert.assertSame(bundle, rsae.getSource());
+ ExportReference er = rsae.getExportReference();
+ Assert.assertSame(epd, er.getExportedEndpoint());
+ Assert.assertSame(sref, er.getExportedService());
+
+ return null;
+ }
+ });
+ EasyMock.replay(ea);
+
+ ServiceReference eaSref = EasyMock.createNiceMock(ServiceReference.class);
+ EasyMock.replay(eaSref);
+
+ BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+
+ EasyMock.expect(bc.getBundle()).andReturn(bundle).anyTimes();
+ EasyMock.expect(bc.getServiceReference(EventAdmin.class)).andReturn(eaSref).anyTimes();
+ EasyMock.expect(bc.getService(eaSref)).andReturn(ea).anyTimes();
+ EasyMock.replay(bc);
+
+ RemoteServiceAdminEvent event = new RemoteServiceAdminEvent(
+ RemoteServiceAdminEvent.EXPORT_ERROR,
+ bundle,
+ er,
+ exportException
+ );
+ new EventAdminSender(bc).send(event);
+ EasyMock.verify(epd, sref, er, ea, eaSref, bc);
+ }
+}
(aries-rsa) 02/07: Refactor EventAdminSender to decouple methods
Posted by am...@apache.org.
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 3477bdf7ef355c827613dc8faed40f2066dd93e9
Author: Amichai Rothman <am...@apache.org>
AuthorDate: Thu Apr 30 01:31:53 2026 +0300
Refactor EventAdminSender to decouple methods
---
.../aries/rsa/core/event/EventAdminSender.java | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
index e8618e97..724362e1 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
@@ -51,8 +51,7 @@ public class EventAdminSender {
typeToTopic.put(RemoteServiceAdminEvent.IMPORT_WARNING, "IMPORT_WARNING");
}
- public void send(RemoteServiceAdminEvent rsaEvent) {
- final Event event = toEvent(rsaEvent);
+ private void notifyEventAdmins(Event event) {
ServiceReference<EventAdmin> sref = this.context.getServiceReference(EventAdmin.class);
if (sref != null) {
final EventAdmin eventAdmin = this.context.getService(sref);
@@ -66,8 +65,15 @@ public class EventAdminSender {
}
}
- private Event toEvent(RemoteServiceAdminEvent rsaEvent) {
- String topic = getTopic(rsaEvent);
+ public void send(RemoteServiceAdminEvent rsae) {
+ String type = typeToTopic.get(rsae.getType());
+ String topic = "org/osgi/service/remoteserviceadmin/" + type;
+ Map<String, Object> props = createProps(rsae);
+ Event event = new Event(topic, props);
+ notifyEventAdmins(event);
+ }
+
+ private Map<String, Object> createProps(RemoteServiceAdminEvent rsaEvent) {
Map<String, Object> props = new HashMap<>();
Bundle bundle = rsaEvent.getSource();
props.put("bundle", bundle);
@@ -93,10 +99,6 @@ public class EventAdminSender {
}
props.put("timestamp", System.currentTimeMillis());
props.put("event", rsaEvent);
- return new Event(topic, props);
- }
-
- private String getTopic(RemoteServiceAdminEvent rsaEvent) {
- return "org/osgi/service/remoteserviceadmin/" + typeToTopic.get(rsaEvent.getType());
+ return props;
}
}
(aries-rsa) 05/07: ARIES-2205 Fix EventAdminSender.notifyEventAdmins potential NPE and leaked service reference
Posted by am...@apache.org.
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 3bc2c85a7b4cf3117b03d3dd0d4b28ea95cdc09d
Author: Amichai Rothman <am...@apache.org>
AuthorDate: Thu Apr 30 01:54:37 2026 +0300
ARIES-2205 Fix EventAdminSender.notifyEventAdmins potential NPE and leaked service reference
---
.../aries/rsa/core/event/EventAdminSender.java | 30 ++++++++++++++--------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
index ce65cd75..dec33487 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
@@ -35,26 +35,36 @@ import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.osgi.service.remoteserviceadmin.ExportReference;
import org.osgi.service.remoteserviceadmin.ImportReference;
import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class EventAdminSender {
+ private static final Logger LOG = LoggerFactory.getLogger(EventAdminSender.class);
+
private BundleContext context;
public EventAdminSender(BundleContext context) {
this.context = context;
}
- private void notifyEventAdmins(Event event) {
- ServiceReference<EventAdmin> sref = this.context.getServiceReference(EventAdmin.class);
+ private void notifyEventAdmins(String type, Event event) {
+ // according to the EventAdmin specs, we publish to the service with the
+ // highest ranking (which is the one returned by getServiceReference)
+ ServiceReference<EventAdmin> sref = context.getServiceReference(EventAdmin.class);
if (sref != null) {
- final EventAdmin eventAdmin = this.context.getService(sref);
- AccessController.doPrivileged(new PrivilegedAction<Void>() {
- public Void run() {
- eventAdmin.postEvent(event);
- return null;
+ LOG.debug("Publishing event {} to EventAdmin", type);
+ final EventAdmin eventAdmin = context.getService(sref);
+ if (eventAdmin != null) {
+ try {
+ AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+ eventAdmin.postEvent(event);
+ return null;
+ });
+ } finally {
+ context.ungetService(sref);
}
- });
- this.context.ungetService(sref);
+ }
}
}
@@ -63,7 +73,7 @@ public class EventAdminSender {
String topic = "org/osgi/service/remoteserviceadmin/" + type;
Map<String, Object> props = createProps(rsae);
Event event = new Event(topic, props);
- notifyEventAdmins(event);
+ notifyEventAdmins(type, event);
}
private static String getTypeName(int type) {
(aries-rsa) 03/07: ARIES-2204 Fix EventAdmin event properties not spec-compliant
Posted by am...@apache.org.
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 e5bd3cc85414591dff2c38304697d20d0e42e00d
Author: Amichai Rothman <am...@apache.org>
AuthorDate: Thu Apr 30 01:41:12 2026 +0300
ARIES-2204 Fix EventAdmin event properties not spec-compliant
---
.../aries/rsa/core/event/EventAdminSender.java | 64 ++++++++++++++++------
1 file changed, 48 insertions(+), 16 deletions(-)
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
index 724362e1..9c8ce797 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java
@@ -20,15 +20,19 @@ package org.apache.aries.rsa.core.event;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.cert.X509Certificate;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.ExportReference;
import org.osgi.service.remoteserviceadmin.ImportReference;
import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
@@ -73,32 +77,60 @@ public class EventAdminSender {
notifyEventAdmins(event);
}
- private Map<String, Object> createProps(RemoteServiceAdminEvent rsaEvent) {
+ private static <K, V> void putIfNotNull(Map<K, V> map, K key, V val) {
+ if (val != null) {
+ map.put(key, val);
+ }
+ }
+
+ private Map<String, Object> createProps(RemoteServiceAdminEvent rsae) {
Map<String, Object> props = new HashMap<>();
- Bundle bundle = rsaEvent.getSource();
+ // bundle properties
+ Bundle bundle = rsae.getSource();
props.put("bundle", bundle);
props.put("bundle.id", bundle.getBundleId());
props.put("bundle.symbolicname", bundle.getSymbolicName());
- props.put("bundle.version", bundle.getVersion());
- props.put("bundle.signer", ""); // TODO What to put here
- Throwable exception = rsaEvent.getException();
+
+ String version = bundle.getHeaders().get("Bundle-Version");
+ Version v = version != null ? new Version(version) : Version.emptyVersion;
+ putIfNotNull(props, "bundle.version", v);
+
+ Map<X509Certificate, List<X509Certificate>> signers = bundle.getSignerCertificates(Bundle.SIGNERS_ALL);
+ if (signers != null) {
+ String[] names = signers.keySet().stream()
+ .map(cert -> cert.getSubjectX500Principal().getName())
+ .filter(s -> s != null && !s.isEmpty())
+ .toArray(String[]::new);
+ if (names.length > 0) {
+ props.put("bundle.signer", names);
+ }
+ }
+
+ // exception properties
+ Throwable exception = rsae.getException();
if (exception != null) {
props.put("exception", exception);
props.put("exception.class", exception.getClass().getName());
- props.put("exception.message", exception.getMessage());
- }
- if (rsaEvent.getExportReference() != null) {
- EndpointDescription endpoint = rsaEvent.getExportReference().getExportedEndpoint();
- props.put("endpoint.framework.uuid", endpoint.getFrameworkUUID());
- props.put("endpoint.id", endpoint.getId());
- props.put("objectClass", endpoint.getInterfaces());
+ putIfNotNull(props, "exception.message", exception.getMessage());
}
- ImportReference importReference = rsaEvent.getImportReference();
- if (importReference != null && importReference.getImportedEndpoint() != null) {
- props.put("service.imported.configs", importReference.getImportedEndpoint().getConfigurationTypes());
+
+ // endpoint properties
+ ImportReference importReference = rsae.getImportReference();
+ ExportReference exportReference = rsae.getExportReference();
+ EndpointDescription endpoint = importReference == null ? null : importReference.getImportedEndpoint();
+ endpoint = endpoint == null && exportReference != null ? exportReference.getExportedEndpoint() : endpoint;
+ if (endpoint != null) {
+ putIfNotNull(props, "endpoint.service.id", endpoint.getServiceId());
+ putIfNotNull(props, "endpoint.framework.uuid", endpoint.getFrameworkUUID());
+ putIfNotNull(props, "endpoint.id", endpoint.getId());
+ props.put("objectClass", endpoint.getInterfaces().toArray(new String[0]));
+ putIfNotNull(props, "service.imported.configs", endpoint.getConfigurationTypes());
}
+
+ // general properties
props.put("timestamp", System.currentTimeMillis());
- props.put("event", rsaEvent);
+ props.put("event", rsae);
+
return props;
}
}
(aries-rsa) 01/07: ARIES-2203 Fix EventProducer exception invoking one RemoteServiceAdminListener prevents all other listeners from receiving event
Posted by am...@apache.org.
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 6733bbd97be9be094b52b7f450c076063bcd3368
Author: Amichai Rothman <am...@apache.org>
AuthorDate: Wed Apr 29 20:29:25 2026 +0300
ARIES-2203 Fix EventProducer exception invoking one RemoteServiceAdminListener prevents all other listeners from receiving event
---
rsa/src/main/java/org/apache/aries/rsa/core/event/EventProducer.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventProducer.java b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventProducer.java
index 24a06821..93d8b0e8 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/event/EventProducer.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/event/EventProducer.java
@@ -107,6 +107,8 @@ public class EventProducer {
rsal, bundle.getSymbolicName());
rsal.remoteAdminEvent(rsae);
}
+ } catch (RuntimeException re) {
+ LOG.error("unexpected exception when notifying {} of {}", rsal, rsae, re);
} finally {
bctx.ungetService(sref);
}