You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2021/04/09 05:23:59 UTC

[karaf] branch karaf-4.2.x updated: [KARAF-7096] Ensure that RMIServerImpl_Stub contains correct rmiServerHost

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

jbonofre pushed a commit to branch karaf-4.2.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new eb0d806  [KARAF-7096] Ensure that RMIServerImpl_Stub contains correct rmiServerHost
eb0d806 is described below

commit eb0d806c08eb9021d6675edf641f5772c5c01182
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Thu Apr 8 15:21:18 2021 +0200

    [KARAF-7096] Ensure that RMIServerImpl_Stub contains correct rmiServerHost
    
    (cherry picked from commit b68199f16922febc15db7bddab11f7a1ebf7c376)
---
 .../apache/karaf/management/internal/Activator.java    | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/management/server/src/main/java/org/apache/karaf/management/internal/Activator.java b/management/server/src/main/java/org/apache/karaf/management/internal/Activator.java
index 6d34226..c4f1a21 100644
--- a/management/server/src/main/java/org/apache/karaf/management/internal/Activator.java
+++ b/management/server/src/main/java/org/apache/karaf/management/internal/Activator.java
@@ -60,6 +60,8 @@ public class Activator extends BaseActivator implements ManagedService {
 
     private EventAdminLogger eventAdminLogger;
 
+    private String originalRmiServerHostname;
+
     protected void doStart() throws Exception {
         // Verify dependencies
         ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
@@ -97,6 +99,16 @@ public class Activator extends BaseActivator implements ManagedService {
         String rmiServerHost = getString("rmiServerHost", "0.0.0.0");
         int rmiServerPort = getInt("rmiServerPort", 44444);
 
+        // https://issues.apache.org/jira/browse/KARAF-7096 - rmiServerHost is where
+        // javax.management.remote.rmi.RMIServerImpl will be set up, but the stub is then put into RMI Registry
+        // to be obtained on client side (from JNDI). However, rmiServerHost is used only for
+        // KarafRMIServerSocketFactory/KarafSslRMIServerSocketFactory bind address (correctly), but the
+        // RMIServerImpl_Stub side of RMI object takes the address from java.rmi.server.hostname property.
+        // Because Karaf "takes over" entire RMI registry anyway, we have to change this property here and restore in
+        // doStop();
+        originalRmiServerHostname = System.getProperty("java.rmi.server.hostname");
+        System.setProperty("java.rmi.server.hostname", rmiServerHost);
+
         String jmxRealm = getString("jmxRealm", "karaf");
         String serviceUrl = getString("serviceUrl",
                 "service:jmx:rmi://" + rmiServerHost + ":" + rmiServerPort + "/jndi/rmi://" + rmiRegistryHost + ":" + rmiRegistryPort + "/karaf-" + System.getProperty("karaf.name"));
@@ -246,6 +258,12 @@ public class Activator extends BaseActivator implements ManagedService {
                 eventAdminLogger = null;
             }
         }
+
+        if (originalRmiServerHostname != null) {
+            System.setProperty("java.rmi.server.hostname", originalRmiServerHostname);
+        } else {
+            System.clearProperty("java.rmi.server.hostname");
+        }
     }
 
 }