1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
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 *
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.
22 */
166
167 System.out.println("Connecting for client-unknown test");
168
169 JMXConnector client = JMXConnectorFactory.connect(addr, clientMap);
170
171 // add a listener to verify no failed notif
172 CNListener cnListener = new CNListener();
173 client.addConnectionNotificationListener(cnListener, null, null);
174
175 MBeanServerConnection mbsc = client.getMBeanServerConnection();
176
177 System.out.println("Getting attribute with class unknown to client");
178 try {
179 Object result = mbsc.getAttribute(on, "ClientUnknown");
180 System.out.println("TEST FAILS: getAttribute for class " +
181 "unknown to client should fail, returned: " +
182 result);
183 ok = false;
184 } catch (IOException e) {
185 Throwable cause = e.getCause();
186 if (isInstance(cause, "org.omg.CORBA.MARSHAL")) // see CR 4935098
187 cause = cause.getCause();
188 if (cause instanceof ClassNotFoundException) {
189 System.out.println("Success: got an IOException wrapping " +
190 "a ClassNotFoundException");
191 } else {
192 System.out.println("TEST FAILS: Caught IOException (" + e +
193 ") but cause should be " +
194 "ClassNotFoundException: " + cause);
195 ok = false;
196 }
197 }
198
199 System.out.println("Doing queryNames to ensure connection alive");
200 Set<ObjectName> names = mbsc.queryNames(null, null);
201 System.out.println("queryNames returned " + names);
202
203 System.out.println("Provoke exception of unknown class");
204 try {
205 mbsc.invoke(on, "throwClientUnknown", NO_OBJECTS, NO_STRINGS);
206 System.out.println("TEST FAILS: did not get exception");
207 ok = false;
208 } catch (IOException e) {
209 Throwable wrapped = e.getCause();
210 if (isInstance(wrapped, "org.omg.CORBA.MARSHAL")) // see CR 4935098
211 wrapped = wrapped.getCause();
212 if (wrapped instanceof ClassNotFoundException) {
213 System.out.println("Success: got an IOException wrapping " +
214 "a ClassNotFoundException: " +
215 wrapped);
216 } else {
217 System.out.println("TEST FAILS: Got IOException but cause " +
218 "should be ClassNotFoundException: ");
219 if (wrapped == null)
220 System.out.println("(null)");
221 else
222 wrapped.printStackTrace(System.out);
223 ok = false;
224 }
225 } catch (Exception e) {
226 System.out.println("TEST FAILS: Got wrong exception: " +
227 "should be IOException with cause " +
228 "ClassNotFoundException:");
229 e.printStackTrace(System.out);
230 ok = false;
231 }
243 for (int i = 0; i < 2; i++) {
244 boolean setAttribute = (i == 0); // else invoke
245 String what = setAttribute ? "setAttribute" : "invoke";
246 System.out.println("Trying " + what +
247 " with class unknown to server");
248 try {
249 if (setAttribute) {
250 mbsc.setAttribute(on, new Attribute("ServerUnknown",
251 serverUnknown));
252 } else {
253 mbsc.invoke(on, "useServerUnknown",
254 new Object[] {serverUnknown},
255 new String[] {"java.lang.Object"});
256 }
257 System.out.println("TEST FAILS: " + what + " with " +
258 "class unknown to server should fail " +
259 "but did not");
260 ok = false;
261 } catch (IOException e) {
262 Throwable cause = e.getCause();
263 if (isInstance(cause, "org.omg.CORBA.MARSHAL")) // see CR 4935098
264 cause = cause.getCause();
265 if (cause instanceof ClassNotFoundException) {
266 System.out.println("Success: got an IOException " +
267 "wrapping a ClassNotFoundException");
268 } else {
269 System.out.println("TEST FAILS: Caught IOException (" + e +
270 ") but cause should be " +
271 "ClassNotFoundException: " + cause);
272 e.printStackTrace(System.out); // XXX
273 ok = false;
274 }
275 }
276 }
277
278 System.out.println("Doing queryNames to ensure connection alive");
279 names = mbsc.queryNames(null, null);
280 System.out.println("queryNames returned " + names);
281
282 System.out.println("Trying to get unserializable attribute");
283 try {
284 mbsc.getAttribute(on, "Unserializable");
|
1 /*
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
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 *
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.
22 */
166
167 System.out.println("Connecting for client-unknown test");
168
169 JMXConnector client = JMXConnectorFactory.connect(addr, clientMap);
170
171 // add a listener to verify no failed notif
172 CNListener cnListener = new CNListener();
173 client.addConnectionNotificationListener(cnListener, null, null);
174
175 MBeanServerConnection mbsc = client.getMBeanServerConnection();
176
177 System.out.println("Getting attribute with class unknown to client");
178 try {
179 Object result = mbsc.getAttribute(on, "ClientUnknown");
180 System.out.println("TEST FAILS: getAttribute for class " +
181 "unknown to client should fail, returned: " +
182 result);
183 ok = false;
184 } catch (IOException e) {
185 Throwable cause = e.getCause();
186 if (cause instanceof ClassNotFoundException) {
187 System.out.println("Success: got an IOException wrapping " +
188 "a ClassNotFoundException");
189 } else {
190 System.out.println("TEST FAILS: Caught IOException (" + e +
191 ") but cause should be " +
192 "ClassNotFoundException: " + cause);
193 ok = false;
194 }
195 }
196
197 System.out.println("Doing queryNames to ensure connection alive");
198 Set<ObjectName> names = mbsc.queryNames(null, null);
199 System.out.println("queryNames returned " + names);
200
201 System.out.println("Provoke exception of unknown class");
202 try {
203 mbsc.invoke(on, "throwClientUnknown", NO_OBJECTS, NO_STRINGS);
204 System.out.println("TEST FAILS: did not get exception");
205 ok = false;
206 } catch (IOException e) {
207 Throwable wrapped = e.getCause();
208 if (wrapped instanceof ClassNotFoundException) {
209 System.out.println("Success: got an IOException wrapping " +
210 "a ClassNotFoundException: " +
211 wrapped);
212 } else {
213 System.out.println("TEST FAILS: Got IOException but cause " +
214 "should be ClassNotFoundException: ");
215 if (wrapped == null)
216 System.out.println("(null)");
217 else
218 wrapped.printStackTrace(System.out);
219 ok = false;
220 }
221 } catch (Exception e) {
222 System.out.println("TEST FAILS: Got wrong exception: " +
223 "should be IOException with cause " +
224 "ClassNotFoundException:");
225 e.printStackTrace(System.out);
226 ok = false;
227 }
239 for (int i = 0; i < 2; i++) {
240 boolean setAttribute = (i == 0); // else invoke
241 String what = setAttribute ? "setAttribute" : "invoke";
242 System.out.println("Trying " + what +
243 " with class unknown to server");
244 try {
245 if (setAttribute) {
246 mbsc.setAttribute(on, new Attribute("ServerUnknown",
247 serverUnknown));
248 } else {
249 mbsc.invoke(on, "useServerUnknown",
250 new Object[] {serverUnknown},
251 new String[] {"java.lang.Object"});
252 }
253 System.out.println("TEST FAILS: " + what + " with " +
254 "class unknown to server should fail " +
255 "but did not");
256 ok = false;
257 } catch (IOException e) {
258 Throwable cause = e.getCause();
259 if (cause instanceof ClassNotFoundException) {
260 System.out.println("Success: got an IOException " +
261 "wrapping a ClassNotFoundException");
262 } else {
263 System.out.println("TEST FAILS: Caught IOException (" + e +
264 ") but cause should be " +
265 "ClassNotFoundException: " + cause);
266 e.printStackTrace(System.out); // XXX
267 ok = false;
268 }
269 }
270 }
271
272 System.out.println("Doing queryNames to ensure connection alive");
273 names = mbsc.queryNames(null, null);
274 System.out.println("queryNames returned " + names);
275
276 System.out.println("Trying to get unserializable attribute");
277 try {
278 mbsc.getAttribute(on, "Unserializable");
|