author | hb |
Tue, 02 Jan 2018 13:20:18 +0530 | |
branch | jmx-rest-api |
changeset 56003 | 4f7f76f6be2f |
parent 56002 | 60ab3b595a8e |
child 56026 | bd531f08d7c7 |
permissions | -rw-r--r-- |
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 javax.management.remote.rest.PlatformRestAdapter; |
|
9 |
||
10 |
||
11 |
/** |
|
12 |
* @test |
|
13 |
* @modules java.logging |
|
14 |
* java.management.rest |
|
15 |
* @run main RunRestAdapter |
|
16 |
*/ |
|
17 |
public class RunRestAdapter { |
|
18 |
||
19 |
private static String sslAgentConfig; |
|
20 |
private static String sslClientConfig; |
|
21 |
private static String configFile; |
|
22 |
||
23 |
public static void main(String[] args) throws Exception { |
|
24 |
RunRestAdapter rr = new RunRestAdapter(); |
|
25 |
rr.run(); |
|
26 |
while (true) |
|
27 |
{ |
|
28 |
Thread.sleep(1000); |
|
29 |
} |
|
30 |
} |
|
31 |
||
32 |
private void createAgentSslConfigFile(String fileName) throws IOException { |
|
33 |
File f = new File(fileName); |
|
34 |
if (f.exists()) { |
|
35 |
return; |
|
36 |
} |
|
37 |
Properties props = new Properties(); |
|
38 |
String testDir = System.getProperty("test.src"); |
|
39 |
props.setProperty("javax.net.ssl.keyStore", testDir + File.separator + "keystoreAgent"); |
|
40 |
props.setProperty("javax.net.ssl.keyStorePassword", "glopglop"); |
|
41 |
props.setProperty("javax.net.ssl.trustStore", testDir + File.separator + "truststoreAgent"); |
|
42 |
props.setProperty("javax.net.ssl.trustStorePassword", "glopglop"); |
|
43 |
||
44 |
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) { |
|
45 |
props.store(writer, ""); |
|
46 |
} |
|
47 |
} |
|
48 |
||
49 |
private void createClientSslConfigFile(String fileName) throws IOException { |
|
50 |
File f = new File(fileName); |
|
51 |
if (f.exists()) { |
|
52 |
return; |
|
53 |
} |
|
54 |
Properties props = new Properties(); |
|
55 |
String testDir = System.getProperty("test.src"); |
|
56 |
props.setProperty("javax.net.ssl.keyStore", testDir + File.separator + "keystoreClient"); |
|
57 |
props.setProperty("javax.net.ssl.keyStorePassword", "glopglop"); |
|
58 |
props.setProperty("javax.net.ssl.trustStore", testDir + File.separator + "truststoreClient"); |
|
59 |
props.setProperty("javax.net.ssl.trustStorePassword", "glopglop"); |
|
60 |
||
61 |
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) { |
|
62 |
props.store(writer, ""); |
|
63 |
} |
|
64 |
} |
|
65 |
||
56002 | 66 |
private void setupManagementConfig(String fileName) throws IOException { |
55994 | 67 |
Properties props = new Properties(); |
68 |
props.setProperty("com.sun.management.jmxremote.ssl", "true"); |
|
69 |
props.setProperty("com.sun.management.jmxremote.ssl.config.file", sslAgentConfig); |
|
55998
54779691e11f
Code cleanup - PlatformMBeanServer, MBeanServerResource
hb
parents:
55995
diff
changeset
|
70 |
props.setProperty("com.sun.management.jmxremote.authenticate", "false"); |
55994 | 71 |
props.setProperty("com.sun.management.jmxremote.rest.port", "8686"); |
72 |
||
73 |
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) { |
|
74 |
props.store(writer, ""); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
private void setupConfig() throws Exception { |
|
79 |
String testSrcRoot = System.getProperty("test.src") + File.separator; |
|
80 |
sslAgentConfig = testSrcRoot + "sslConfigAgent"; |
|
81 |
sslClientConfig = testSrcRoot + "sslConfigClient"; |
|
82 |
||
83 |
configFile = testSrcRoot + "mgmt1.properties"; |
|
84 |
createAgentSslConfigFile(sslAgentConfig); |
|
85 |
createClientSslConfigFile(sslClientConfig); |
|
56002 | 86 |
setupManagementConfig(configFile); |
55994 | 87 |
} |
88 |
||
89 |
public void run() throws Exception { |
|
90 |
setupConfig(); |
|
91 |
File file = new File(configFile); |
|
92 |
Properties props = new Properties(); |
|
93 |
props.load(new FileInputStream(file)); |
|
94 |
if (props.get("com.sun.management.jmxremote.rest.port") != null) { |
|
55998
54779691e11f
Code cleanup - PlatformMBeanServer, MBeanServerResource
hb
parents:
55995
diff
changeset
|
95 |
PlatformRestAdapter.init(props); |
55994 | 96 |
} |
97 |
} |
|
98 |
} |