Search in sources :

Example 1 with Management

use of javax.management.j2ee.Management in project Payara by payara.

the class MEJBTest method testMBean.

private void testMBean(final ObjectName objectName) throws Exception {
    println("");
    println("" + objectName);
    final Management mejb = mMEJB;
    final MBeanInfo info = mejb.getMBeanInfo(objectName);
    final String[] attrNames = getAttributeNames(info.getAttributes());
    println("attributes: " + toString(newListFromArray(attrNames), ", "));
    final AttributeList list = mejb.getAttributes(objectName, attrNames);
    for (final String attrName : attrNames) {
        try {
            final Object value = mejb.getAttribute(objectName, attrName);
        } catch (Exception e) {
            println("Attribute failed: " + attrName);
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) AttributeList(javax.management.AttributeList) PortableRemoteObject(javax.rmi.PortableRemoteObject) Management(javax.management.j2ee.Management)

Example 2 with Management

use of javax.management.j2ee.Management in project Payara by payara.

the class MEJBTest method main.

public static void main(String[] args) {
    try {
        final String mejbName = "java:global/mejb/MEJBBean";
        final String username = "admin";
        final String password = "";
        final String realm = "admin-realm";
        System.out.println("Authenticating with \"" + username + "\", \"" + password + "\"");
        final ProgrammaticLogin pm = new ProgrammaticLogin();
        pm.login(username, password, realm, true);
        println("Looking up: " + mejbName);
        final InitialContext initial = new InitialContext();
        final Object objref = initial.lookup(mejbName);
        final ManagementHome home = (ManagementHome) PortableRemoteObject.narrow(objref, ManagementHome.class);
        try {
            final ManagementHome home2 = (ManagementHome) objref;
        } catch (final Exception e) {
            println("WARNING: (ManagementHome)PortableRemoteObject.narrow(objref, ManagementHome.class) works, but (ManagementHome)objref does not!");
        }
        // println("ManagementHome: " + home + " for " + mejbName);
        final Management mejb = (Management) home.create();
        println("Got the MEJB");
        new MEJBTest(mejb).test();
        println("Calling mejb.remove()");
        mejb.remove();
    } catch (Exception ex) {
        System.err.println("Caught an unexpected exception!");
        ex.printStackTrace();
    }
    println("Exiting main() forcibly");
    System.exit(-1);
}
Also used : ManagementHome(javax.management.j2ee.ManagementHome) PortableRemoteObject(javax.rmi.PortableRemoteObject) Management(javax.management.j2ee.Management) ProgrammaticLogin(com.sun.enterprise.security.ee.auth.login.ProgrammaticLogin) InitialContext(javax.naming.InitialContext)

Example 3 with Management

use of javax.management.j2ee.Management in project Payara by payara.

the class J2EEManagedObjectMdl method getMEJB.

protected final Management getMEJB() {
    Management mejb = null;
    try {
        Context ic = new InitialContext();
        String ejbName = System.getProperty("mejb.name", "ejb/mgmt/MEJB");
        java.lang.Object objref = ic.lookup(ejbName);
        ManagementHome home = (ManagementHome) PortableRemoteObject.narrow(objref, ManagementHome.class);
        mejb = home.create();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return mejb;
}
Also used : ManagementHome(javax.management.j2ee.ManagementHome) Management(javax.management.j2ee.Management)

Example 4 with Management

use of javax.management.j2ee.Management in project Payara by payara.

the class J2EEManagedObjectImplBase method getMEJB.

public final Management getMEJB() {
    Management mejb = null;
    try {
        final Context ic = new InitialContext();
        final String ejbName = System.getProperty("mejb.name", "ejb/mgmt/MEJB");
        final Object objref = ic.lookup(ejbName);
        final ManagementHome home = (ManagementHome) PortableRemoteObject.narrow(objref, ManagementHome.class);
        mejb = home.create();
    } catch (Exception ex) {
        throw new RuntimeException("Can't find MEJB", ex);
    }
    return mejb;
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ManagementHome(javax.management.j2ee.ManagementHome) J2EEManagedObject(org.glassfish.admin.amx.j2ee.J2EEManagedObject) PortableRemoteObject(javax.rmi.PortableRemoteObject) Management(javax.management.j2ee.Management) String(java.lang.String) InitialContext(javax.naming.InitialContext)

Example 5 with Management

use of javax.management.j2ee.Management in project wildfly by wildfly.

the class Jsr77TestCase method testJSR77Availabilty.

/**
 * Test for simple MBean functionality
 *
 * Catches NamingException if a naming exception is encountered in lookup() method.
 * Catches CreateException Indicates a failure to create the EJB object in create() method.
 * Catches RemoteException A communication exception occurred during the execution of a remote method call CreateException in create(), getDefaultDomain() or getMBeanCount() method.
 */
@Test
public void testJSR77Availabilty() {
    try {
        Context ic = new InitialContext();
        Object obj = ic.lookup("ejb/mgmt/MEJB");
        ManagementHome mejbHome = (ManagementHome) obj;
        final Management management = mejbHome.create();
        Assert.assertNotNull(management.getDefaultDomain());
        Assert.assertTrue(management.getMBeanCount() > 0);
    } catch (NamingException | CreateException | RemoteException ne) {
        Assert.fail(ne.getMessage());
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ManagementHome(javax.management.j2ee.ManagementHome) NamingException(javax.naming.NamingException) Management(javax.management.j2ee.Management) RemoteException(java.rmi.RemoteException) CreateException(javax.ejb.CreateException) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

Management (javax.management.j2ee.Management)6 ManagementHome (javax.management.j2ee.ManagementHome)4 InitialContext (javax.naming.InitialContext)3 PortableRemoteObject (javax.rmi.PortableRemoteObject)3 Context (javax.naming.Context)2 ProgrammaticLogin (com.sun.enterprise.security.ee.auth.login.ProgrammaticLogin)1 String (java.lang.String)1 RemoteException (java.rmi.RemoteException)1 CreateException (javax.ejb.CreateException)1 AttributeList (javax.management.AttributeList)1 MBeanInfo (javax.management.MBeanInfo)1 ObjectName (javax.management.ObjectName)1 NamingException (javax.naming.NamingException)1 J2EEManagedObject (org.glassfish.admin.amx.j2ee.J2EEManagedObject)1 Test (org.junit.Test)1