Pluggable Administration Console

Older versions of Apache Geronimo came with a monolithic Administration Console. However, the server was extendable through plugins. This introduced a problem: How to administer the new plugins that were added to the server? To resolve this problem, the Apache Geronimo developers rewrote the Administration Console to be extensible through console plugins called Administration Console Extensions. In this section, we will look into how to create an Administration Console portlet for the World Clock plugin that we developed in the previous section.

Architecture

The pluggable Administration Console functionality is based on the support provided by the Apache Pluto portlet container for dynamically adding and removing portlets and pages without requiring a restart. Apache Geronimo exposes this functionality through two GBeans, namely, the Administration Console Extension (ACE) GBean (org.apache.geronimo.pluto.AdminConsoleExtensionGBean) and the Portal Container Services GBean (org.apache.geronimo.pluto.PortalContainerServicesGBean). The PortalContainerServicesGBean exposes the features of the Pluto container in order to add and remove portlets and pages at runtime. The ACE GBean invokes these APIs to add and remove the portlets or pages. The ACE GBean should be specified in the Geronimo-specific deployment plan of your web application or plugin, that is, geronimo-web.xml. The architecture is shown in the following figure:

Developing an Administration Console extension

We will now go through the steps to develop an Administration Console Extension for the World Clock plugin that we created in the previous section.

  1. We will use Maven WAR archetype to create a web application project. To create the project, run the following command from the command-line console:

    mvn archetype:create -DgroupId=com.packt.plugins -DartifactId=ClockWebApp -DarchetypeArtifactId=maven-archetype-webapp
    

    This will result in the Maven web project being created, named ClockWebApp.

  2. A default pom.xml will be created. This will need to be edited to add dependencies to the two modules, as shown in the following code snippet:

    <dependency>
    <groupId>org.apache.geronimo.framework</groupId>
    <artifactId>geronimo-kernel</artifactId>
    <version>2.1.4</version>
    </dependency>
    <dependency>
    <groupId>com.packt.plugins</groupId>
    <artifactId>WorldClockModule</artifactId>
    <version>1.0</version>
    </dependency>
    

    We add these dependencies because the portlet that we are going to write will use the classes mentioned in the above two modules.

  3. In the src/main/java directory, add the class ClockPortlet shown below, and create the corresponding package directory structure.

    package com.packt.plugins;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Date;
    import java.util.TimeZone;
    import javax.portlet.GenericPortlet;
    import javax.portlet.PortletException;
    import javax.portlet.RenderRequest;
    import javax.portlet.RenderResponse;
    import org.apache.geronimo.kernel.GBeanNotFoundException;
    import org.apache.geronimo.kernel.InternalKernelException;
    import org.apache.geronimo.kernel.Kernel;
    import org.apache.geronimo.kernel.KernelRegistry;
    /**
    *
    * This portlet displays time from the WorldClock GBean
    */
    public class ClockPortlet extends GenericPortlet {
    // called when user clicks on this portlets link
    public void doView(RenderRequest request, RenderResponse response)
    throws PortletException, IOException {
    // Set the response to read HTML
    response.setContentType("text/html;charset=UTF-8");
    // Get the writer to the response
    PrintWriter out = response.getWriter();
    Kernel kernel = KernelRegistry.getSingleKernel();
    try {
    Clock cl = (Clock)kernel.getGBean("ClockGBean");
    String[] ids = TimeZone.getAvailableIDs();
    for(int i=0;i<ids.length;i++){
    cl.setTimeZone(ids[i]);
    out.println(cl.getTime());
    out.println("<br>");
    }
    } catch (GBeanNotFoundException e) {
    e.printStackTrace(System.out);
    } catch (InternalKernelException e) {
    e.printStackTrace(System.out);
    } catch (IllegalStateException e) {
    e.printStackTrace(System.out);
    }
    }
    }
    

    This class gets the kernel from the KernelRegistry and then gets the ClockGBean. It then proceeds to invoke the setTimeZone and getTime methods for all available time zones and prints them to the response.

  4. In the src/main/webapp/WEB-INF directory, we create the web.xml, geronimo-web.xml, and portlet.xml files, as shown below:

    <web-app>
    <servlet>
    <servlet-name>WorldClockPortlet</servlet-name>
    <servlet-class>org.apache.pluto.core.PortletServlet </servlet-class>
    <init-param>
    <param-name>portlet-name</param-name>
    <param-value>WorldClockPortlet</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>WorldClockPortlet</servlet-name>
    <url-pattern>/PlutoInvoker/WorldClockPortlet</url-pattern>
    </servlet-mapping>
    </web-app>
    
  5. In the web.xml file shown above, we configure org.apache.pluto.core.PortletServlet at the URL /PlutoInvoker/WorldClockPortlet with the portlet-name parameter set to the name of the portlet that we created, namely, WorldClockPortlet. This should be the same as the portlet-name that we specify in the portlet.xml file.

    The deployment plan geronimo-web.xml is shown below:

    <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.2">
    <environment>
    <moduleId>
    <groupId>com.packt.plugins</groupId>
    <artifactId>WorldClockView</artifactId>
    <version>1.0</version>
    <type>war</type>
    </moduleId>
    <dependencies>
    <dependency>
    <groupId>org.apache.geronimo.plugins</groupId>
    <artifactId>pluto-support</artifactId>
    <type>car</type>
    </dependency>
    <dependency>
    <groupId>com.packt.plugins</groupId>
    <artifactId>WorldClock</artifactId>
    <type>car</type>
    </dependency>
    </dependencies>
    </environment>
    <!-- This is where the files are accessed from. (aka - portletContext) -->
    <context-root>/WorldClockPortlet</context-root>
    <!-- Start off a ACEGBean, this is the lifecycle for the portlet -->
    <gbean name="PlutoTest" class="org.apache.geronimo.pluto. AdminConsoleExtensionGBean">
    <attribute name="pageTitle">World Clock</attribute>
    <attribute name="portletContext">/WorldClockPortlet </attribute>
    <attribute name="portletList">[WorldClockPortlet] </attribute>
    <reference name="PortalContainerServices">
    <name>PlutoPortalServices</name>
    </reference>
    </gbean>
    </web-app>
    

    In the geronimo-web.xml file, we add dependencies to the pluto-support plugin and the World Clock plugin, as both of these will be used by our portlet. The Pluto-support plugin will provide the Pluto functionality, as well as both the ACE GBean and PortalContainerServicesGBean. We also specify an instance of the ACE GBean to start with this web module so that it can add the portlets to the Administration Console. We specify three attributes, namely, pageTitle, portletContext, and portletList, which specify the page title, portlet context, and the portlets that this GBean is going to add to the Administration Console, respectively. We also add a reference to the PortalContainerServicesGBean.

  6. Finally, we create a portlet.xml file, as shown below, which specifies the portlet mode, title, and name.

    <portlet-app
    xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
    version="1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/ portlet-app_1_0.xsd
    http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
    <portlet>
    <description>Clock Plugin portlet</description>
    <portlet-name>WorldClockPortlet</portlet-name>
    <display-name>World Clock Portlet</display-name>
    <portlet-class>com.packt.plugins.ClockPortlet </portlet-class>
    <supports> <!-- Defines which views are available [view,edit,help] -->
    <mime-type>text/html</mime-type>
    <portlet-mode>VIEW</portlet-mode>
    </supports>
    <portlet-info>
    <title>World Clock Portlet</title>
    </portlet-info>
    </portlet>
    </portlet-app>
    

    Ensure that the portlet-name matches the one in web.xml.

  7. Once you have created these files, build the web application by invoking the following command from the ClockWebApp directory:

    mvn clean install
    
  8. Deploy the WAR file created to the Apache Geronimo server where you had previously deployed the World Clock plugin.

Once you log in to the Administration Console, you will notice a World Clock link at the bottom of the console navigation menu in the Other section. Clicking on it will bring up the page shown in the following screenshot:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset