Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find all ejbs deployed for an ear on Websphere?

 
Giriraj Bhojak
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to find out how many EJBs have been deployed as a part of ear through a program?
I have to list all the ejbs that have been deployed for an ear application in Websphere.


Regards,
Giriraj.
[ December 29, 2008: Message edited by: Giriraj Bhojak ]
 
S Setty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find using an MBean, here is the sample code..

MBeanFactory mf = AdminServiceFactory.getMBeanFactory();
MBeanServer server = mf.getMBeanServer();

ObjectName obj = new ObjectName("WebSphere:type=StatelessSessionBean,*");
Set mbeans = server.queryMBeans(obj, null);

if(mbeans!=null ) {
Iterator itr = mbeans.iterator();
while(itr.hasNext()) {
ObjectInstance objInstance = (ObjectInstance) itr.next();

if(objInstance!=null && objInstance.getObjectName()!=null) {
String beanName = objInstance.getObjectName().getKeyProperty("name");

System.out.println(beanName);
}
}
}
 
Giriraj Bhojak
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Setty for your reply...
Can this code snippet work if I use it as a part of the servlet?

Regards,
Giriraj.
 
S Setty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it works
 
Giriraj Bhojak
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Setty.
I have tried it the way you have mentioned.
And it works.
After trying this example I found out that I need to be aware of MBeans.
So I have read about MBeans.
Now that I have the names of all the ejbs deployed in websphere, how do I do a JNDI lookup to invoke ejb method.
Is there any JMX api that would help me to actually retrieve an ejb reference?

Regards,
Giriraj.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic