Search in sources :

Example 1 with ManagementHome

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

the class MEJBUtility method getMEJB.

public synchronized Management getMEJB() throws RemoteException {
    if (mMEJB == null) {
        try {
            final Context ic = new InitialContext();
            final String ejbName = System.getProperty(MEJB_NAME_PROP, MEJB_DEFAULT_NAME);
            final Object objref = ic.lookup(ejbName);
            final ManagementHome home = (ManagementHome) PortableRemoteObject.narrow(objref, ManagementHome.class);
            mMEJB = (Management) home.create();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return mMEJB;
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ManagementHome(javax.management.j2ee.ManagementHome) PortableRemoteObject(javax.rmi.PortableRemoteObject) InitialContext(javax.naming.InitialContext) UnknownHostException(java.net.UnknownHostException) RemoteException(java.rmi.RemoteException) ListenerNotFoundException(javax.management.ListenerNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException)

Example 2 with ManagementHome

use of javax.management.j2ee.ManagementHome 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 ManagementHome

use of javax.management.j2ee.ManagementHome 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 ManagementHome

use of javax.management.j2ee.ManagementHome 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 ManagementHome

use of javax.management.j2ee.ManagementHome 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

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