author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 14917 | bf08557604f8 |
child 30376 | 2ccf2cf7ea48 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
14917
diff
changeset
|
2 |
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test ProviderTest.java |
|
26 |
* @summary Tests jar services provider are called |
|
27 |
* @run clean ProviderTest provider.JMXConnectorProviderImpl provider.JMXConnectorServerProviderImpl |
|
28 |
* @run build ProviderTest provider.JMXConnectorProviderImpl provider.JMXConnectorServerProviderImpl |
|
29 |
* @run main ProviderTest |
|
30 |
*/ |
|
31 |
||
32 |
import java.net.MalformedURLException; |
|
33 |
||
34 |
import javax.management.remote.JMXConnectorFactory; |
|
35 |
import javax.management.remote.JMXConnectorServerFactory; |
|
36 |
import javax.management.remote.JMXConnector; |
|
37 |
import javax.management.remote.JMXConnectorServer; |
|
38 |
import javax.management.remote.JMXServiceURL; |
|
39 |
import javax.management.remote.JMXProviderException; |
|
40 |
||
41 |
||
42 |
import javax.management.MBeanServerConnection; |
|
43 |
import javax.management.MBeanServerFactory; |
|
44 |
import javax.management.MBeanServer; |
|
45 |
||
46 |
/* |
|
47 |
* Tests jar services provider are called |
|
48 |
*/ |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
49 |
import provider.JMXConnectorProviderImpl; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
50 |
import provider.JMXConnectorServerProviderImpl; |
2 | 51 |
public class ProviderTest { |
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
52 |
|
2 | 53 |
public static void main(String[] args) throws Exception { |
54 |
System.out.println("Starting ProviderTest"); |
|
55 |
MBeanServer mbs = MBeanServerFactory.newMBeanServer(); |
|
56 |
||
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
57 |
// First do the test with a protocol handled by Service providers |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
58 |
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); |
2 | 59 |
dotest(url, mbs); |
60 |
||
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
61 |
boolean clientCalled = provider.JMXConnectorProviderImpl.called(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
62 |
boolean serverCalled = provider.JMXConnectorServerProviderImpl.called(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
63 |
boolean ok = clientCalled && serverCalled; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
64 |
if (!ok) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
65 |
if (!clientCalled) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
66 |
System.out.println("Client provider not called"); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
67 |
if (!serverCalled) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
2
diff
changeset
|
68 |
System.out.println("Server provider not called"); |
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
69 |
throw new RuntimeException("Test failed - see log for details"); |
2 | 70 |
} |
71 |
||
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
72 |
// The Service Provider doesn't handle IIOP. Default providers MUST |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
73 |
// be called, which may or may not support IIOP. |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
74 |
url = new JMXServiceURL("service:jmx:iiop://"); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
75 |
try { |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
76 |
dotest(url, mbs); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
77 |
} catch (MalformedURLException e) { |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
78 |
try { |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
79 |
Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie"); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
80 |
e.printStackTrace(System.out); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
81 |
throw new RuntimeException("MalformedURLException throw but IIOP appears to be supported"); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
82 |
} catch (ClassNotFoundException expected) { } |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
83 |
System.out.println("MalformedURLException thrown, IIOP transport not supported"); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
84 |
} |
2 | 85 |
|
86 |
// Unsupported protocol. |
|
87 |
JMXConnectorServer server = null; |
|
88 |
JMXConnector client = null; |
|
89 |
url = |
|
90 |
new JMXServiceURL("service:jmx:unknown-protocol://"); |
|
91 |
try { |
|
92 |
server = |
|
93 |
JMXConnectorServerFactory.newJMXConnectorServer(url, |
|
94 |
null, |
|
95 |
mbs); |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
96 |
throw new RuntimeException("Exception not thrown."); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
97 |
} catch (MalformedURLException e) { |
2 | 98 |
System.out.println("Expected MalformedURLException thrown."); |
99 |
} |
|
100 |
||
101 |
try { |
|
102 |
client = |
|
103 |
JMXConnectorFactory.newJMXConnector(url, |
|
104 |
null); |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
105 |
throw new RuntimeException("Exception not thrown."); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
106 |
} catch (MalformedURLException e) { |
2 | 107 |
System.out.println("Expected MalformedURLException thrown."); |
108 |
} |
|
109 |
||
110 |
//JMXConnectorProviderException |
|
111 |
url = |
|
112 |
new JMXServiceURL("service:jmx:throw-provider-exception://"); |
|
113 |
try { |
|
114 |
server = |
|
115 |
JMXConnectorServerFactory.newJMXConnectorServer(url, |
|
116 |
null, |
|
117 |
mbs); |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
118 |
throw new RuntimeException("Exception not thrown."); |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
119 |
} catch(JMXProviderException e) { |
2 | 120 |
System.out.println("Expected JMXProviderException thrown."); |
121 |
} |
|
122 |
||
123 |
try { |
|
124 |
client = |
|
125 |
JMXConnectorFactory.newJMXConnector(url, |
|
126 |
null); |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
127 |
throw new RuntimeException("Exception not thrown."); |
2 | 128 |
}catch(JMXProviderException e) { |
129 |
System.out.println("Expected JMXProviderException thrown."); |
|
130 |
} |
|
131 |
||
132 |
System.out.println("Test OK"); |
|
133 |
} |
|
134 |
||
135 |
private static void dotest(JMXServiceURL url, MBeanServer mbs) |
|
136 |
throws Exception { |
|
137 |
JMXConnectorServer server = null; |
|
138 |
JMXConnector client = null; |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
139 |
|
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
140 |
server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); |
2 | 141 |
server.start(); |
142 |
JMXServiceURL outputAddr = server.getAddress(); |
|
143 |
System.out.println("Server started ["+ outputAddr+ "]"); |
|
144 |
||
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
5506
diff
changeset
|
145 |
client = JMXConnectorFactory.newJMXConnector(outputAddr, null); |
2 | 146 |
|
147 |
client.connect(); |
|
148 |
System.out.println("Client connected"); |
|
149 |
||
150 |
MBeanServerConnection connection |
|
151 |
= client.getMBeanServerConnection(); |
|
152 |
||
153 |
System.out.println(connection.getDefaultDomain()); |
|
154 |
} |
|
155 |
} |