Print this page


Split Close
Expand all
Collapse all
          --- old/test/java/lang/management/ManagementFactory/MBeanServerMXBeanUnsupportedTest.java
          +++ new/test/java/lang/management/ManagementFactory/MBeanServerMXBeanUnsupportedTest.java
   1    1  /*
   2      - * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
        2 + * Copyright (c) 2006, 2013 Oracle and/or its affiliates. All rights reserved.
   3    3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4    4   *
   5    5   * This code is free software; you can redistribute it and/or modify it
   6    6   * under the terms of the GNU General Public License version 2 only, as
   7    7   * published by the Free Software Foundation.
   8    8   *
   9    9   * This code is distributed in the hope that it will be useful, but WITHOUT
  10   10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11   11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12   12   * version 2 for more details (a copy is included in the LICENSE file that
↓ open down ↓ 16 lines elided ↑ open up ↑
  29   29   * @author Luis-Miguel Alventosa
  30   30   * @run clean MBeanServerMXBeanUnsupportedTest
  31   31   * @run build MBeanServerMXBeanUnsupportedTest
  32   32   * @run main/othervm MBeanServerMXBeanUnsupportedTest
  33   33   */
  34   34  
  35   35  import java.lang.management.ManagementFactory;
  36   36  import java.lang.reflect.InvocationHandler;
  37   37  import java.lang.reflect.Method;
  38   38  import java.lang.reflect.Proxy;
       39 +import java.util.Arrays;
       40 +import java.util.HashSet;
  39   41  import javax.management.MBeanServer;
  40   42  import javax.management.MBeanServerBuilder;
  41   43  import javax.management.MBeanServerDelegate;
  42   44  import javax.management.ObjectName;
  43   45  import javax.management.StandardMBean;
  44   46  import javax.management.remote.MBeanServerForwarder;
  45   47  
  46   48  public class MBeanServerMXBeanUnsupportedTest {
  47   49  
  48   50      /**
↓ open down ↓ 25 lines elided ↑ open up ↑
  74   76          }
  75   77      }
  76   78  
  77   79      /**
  78   80       * An MBeanServerForwarderInvocationHandler that throws a
  79   81       * RuntimeException if we try to register a non StandardMBean.
  80   82       */
  81   83      public static class MBeanServerForwarderInvocationHandler
  82   84              implements InvocationHandler {
  83   85  
       86 +        public static final HashSet<String> excludeList = new HashSet<String>(
       87 +            Arrays.asList("com.sun.management:type=DiagnosticCommand"));
       88 +
  84   89          public static MBeanServerForwarder newProxyInstance() {
  85   90  
  86   91              final InvocationHandler handler =
  87   92                      new MBeanServerForwarderInvocationHandler();
  88   93  
  89   94              final Class[] interfaces =
  90   95                      new Class[] {MBeanServerForwarder.class};
  91   96  
  92   97              Object proxy = Proxy.newProxyInstance(
  93   98                      MBeanServerForwarder.class.getClassLoader(),
↓ open down ↓ 25 lines elided ↑ open up ↑
 119  124              if (methodName.equals("registerMBean")) {
 120  125                  Object mbean = args[0];
 121  126                  ObjectName name = (ObjectName) args[1];
 122  127                  String domain = name.getDomain();
 123  128                  System.out.println("registerMBean: class=" +
 124  129                          mbean.getClass().getName() + "\tname=" + name);
 125  130                  Object result = method.invoke(mbs, args);
 126  131                  if (domain.equals("java.lang") ||
 127  132                      domain.equals("java.util.logging") ||
 128  133                      domain.equals("com.sun.management")) {
 129      -                    String mxbean = (String)
 130      -                        mbs.getMBeanInfo(name).getDescriptor().getFieldValue("mxbean");
 131      -                    if (mxbean == null || !mxbean.equals("true")) {
 132      -                        throw new RuntimeException(
 133      -                                "Platform MBeans must be MXBeans!");
 134      -                    }
 135      -                    if (!(mbean instanceof StandardMBean)) {
 136      -                        throw new RuntimeException(
      134 +                    if(!excludeList.contains(name.getCanonicalName())) {
      135 +                        String mxbean = (String)
      136 +                            mbs.getMBeanInfo(name).getDescriptor().getFieldValue("mxbean");
      137 +                        if (mxbean == null || !mxbean.equals("true")) {
      138 +                            throw new RuntimeException(
      139 +                                "Platform MBeans must be MXBeans!");
      140 +                        }
      141 +                        if (!(mbean instanceof StandardMBean)) {
      142 +                            throw new RuntimeException(
 137  143                                  "MXBeans must be wrapped in StandardMBean!");
 138      -                    }
      144 +                        }
      145 +                    }
 139  146                  }
 140  147                  return result;
 141  148              }
 142  149  
 143  150              return method.invoke(mbs, args);
 144  151          }
 145  152  
 146  153          private MBeanServer mbs;
 147  154      }
 148  155  
↓ open down ↓ 17 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX