Use the RMIConnector to access the MBeanServer remotely. This
is used commonly by the unit test code to check on the existence
of MBeans and invoke methods on them. For example, in
org.jboss.test.web.test.TestWebIntegration there is there is a
lookup of the "J2EE:service=J2eeDeployer" to find the WarDeployerName
so that a check can be made for the existence of this MBean service.
There is also a flush of the authentication cache made using the
"Security:name=JaasSecurityManager" MBean.

MBeans do not need to be bound into JNDI to be used and that is why
you don't see this being done automatically.

import org.jboss.jmx.interfaces.RMIConnector;

...
      try
      {
         String serverName = InetAddress.getLocalHost().getHostName();
         String connectorName = "jmx:" +serverName+ ":rmi";
         RMIConnector server = (RMIConnector) new
InitialContext().lookup(connectorName);
         ObjectName deployerName = new
ObjectName("J2EE:service=J2eeDeployer");
         // Ask the deployer for the getWarDeployerName
         Object[] params =  {};
         String[] signature =  {};
         String warDeployerName = (String) server.invoke(deployerName,
         "getWarDeployerName", params, signature);
         // See if the warDeployerName exists
         deployerName = new ObjectName(warDeployerName);
         webServerAvailable = server.isRegistered(deployerName);
         if( webServerAvailable == true )
         {
            System.out.println("Found warDeployer named: "+warDeployerName);
            try
            {
               Deploy.deploy("jbosstest-web.ear");
            }
            catch(Exception e)
            {
               e.printStackTrace();
               fail("Failed to deploy jbosstest-web.ear");
            }
            // Flush the security domain cache to avoid conflicts with other
testcases
            ObjectName jaasMgr = new
ObjectName("Security:name=JaasSecurityManager");
            params = new Object[] {"other"};
            signature = new String[] {"java.lang.String"};
            server.invoke(jaasMgr, "flushAuthenticationCache", params,
signature);
         }
         else
         {
            System.out.println("No war deployer found, skipping tests");
         }
      }
      catch(Exception x)
      {
         webServerAvailable = false;
         x.printStackTrace();
         if (x instanceof RuntimeMBeanException)
         {

((RuntimeMBeanException)x).getTargetException().printStackTrace();
         }
         System.out.println("No war deployer found, skipping tests");
      }

----- Original Message -----
From: "Guy Rouillier" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, September 14, 2001 12:01 PM
Subject: [JBoss-user] MBean from external client?


> I am implementing my first MBean based on the sample in the documentation.
> I finally figured out (by reading the mail archives) that MBeans are not
> automatically bound into the JNDI name space, so I copied the sample code
> into my MBean and used this to bind my MBean into JNDI:
>
>       NonSerializableFactory.rebind(parentCtx, atom, this);
>
> Now, I am able to invoke my test method in the MBean successfully using
> JNDIView, and also from within an EJB using the following:
>
>    Flipper obj = (Flipper) new InitialContext().lookup("Flipper");
>    System.out.println("Flipped value of 5 is: " + obj.flip(5));
>
> The last thing I'm trying to do is to access this MBean from a general
Java
> application outside of JBoss.  But when I do the lookup above from such a
> client, obj is null.  Is there a way for external clients to gain access
to
> an MBean, or do I need to use an EJB as a proxy?
>
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
>


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to