Portlet and PortletApplication MBeans
The MBeans of type portlet and portletapplication provide information about a given portlet application and its portlets. Through the MBean of type portletapplication, you can retrieve a list of names of all portlets that belong to a portlet application. By querying the MBean of type portlet with a given portlet name, you can retrieve portlet specific information from the MBean of type portlet.
Each MBean that corresponds to a portlet or portlet application is uniquely identifiable by its
name. Portlet applications are not required to have a name set within the
portlet.xml. The MBean name for MBeans of the portletapplication type is the
enterprise archive (EAR) file name followed by "#" and the web module name concatenated with the
string "_portlet". For example, portletapplication type MBeans have the following
format:
<EarFileName>#<WarFileName>_portletThe name chosen for the MBean of type portlet is the name of the MBean of type portletapplication that the portlet belongs to, concatenated with the portlet name:
<EarFileName>#<WarFileName>_portlet.<portletname>
The following is an example of the resulting PortletApplication MBean name and portlet names:
EarName SampleEar
WebModule SampleWar.war
PortletApplication MBean name: SampleEar#SampleWar_portlet
Portlet: SampleEar#SampleWar_portlet.BookmarkPortlet
The
MBean names have been changed compared to version 6.1, because the old naming patterns are not
unique and can lead to problems under certain circumstances. If you rely on the old naming pattern,
you can set the portlet container custom property, useShortMBeanNames
, to true to
activate the previous known MBean names. Because this is a performance impact, you might not want to
activate the old naming pattern if it is not necessary.A full stop separates the preceding web module name from the portlet name. Review the Portlet and PortletApplication MBean type API documentation for additional information. The generated API documentation is available in the documentation table of contents from the path,
.The following code is an example of how to invoke the MBean of type portletapplication for an
application with the name, SampleWar.
String myPortletApplicationName = "SampleEar#SampleWar_portlet";
This name is composed by the Ear file name followed by "#" and
the web module name concatenated with the substring "_portlet"
com.ibm.websphere.management.AdminService adminService =
com.ibm.websphere.management.AdminServiceFactory.getAdminService();
javax.management.ObjectName on =
new ObjectName("WebSphere:type=PortletApplication,name=" + myPortletApplicationName + ",*");
Iterator onIter = adminService.queryNames(on, null).iterator();
while(onIter.hasNext())
{
on = (ObjectName)onIter.next();
}
String ctxRoot = (java.lang.String)adminService.getAttribute(on, "webApplicationContextRoot");
In
the previous example, the MBeanServer is first queried for an MBean of type portletapplication. If
this query is successful, the webApplicationContextRoot attribute is retrieved on that MBean or the
first MBean that is found. The result is stored in the ctxRoot variable. This variable now contains
the context root of the web application that contains the portlet application that was searched. The
variable is similar to "/bookmark".The next code example demonstrates how to invoke the MBean of type portlet for a portlet with the
name,
BookmarkPortlet.
String myPortletName = "SampleEar#SampleWar_portlet.BookmarkPortlet";
This name is composed by the name of the MBean of type portletapplication and
the portlet name, separated by a full stop because the same portlet name may
be used within different web modules, but must be unique within the system.
com.ibm.websphere.management.AdminService adminService =
com.ibm.websphere.management.AdminServiceFactory.getAdminService();
javax.management.ObjectName on =
new ObjectName("WebSphere:type=Portlet,name=" + myPortletName + ",*");
Iterator iter = adminService.queryNames(on, null).iterator();
while(iter.hasNext())
{
on = (ObjectName)iter.next;
}
java.util.Locale locale = (java.util.Locale) adminService.getAttribute(on, "defaultLocale");
The
locale returned by the method getAttribute method for the MBean is the default locale defined for
this portlet.Full names for Portlet and PortletApplication MBeans
MBeans are also registered by the full identifiable
name:
<ApplicationName>#<WARfilename.war>_portlet.<portlet_name> for the Portlet MBean
<ApplicationName>#<WARfilename.war>_portlet for the PortletApplication MBean
where
<..> is replaced by the corresponding application data. For example,
SampleApplication#SamplePortlet.war_portlet.SamplePortlet
. You can enable the short
MBean names by setting the useShortMBeanNames
portlet container custom property to
true.