author | hb |
Mon, 01 Jan 2018 23:59:14 +0530 | |
branch | jmx-rest-api |
changeset 56002 | 60ab3b595a8e |
parent 55998 | 54779691e11f |
child 56003 | 4f7f76f6be2f |
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(); |
|
56002 | 25 |
System.setProperty("test.src",System.getProperty("user.dir") + "/test"); |
55994 | 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 |
||
56002 | 67 |
private void setupManagementConfig(String fileName) throws IOException { |
55994 | 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); |
|
55998
54779691e11f
Code cleanup - PlatformMBeanServer, MBeanServerResource
hb
parents:
55995
diff
changeset
|
71 |
props.setProperty("com.sun.management.jmxremote.authenticate", "false"); |
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); |
|
56002 | 87 |
setupManagementConfig(configFile); |
55994 | 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) { |
|
55998
54779691e11f
Code cleanup - PlatformMBeanServer, MBeanServerResource
hb
parents:
55995
diff
changeset
|
96 |
PlatformRestAdapter.init(props); |
55994 | 97 |
} |
98 |
} |
|
99 |
} |