title: Programmatically stopping MDB in JBoss 5.1.0GA
body: <p>I am trying to stop a MDB in JBoss 5.1.0.</p>
  
  <p>My code is as follows : </p>
  
  <pre><code>public static void stopAllMDB()
          throws InterruptedException, MalformedObjectNameException, NullPointerException {
  
          String currentVersion = "1.0";
  
          for (String name : Util.MDB_NAMES) {
              String mbean = "jboss.j2ee:ear=myEar" + currentVersion + ".ear,jar=myJar.jar,name=myMDB,service=EJB3";
              ObjectName objName = new ObjectName(mbean);
  
              System.out.println("Stop MDB " + name);
              try {
                  MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
                  MessagingDelegateWrapperMBean invoker = (MessagingDelegateWrapperMBean)MBeanProxy.get(MessagingDelegateWrapperMBean.class,
                          objName, mbeanServer);
                  invoker.stopDelivery();
                  }
              } catch (Exception e) {
              }
   }
  </code></pre>
  
  <p>But if fails at </p>
  
  <pre><code>MessagingDelegateWrapperMBean invoker = (MessagingDelegateWrapperMBean)MBeanProxy.get(MessagingDelegateWrapperMBean.class,objName, mbeanServer)
  </code></pre>
  
  <p>with </p>
  
  <blockquote>
    <p>Illegal argument exception.</p>
  </blockquote>