Example usage for javax.management MBeanException MBeanException

List of usage examples for javax.management MBeanException MBeanException

Introduction

In this page you can find the example usage for javax.management MBeanException MBeanException.

Prototype

public MBeanException(java.lang.Exception e) 

Source Link

Document

Creates an MBeanException that wraps the actual java.lang.Exception.

Usage

From source file:org.codice.ddf.configuration.migration.ConfigurationMigrationManagerTest.java

@Test
public void doImportSucceedsWithWrapperRestartAndFailsToReboot() throws Exception {
    System.setProperty(WRAPPER_KEY, "abc");

    doThrow(new MBeanException(null)).when(mockWrapperManager).restart();
    expectZipWithChecksum(true);/*from  w  w  w. j a v  a 2 s .co  m*/
    expectImportDelegationIsSuccessful();

    MigrationReport report = configurationMigrationManager.doImport(path);

    assertThat("Import was successful", report.wasSuccessful(), is(true));
    assertThat("Restart system property was not cleared", System.getProperty(RESTART_JVM), equalTo("true"));
    assertThat(ddfBin.resolve("restart.jvm").toFile(), Matchers.not(FileMatchers.anExistingFile()));
    reportHasInfoMessage(report.infos(),
            equalTo("Successfully imported from file [" + encryptedFileName + "]."));
    reportHasInfoMessage(report.infos(), equalTo("Please restart the system for changes to take effect."));
    verify(mockSystemService, Mockito.never()).halt();
    verify(mockWrapperManager).restart();
    verify(configurationMigrationManager).delegateToImportMigrationManager(any(MigrationReportImpl.class),
            any(MigrationZipFile.class), any(Set.class));
}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create, register, and return an MBean for this
 * <code>MBeanFactory</code> object.
 *
 * @param factory The MBeanFactory to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 *///from   www  . jav a  2 s  .  co m
public static ModelMBean createMBean(MBeanFactory factory) throws Exception {

    String mname = createManagedName(factory);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(factory);
    ObjectName oname = createObjectName(domain, factory);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create, register, and return an MBean for this
 * <code>NamingResources</code> object.
 *
 * @param resource The NamingResources to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 *//*from ww  w .  jav  a  2s.c  o  m*/
public static ModelMBean createMBean(NamingResources resource) throws Exception {

    String mname = createManagedName(resource);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(resource);
    ObjectName oname = createObjectName(domain, resource);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new HttpsConnector/*from  w  w w .  j a v  a2 s.c o  m*/
 *
 * @param parent MBean Name of the associated parent component
 * @param address The IP address on which to bind
 * @param port TCP port number to listen on
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createHttpsConnector(String parent, String address, int port) throws Exception {

    Object retobj = null;

    try {

        // Create a new CoyoteConnector instance
        // use reflection to avoid j-t-c compile-time circular dependencies
        Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
        Constructor ct = cls.getConstructor(null);
        retobj = ct.newInstance(null);
        Class partypes1[] = new Class[1];
        // Set address
        String str = new String();
        partypes1[0] = str.getClass();
        Method meth1 = cls.getMethod("setAddress", partypes1);
        Object arglist1[] = new Object[1];
        arglist1[0] = address;
        meth1.invoke(retobj, arglist1);
        // Set port number
        Class partypes2[] = new Class[1];
        partypes2[0] = Integer.TYPE;
        Method meth2 = cls.getMethod("setPort", partypes2);
        Object arglist2[] = new Object[1];
        arglist2[0] = new Integer(port);
        meth2.invoke(retobj, arglist2);
        // Set scheme
        Class partypes3[] = new Class[1];
        partypes3[0] = str.getClass();
        Method meth3 = cls.getMethod("setScheme", partypes3);
        Object arglist3[] = new Object[1];
        arglist3[0] = new String("https");
        meth3.invoke(retobj, arglist3);
        // Set secure
        Class partypes4[] = new Class[1];
        partypes4[0] = Boolean.TYPE;
        Method meth4 = cls.getMethod("setSecure", partypes4);
        Object arglist4[] = new Object[1];
        arglist4[0] = new Boolean(true);
        meth4.invoke(retobj, arglist4);
        // Set factory 
        Class serverSocketFactoryCls = Class.forName("org.apache.catalina.net.ServerSocketFactory");
        Class coyoteServerSocketFactoryCls = Class
                .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
        Constructor factoryConst = coyoteServerSocketFactoryCls.getConstructor(null);
        Object factoryObj = factoryConst.newInstance(null);
        Class partypes5[] = new Class[1];
        partypes5[0] = serverSocketFactoryCls;
        Method meth5 = cls.getMethod("setFactory", partypes5);
        Object arglist5[] = new Object[1];
        arglist5[0] = factoryObj;
        meth5.invoke(retobj, arglist5);
    } catch (Exception e) {
        throw new MBeanException(e);
    }

    try {
        // Add the new instance to its parent component
        ObjectName pname = new ObjectName(parent);
        Server server = ServerFactory.getServer();
        Service service = server.findService(pname.getKeyProperty("name"));
        service.addConnector((Connector) retobj);
    } catch (Exception e) {
        // FIXME
        // disply error message 
        // the user needs to use keytool to configure SSL first
        // addConnector will fail otherwise
        return null;
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("CoyoteConnector");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), (Connector) retobj);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create, register, and return an MBean for this
 * <code>Realm</code> object.
 *
 * @param realm The Realm to be managed/*from   ww w. ja  v  a 2 s .  c o  m*/
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static ModelMBean createMBean(Realm realm) throws Exception {

    String mname = createManagedName(realm);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(realm);
    ObjectName oname = createObjectName(domain, realm);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create, register, and return an MBean for this
 * <code>Role</code> object.
 *
 * @param role The Role to be managed/*from   w  w  w.j  a  v  a  2s . com*/
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static ModelMBean createMBean(Role role) throws Exception {

    String mname = createManagedName(role);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(role);
    ObjectName oname = createObjectName(domain, role);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create, register, and return an MBean for this
 * <code>Server</code> object.
 *
 * @param server The Server to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 *///from   w w w.  j a v  a 2 s . co m
public static ModelMBean createMBean(Server server) throws Exception {

    String mname = createManagedName(server);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(server);
    ObjectName oname = createObjectName(domain, server);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create, register, and return an MBean for this
 * <code>Service</code> object.
 *
 * @param service The Service to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 *///  w ww  . j a v  a2 s .co  m
public static ModelMBean createMBean(Service service) throws Exception {

    String mname = createManagedName(service);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(service);
    ObjectName oname = createObjectName(domain, service);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create, register, and return an MBean for this
 * <code>User</code> object.
 *
 * @param user The User to be managed//from   w w w .  ja  v a2  s.  c  o  m
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static ModelMBean createMBean(User user) throws Exception {

    String mname = createManagedName(user);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(user);
    ObjectName oname = createObjectName(domain, user);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create, register, and return an MBean for this
 * <code>UserDatabase</code> object.
 *
 * @param userDatabase The UserDatabase to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 *///from w ww. j ava2 s.c  o  m
public static ModelMBean createMBean(UserDatabase userDatabase) throws Exception {

    String mname = createManagedName(userDatabase);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(userDatabase);
    ObjectName oname = createObjectName(domain, userDatabase);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}