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:catalina.mbeans.MBeanUtils.java

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

    String mname = createManagedName(environment);
    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(environment);
    ObjectName oname = createObjectName(domain, environment);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:be.fgov.kszbcss.rhq.websphere.connector.SecureAdminClient.java

public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature)
        throws InstanceNotFoundException, MBeanException, ReflectionException, ConnectorException {
    Object result;//from   www. j a  v  a2s. com
    try {
        WSSubject.setRunAsSubject(subject);
        try {
            result = super.invoke(name, operationName, params, signature);
            if (result instanceof DocumentContentSource) {
                // FileTransferClientImpl (which is used by the input stream returned by
                // DocumentContentSource) uses the subject stored in the global AdminDataHolder.
                // This breaks thread isolation. As a workaround, we synchronize access and
                // set the cached subject explicitly.
                synchronized (AdminDataHolder.class) {
                    AdminDataHolder.setData(AdminDataHolder.WSSUBJECT, subject);
                    DocumentContentSource dcs = (DocumentContentSource) result;
                    try {
                        try {
                            InputStream in = dcs.getSource();
                            try {
                                return new DocumentContentSource(dcs.getDocument(), IOUtils.toByteArray(in));
                            } finally {
                                in.close();
                            }
                        } catch (IOException ex) {
                            throw new MBeanException(ex);
                        }
                    } finally {
                        AdminDataHolder.removeData(AdminDataHolder.WSSUBJECT);
                    }
                }
            } else {
                return result;
            }
        } finally {
            WSSubject.setRunAsSubject(null);
        }
    } catch (WSSecurityException ex) {
        throw new ConnectorException(ex);
    }
}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create, register, and return an MBean for this
 * <code>ContextResource</code> object.
 *
 * @param resource The ContextResource to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 *//*from w  w w.  j  av a2s . co  m*/
public static ModelMBean createMBean(ContextResource 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 AjpConnector//ww  w .j a va 2s  .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 createAjpConnector(String parent, String address, int port) throws Exception {

    Object retobj = null;

    try {

        // Create a new CoyoteConnector instance for AJP
        // 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 protocolHandlerClassName for AJP
        Class partypes3[] = new Class[1];
        partypes3[0] = str.getClass();
        Method meth3 = cls.getMethod("setProtocolHandlerClassName", partypes3);
        Object arglist3[] = new Object[1];
        arglist3[0] = new String("org.apache.jk.server.JkCoyoteHandler");
        meth3.invoke(retobj, arglist3);

    } catch (Exception e) {
        throw new MBeanException(e);
    }

    // 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);

    // 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>ContextResourceLink</code> object.
 *
 * @param resourceLink The ContextResourceLink to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 *//*from   w  ww  .j av  a 2 s .  c om*/
public static ModelMBean createMBean(ContextResourceLink resourceLink) throws Exception {

    String mname = createManagedName(resourceLink);
    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(resourceLink);
    ObjectName oname = createObjectName(domain, resourceLink);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

/**
 *
 * @param uid//w  ww  .  j a  v a  2s  .c  o m
 * @param title
 * @param content
 * @param appendix
 * @param count
 * @param type
 * @throws java.lang.Exception
 */
public void sendMail(final String uid, final String title, final String content, final String appendix,
        final String count, final String type) throws Exception {
    try {
        User user = userRepository.findByUid(Integer.parseInt(uid));
        if (user == null) {
            throw new RuntimeException("Not found user[" + uid + "]");
        }

        roleProvider.sendMail(user.getUid(),
                newMail(new String(title.getBytes("ISO-8859-1"), "UTF-8"),
                        new String(content.getBytes("ISO-8859-1"), "UTF-8"), appendix, Integer.valueOf(count),
                        Integer.valueOf(type)));
    } catch (Exception e) {
        throw new MBeanException(e);
    }
}

From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java

public Object getAttribute(String attribute)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (methods == null)
        init();/*  w w w.j  a  v  a 2  s.  co  m*/
    Method m = (Method) getAttMap.get(attribute);
    if (m == null)
        throw new AttributeNotFoundException(attribute);

    try {
        if (log.isDebugEnabled())
            log.debug(real.getClass().getName() + " getAttribute " + attribute);
        return m.invoke(real, NO_ARGS_PARAM);
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
        throw new MBeanException(ex);
    } catch (InvocationTargetException ex1) {
        ex1.printStackTrace();
        throw new MBeanException(ex1);
    }
}

From source file:catalina.mbeans.MBeanUtils.java

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

    String mname = createManagedName(context);
    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(context);
    ObjectName oname = createObjectName(domain, context);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

/**
 *
 * @param title//from ww  w .  jav  a 2  s  .  c  o m
 * @param content
 * @param appendix
 * @param count
 * @param type
 * @throws java.lang.Exception
 */
public void sendAllMail(final String title, final String content, final String appendix, final String count,
        final String type) throws Exception {
    try {
        String _title = new String(title.getBytes("ISO-8859-1"), "UTF-8");
        String _content = new String(content.getBytes("ISO-8859-1"), "UTF-8");

        List<Integer> rids = loadAllRids();
        for (int rid : rids) {
            roleProvider.sendMail(rid,
                    newMail(_title, _content, appendix, Integer.valueOf(count), Integer.valueOf(type)));
        }
    } catch (Exception e) {
        throw new MBeanException(e);
    }
}

From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java

public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    if (methods == null)
        init();/*w ww.  j a  va  2  s  .c o  m*/
    // XXX Send notification !!!
    Method m = (Method) setAttMap.get(attribute.getName());
    if (m == null)
        throw new AttributeNotFoundException(attribute.getName());

    try {
        log.info(real.getClass().getName() + "setAttribute " + attribute.getName());
        m.invoke(real, new Object[] { attribute.getValue() });
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
        throw new MBeanException(ex);
    } catch (InvocationTargetException ex1) {
        ex1.printStackTrace();
        throw new MBeanException(ex1);
    }
}