55994
|
1 |
|
|
2 |
import java.io.BufferedWriter;
|
|
3 |
import java.io.File;
|
|
4 |
import java.io.FileInputStream;
|
|
5 |
import java.io.FileWriter;
|
|
6 |
import java.io.IOException;
|
|
7 |
import java.util.Properties;
|
|
8 |
import java.util.Scanner;
|
|
9 |
import javax.management.remote.rest.PlatformRestAdapter;
|
|
10 |
|
|
11 |
|
|
12 |
/**
|
|
13 |
* @test
|
|
14 |
* @modules java.logging
|
|
15 |
* java.management.rest
|
|
16 |
* @run main RunRestAdapter
|
|
17 |
*/
|
|
18 |
public class RunRestAdapter {
|
|
19 |
|
|
20 |
private static String sslAgentConfig;
|
|
21 |
private static String sslClientConfig;
|
|
22 |
private static String configFile;
|
|
23 |
|
|
24 |
public static void main(String[] args) throws Exception {
|
|
25 |
RunRestAdapter rr = new RunRestAdapter();
|
|
26 |
rr.run();
|
|
27 |
while (true)
|
|
28 |
{
|
|
29 |
Thread.sleep(1000);
|
|
30 |
}
|
|
31 |
}
|
|
32 |
|
|
33 |
private void createAgentSslConfigFile(String fileName) throws IOException {
|
|
34 |
File f = new File(fileName);
|
|
35 |
if (f.exists()) {
|
|
36 |
return;
|
|
37 |
}
|
|
38 |
Properties props = new Properties();
|
|
39 |
String testDir = System.getProperty("test.src");
|
|
40 |
props.setProperty("javax.net.ssl.keyStore", testDir + File.separator + "keystoreAgent");
|
|
41 |
props.setProperty("javax.net.ssl.keyStorePassword", "glopglop");
|
|
42 |
props.setProperty("javax.net.ssl.trustStore", testDir + File.separator + "truststoreAgent");
|
|
43 |
props.setProperty("javax.net.ssl.trustStorePassword", "glopglop");
|
|
44 |
|
|
45 |
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) {
|
|
46 |
props.store(writer, "");
|
|
47 |
}
|
|
48 |
}
|
|
49 |
|
|
50 |
private void createClientSslConfigFile(String fileName) throws IOException {
|
|
51 |
File f = new File(fileName);
|
|
52 |
if (f.exists()) {
|
|
53 |
return;
|
|
54 |
}
|
|
55 |
Properties props = new Properties();
|
|
56 |
String testDir = System.getProperty("test.src");
|
|
57 |
props.setProperty("javax.net.ssl.keyStore", testDir + File.separator + "keystoreClient");
|
|
58 |
props.setProperty("javax.net.ssl.keyStorePassword", "glopglop");
|
|
59 |
props.setProperty("javax.net.ssl.trustStore", testDir + File.separator + "truststoreClient");
|
|
60 |
props.setProperty("javax.net.ssl.trustStorePassword", "glopglop");
|
|
61 |
|
|
62 |
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) {
|
|
63 |
props.store(writer, "");
|
|
64 |
}
|
|
65 |
}
|
|
66 |
|
|
67 |
private void setupMgmtConfig(String fileName) throws IOException {
|
|
68 |
Properties props = new Properties();
|
|
69 |
props.setProperty("com.sun.management.jmxremote.ssl", "true");
|
|
70 |
props.setProperty("com.sun.management.jmxremote.ssl.config.file", sslAgentConfig);
|
55995
|
71 |
props.setProperty("com.sun.management.jmxremote.authenticate", "true");
|
55994
|
72 |
props.setProperty("com.sun.management.jmxremote.rest.port", "8686");
|
|
73 |
|
|
74 |
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) {
|
|
75 |
props.store(writer, "");
|
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
private void setupConfig() throws Exception {
|
|
80 |
String testSrcRoot = System.getProperty("test.src") + File.separator;
|
|
81 |
sslAgentConfig = testSrcRoot + "sslConfigAgent";
|
|
82 |
sslClientConfig = testSrcRoot + "sslConfigClient";
|
|
83 |
|
|
84 |
configFile = testSrcRoot + "mgmt1.properties";
|
|
85 |
createAgentSslConfigFile(sslAgentConfig);
|
|
86 |
createClientSslConfigFile(sslClientConfig);
|
|
87 |
setupMgmtConfig(configFile);
|
|
88 |
}
|
|
89 |
|
|
90 |
public void run() throws Exception {
|
|
91 |
setupConfig();
|
|
92 |
File file = new File(configFile);
|
|
93 |
Properties props = new Properties();
|
|
94 |
props.load(new FileInputStream(file));
|
|
95 |
if (props.get("com.sun.management.jmxremote.rest.port") != null) {
|
|
96 |
PlatformRestAdapter.init((String) props.get("com.sun.management.jmxremote.rest.port"), props);
|
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|