Skip to content

Commit 8a781ba

Browse files
committed
add ssl rmi registry support in app container
1 parent e426eed commit 8a781ba

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public class TestAppContainer extends GenericContainer<TestAppContainer> {
2828
private String login;
2929
private String pwd;
3030
private boolean jmxSsl;
31+
private boolean jmxSslRegistry;
3132
private Path keyStore;
3233
private String keyStorePassword;
3334
private Path trustStore;
3435
private String trustStorePassword;
36+
private int jmxPort;
37+
private int jmxRmiPort;
3538

3639
public TestAppContainer() {
3740
super("openjdk:8u272-jre-slim");
@@ -55,7 +58,7 @@ public TestAppContainer() {
5558
*/
5659
@CanIgnoreReturnValue
5760
public TestAppContainer withJmxPort(int port) {
58-
properties.put("com.sun.management.jmxremote.port", Integer.toString(port));
61+
this.jmxPort = port;
5962
return this;
6063
}
6164

@@ -72,6 +75,13 @@ public TestAppContainer withJmxSsl() {
7275
return this;
7376
}
7477

78+
@CanIgnoreReturnValue
79+
public TestAppContainer withSslRmiRegistry(int registryPort) {
80+
this.jmxSslRegistry = true;
81+
this.jmxRmiPort = registryPort;
82+
return this;
83+
}
84+
7585
@CanIgnoreReturnValue
7686
public TestAppContainer withKeyStore(Path keyStore, String password) {
7787
this.keyStore = keyStore;
@@ -88,7 +98,19 @@ public TestAppContainer withTrustStore(Path trustStore, String password) {
8898

8999
@Override
90100
public void start() {
101+
properties.put("com.sun.management.jmxremote.port", Integer.toString(jmxPort));
102+
91103
properties.put("com.sun.management.jmxremote.ssl", Boolean.toString(jmxSsl));
104+
if (jmxSslRegistry) {
105+
properties.put("com.sun.management.jmxremote.registry.ssl", "true");
106+
properties.put("com.sun.management.jmxremote.rmi.port", Integer.toString(jmxRmiPort));
107+
if (jmxRmiPort == jmxPort) {
108+
// making it harder to attempt using the same port
109+
throw new IllegalStateException(
110+
"RMI with SSL registry requires a distinct port from JMX: " + jmxRmiPort);
111+
}
112+
}
113+
92114

93115
if (pwd == null) {
94116
properties.put("com.sun.management.jmxremote.authenticate", "false");

0 commit comments

Comments
 (0)