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);
}
}
}
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);
}
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;
}
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;
}
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());
}
}
Aggregations