Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMLII-1314: Improves misbehaving-jmx-server support for firewalled environments #507

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,29 @@ public static void main( String[] args ) throws IOException, MalformedObjectName
// I don't think this call is actually important for jmx, the below 'env' param to JMXConnectorServerFactory is the important one
RMISocketFactory.setSocketFactory(customRMISocketFactory);


// Explicitly set RMI hostname to specified argument value
// This value is returned from the RMI registry as the hostname that the client should connect out to.
System.setProperty("java.rmi.server.hostname", config.rmiHost);

// Initialize RMI registry at same port as the jmx service
// It is ridiculously hard to find good reference docs for the system properties controlling RMI ports.
// There are 3 ports relevant to JMX over RMI
// 1. port that RMI registry is available on. The initial network request for a RMI connection
// comes into this port.
// This java option is the one that controls the RMI registry port
System.setProperty("com.sun.management.jmxremote.rmi.port", "" + config.rmiPort);//
// If we don't create this registry explicitly, the above system property should be used.
LocateRegistry.createRegistry(config.rmiPort, null, customRMISocketFactory);
// 2. port that RMI advertises in the initial handshake. This defaults to a random port unless
// the system property is set. Some docs call this the "RMI Server Port", with there being
// a distinction between "RMI Registry" and "RMI Server".
System.setProperty("com.sun.management.jmxremote.port", "" + config.rmiPort);//
// 3. A local port that is used for the AttachAPI. This doesn't matter for the purposes of our jmx-test-server,
// com.sun.management.jmxremote.local.port=<port#>
//
// References:
// https://www.oracle.com/java/technologies/javase/15all-relnotes.html#JDK-8234484


MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

Expand Down Expand Up @@ -249,7 +267,7 @@ public static void main( String[] args ) throws IOException, MalformedObjectName
// IMPORTANT! Without this, the custom RMI socket factory will not be used for JMX connections
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, customRMISocketFactory);

JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + config.rmiHost + ":" + config.rmiPort + "/jmxrmi");
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + config.rmiPort + "/jmxrmi");
log.info("JMXRMI Service listening at {}", url);
JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);

Expand Down
Loading