-
1. Re: How to bind an MBean to JNDI, then access from within ap
monocongo Jun 10, 2004 3:03 PM (in response to monocongo)This seems to work OK, I can bind the bean to a JNDI name, then access the bean from a servlet which looks up the MBean using the JNDI name.
-James -
2. Re: How to bind an MBean to JNDI, then access from within ap
maroni Jun 14, 2004 3:32 AM (in response to monocongo)Hi James,
Can you please tell me how you bound your MBean to JNDI and how you accessed it in your client application then?
Can you please show me some code? I was trying to do the same, but it does not work.
Thanks a lot,
Marion -
3. Re: How to bind an MBean to JNDI, then access from within ap
monocongo Jun 14, 2004 2:34 PM (in response to monocongo)In my MBean class, which extends ServiceMBeanSupport, I do the following in the startService() method:
protected void startService () { // create a HashTable of environment properties for the InitialContext Hashtable environment = new Hashtable(); environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); environment.put(Context.PROVIDER_URL, "localhost:1099"); environment.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); try { // bind to JNDI Context context = new InitialContext(environment); Name fullName = context.getNameParser("").parse(m_jndiName); NonSerializableFactory.rebind(fullName, this, true); } catch (NamingException e) { System.out.println("Unable to bind UserManager MBean"); } }
I have a variable m_jndiName which I set before this method is called (right now it is hard-coded, but later I will hopefully be able to pull it from a configuration file of some sort.
In my EJB and servlet code I just do a lookup and cast of the object at that name:// lookup and cast the user manager MBean UserManager userManager; try { // get the InitialContext and lookup the home interface Context context = new InitialContext(environment); userManager = (UserManager) context.lookup("mbean/UserManager"); } catch (NameNotFoundException e) { // throw an UnavailableException so this servlet can never be called throw new UnavailableException("Lookup of UserManager MBean failed: " + e); } catch (NamingException e) { // log the error //m_logger.error("Lookup of the IOIManagerHome interface failed", e); // throw an UnavailableException so this servlet can never be called throw new UnavailableException("Lookup of UserManager MBean failed: " + e); }
I hope this is helpful for you.
-James -
4. Re: How to bind an MBean to JNDI, then access from within ap
maroni Jun 15, 2004 9:38 AM (in response to monocongo)Hi James,
That´s exactly what I did, and I can see my service bound to JNDI in the JMX console, my client can fetch the service from JNDI, but then...
The lookup is successful, no exception is thrown, but how can you invoke now methods on your mbean?? Because in my code, userManager is null. When I use the object, I get a NullPointerException.
Can you please tell me?
Thanks a lot,
Marion -
5. Re: How to bind an MBean to JNDI, then access from within ap
cbuckley Jun 30, 2004 6:27 PM (in response to monocongo)Most people use an adaptor to access their MBean. Just like the jmx-console is an html adaptor, jboss offers other adaptors as well, including a soap adaptor. you would use a soap call to get a reference to the jmx server then you would call "invoke(new Object[]{new ObjectName("your.domain:service=YourService"), new String("yourMethod"), new Object[]{"paramValue"}, new String[]{String.class.getName()}" the "String.class.getName()" part is the class name.
-
6. Re: How to bind an MBean to JNDI, then access from within ap
umeshs79 May 20, 2005 7:07 AM (in response to monocongo)Hi All,
I also need to do the same is this the right approach or you had find the better approach.
Please reply.
Thanks
Umesh