Developing Apache Geronimo Plugins

Apache Geronimo is an open source application server that is suitable for use on everything from development environments to enterprise-level deployments. Geronimo brings together the best-of-breed open source technologies to deliver full Java EE 5 compliance. Distributed under the ASL2.0 license, one of the most liberal open source licenses, Geronimo becomes an application server of choice for enterprises and solution vendors.

also read:

This book provides the reader with a comprehensive reference to the Apache Geronimo Application Server from the Apache Server Foundation. The authors have provided a reference for the average Apache Geronimo user that provides the user with the steps required to configure anything and everything in Apache Geronimo. This book covers everything from where to download the server software to how to customize it using custom GBeans. After reading this book, the user will be familiar with most of the features of Apache Geronimo v2.1.

This book provides samples that are relevant to each task being performed. The book provides an in-depth coverage of the Apache Geronimo internals, in order for the user to be able to write custom services on Geronimo. There is also coverage of the Geronimo plugin architecture and how to extend the server functionality through plugins. The authors have made the different configuration items available as self contained chapters that can be referred to independently of the other chapters, so that readers can go straight to whatever part of Geronimo they want to configure.

What This Book Covers

Chapter 1: Introduction – This chapter introduces the reader to the Apache Geronimo Application Server, lists the features that it provides, and the steps that the user has to follow in order to download, install, and start the server.

Chapter 2: Architecture – This chapter gives a high-level overview of the Geronimo architecture. It introduces the reader to the concepts of GBeans, Geronimo Plugins, and the different subsystems of Geronimo.

Chapter 3: Database connectivity – This chapter talks about Geronimo’s database connectivity features. It lists the databases supported, and explains how to create database pools and establish connectivity with all of the supported databases using Geronimo.

Chapter 4: JMS – This chapter details the messaging features that Geronimo provides, and guides the user through using the bundled JMS provider, ActiveMQ, to create and use JMS resources.

Chapter 5: Java EE Application deployment – This chapter details the installation of different types of Java EE applications and modules and application clients. It guides users through writing deployment plans for these different Java EE artifacts. This chapter
also covers the transaction support provided by Geronimo.

Chapter 6: Security – This chapter takes the user through configuring security in order to secure the server environment and the applications running in Geronimo.

Chapter 7: CORBA – This chapter covers configuring the EJBs running in Geronimo so that they are available through CORBA, and also covers configuring remote EJB references to invoke remote EJBs through CORBA.

Chapter 8: JNDI – This chapter describes the different JNDI environments in Geronimo, gives the steps necessary to bind custom resources to JNDI by using GBeans, and shows us how the global JNDI environment can be leveraged for user’s applications.

Chapter 9: Plugins – This chapter educates the user in creating and deploying Geronimo plugins, creating custom server assemblies, and extending Administration Console through plugins.

Chapter 10: Administration – This chapter walks the user through the common administration tasks, such as managing server components, application management, monitoring, working with keystores, and GShell.

Chapter 11: Eclipse Plugin – This chapter introduces the Geronimo Eclipse Plugin (GEP) and explains how to obtain and install it. It takes the user through the various features of the GEP and shows how to develop a sample application by using the Geronimo Eclipse Plugin.

Chapter 12: Clustering – This chapter covers how to configure horizontal and vertical clustering using Geronimo, demonstrates web application clustering using WADI, and explains how to configure load balancing by using the Apache Web Server and mod_jk plugin.

Chapter 13: Logging – This chapter covers all of the configurations required for setting up logging for both the server and user applications. It covers logging frameworks such as log4j JUL, and so on, and the SLF4j wrapper that comes with Geronimo.

Chapter 14: Geronimo Internals – This chapter introduces the user to the internals of Geronimo and the low-level services such as kernel, server info, configuration manager, and so on. It takes the user through developing and deploying new services through GBeans.

Appendix-A: Deployment plans – This appendix covers elements common to all Geronimo deployment plans.

Appendix-B: Troubleshooting – This appendix covers troubleshooting server startup, application deployment, application startup, and runtime problems.

Geronimo Plugins 

Apache Geronimo provides a mechanism for users to extend its functionality through plugins. In this chapter, we will explore how to extend the functionality of Apache Geronimo, by using Geronimo plugins. In fact, all of the Java EE functionality in Apache Geronimo is installed as plugins. For example, the web services functionality is provided through the Axis, Axis2, and CXF plugins. EJB functionality is provided through the OpenEJB plugin, and so on. Therefore, if you want to extend the server to provide new functionality, such as job scheduling, then you can write a plugin to integrate a scheduler (such as Quartz) into Apache Geronimo. There are also a large number of plugins available for Apache Geronimo already. We will also cover the custom server assemblies feature in this chapter. This feature will enable you to export custom server assemblies, from either the server’s Administration Console or the command-line shell. In this chapter, you will learn about:

  • Developing and installing Apache Geronimo plugins
  • Extending the Administration Console through plugins
  • Creating custom server assemblies

Developing a plugin

In this section, we will develop our very own plugin, the World Clock plugin. This is a very simple plugin that provides the time in different locales. We will go through all of the steps required to develop it from scratch. These steps are as follows:

  • Creating the plugin project
  • Generating the plugin project, using maven2
  • Writing the plugin interface and implementation
  • Creating a deployment plan
  • Installing the plugin

Creating a plugin project

There are many ways in which you can develop plugins. You can manually create all of the plugin artifacts and package them. We will use the easiest method, that is, by using Maven’s geronimo-plugin-archetype. This will generate the plugin project with all of the artifacts with the default values filled in.

To generate the plugin project, run the following command:

mvn archetype:create -DarchetypeGroupId=org.apache.geronimo.buildsupport
-DarchetypeArtifactId=geronimo-plugin-archetype -DarchetypeVersion=2.1.4
-DgroupId=com.packt.plugins -DartifactId=WorldClock

This will create a plugin project called WorldClock. A directory called WorldClock will be created, with the following artifacts in it:

  • pom.xml
  • pom.sample.xml
  • src/main/plan/plan.xml
  • src/main/resources

In the same directory in which the WorldClock directory is created, you will need to create a java project that will contain the source code of the plugin. We can create this by using the following command:

<b>mvn archetype:create -DgroupId=com.packt.plugins -DartifactId=WorldClock
Module

This will create a java project with the same groupId and artifactId in a directory called WorldClockModule. This directory will contain the following artifacts:

  • pom.xml
  • src/main/java/com/packt/plugins/App.java
  • src/test/java/com/packt/plugins/AppTest.java

You can safely remove the second and third artifacts, as they are just sample stubs generated by the archetype.

In this project, we will need to modify the pom.xml to have a dependency on the Geronimo kernel, so that we can compile the GBean that we are going to create and include in this module. The modified pom.xml is shown below:

	<project xmlns="http://maven.apache.org/POM/4.0.0"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://maven.apache.org/POM/4.0.0

http://maven.apache.org/maven-v4_0_0.xsd">

		<modelVersion>4.0.0</modelVersion>
		<groupId>com.packt.plugins</groupId>
		<artifactId>WorldClockModule</artifactId>
		<packaging>jar</packaging>
		<version>1.0-SNAPSHOT</version>
		<name>WorldClockModule</name>
		<url>http://maven.apache.org</url>
		<dependencies>
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>3.8.1</version>
				<scope>test</scope>
			</dependency>
			<dependency>
				<groupId>org.apache.geronimo.framework</groupId>
				<artifactId>geronimo-kernel</artifactId>
				<version>2.1.4</version>
			</dependency>
		</dependencies>
	</project>

For simplicity, we have only one GBean in our sample. In a real world scenario, there may be many GBeans that you will need to create. Now we need to create the GBean that forms the core functionality of our plugin. Therefore, we will create two classes, namely, Clock and ClockGBean. These classes are shown below:

	
package com.packt.plugins;
	import java.util.Date;
	import java.util.Locale;
	public interface Clock {
		public void setTimeZone(String timeZone);
		public String getTime();
	}

and

	
	package com.packt.plugins;
	import java.text.DateFormat;
	import java.text.SimpleDateFormat;
	import java.util.Calendar;
	import java.util.Date;
	import java.util.GregorianCalendar;
	import java.util.Locale;
	import java.util.TimeZone;
	import org.apache.geronimo.gbean.GBeanInfo;
	import org.apache.geronimo.gbean.GBeanInfoBuilder;
	import org.apache.geronimo.gbean.GBeanLifecycle;
	import sun.util.calendar.CalendarDate;
	public class ClockGBean implements GBeanLifecycle, Clock{
		public static final GBeanInfo GBEAN_INFO;
		private String name;
		private String timeZone;
		public String getTime() {
			GregorianCalendar cal = new GregorianCalendar(TimeZone.
			getTimeZone(timeZone));
			int hour12 = cal.get(Calendar.HOUR); // 0..11
			int minutes = cal.get(Calendar.MINUTE); // 0..59
			int seconds = cal.get(Calendar.SECOND); // 0..59
			boolean am = cal.get(Calendar.AM_PM) == Calendar.AM;
			return (timeZone +":"+hour12+":"+minutes+":"+seconds+":"+((am)?
				"AM":"PM"));
		}
		public void setTimeZone(String timeZone) {
			this.timeZone = timeZone;
		}
		public ClockGBean(String name){
			this.name = name;
			timeZone = TimeZone.getDefault().getID();
		}
		public void doFail() {
			System.out.println("Failed.............");
		}
		public void doStart() throws Exception {
			System.out.println("Started............"+name+" "+getTime());
		}
		public void doStop() throws Exception {
			System.out.println("Stopped............"+name);
		}
		  static {
			GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic
				("ClockGBean",ClockGBean.class);
			infoFactory.addAttribute("name", String.class, true);
			infoFactory.addInterface(Clock.class);
			infoFactory.setConstructor(new String[] {"name"});
			GBEAN_INFO = infoFactory.getBeanInfo();
		  }
		  public static GBeanInfo getGBeanInfo() {
			return GBEAN_INFO;
		  }
	}

As you can see, Clock is an interface and ClockGBean is a GBean that implements this interface. The Clock interface exposes the functionality that is provided by the ClockGBean. The doStart(), doStop(), and doFail() methods are provided by the GBeanLifeCycle interface, and provide lifecycle callback functionality. Refer to Chapter 14, Geronimo Internals, for more detailed explanations on writing your own GBeans. The next step is to run Maven to build this module. Go to the command prompt, and change the directory to the WorldClockModule directory. To build the module, run the following command:

mvn clean install

Once the build completes, you will find a WorldClockModule-1.0-SNAPSHOT.jar in the WorldClockModule/target directory.

Now change the directory to WorldClock, and open the generated pom.xml file. You will need to uncomment the deploymentConfigs for the gbeanDeployer, and add the following module that you want to include in the plugin:

	<module>
		<groupId>com.packt.plugins</groupId>
		<artifactId>WorldClockModule</artifactId>
		<version>1.0</version>
		<type>jar</type>
	</module>

You will notice that we are using the car-maven-plugin in the pom.xml file. The car-maven-plugin is used to build Apache Geronimo configuration archives without starting the server.

The final step is to create the deployment plan in order to deploy the module that we just created into the Apache Geronimo server. This deployment plan will be used by the car-maven-plugin to actually create the artifacts that will be created during deployment to Apache Geronimo. The deployment plan is shown below:

	<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
		<environment>
			<moduleId>
				<groupId>com.packt.plugins</groupId>
				<artifactId>WorldClock</artifactId>
				<version>1.0</version>
				<type>car</type>
			</moduleId>
			<dependencies/>
			<hidden-classes/>
			<non-overridable-classes/>
			<private-classes/>
		</environment>
		<gbean name="ClockGBean" class="com.packt.clock.ClockGBean">
			<attribute name="name">ClockGBean</attribute>
		</gbean>
	</module>

Once the plan is ready, go to the command prompt and change the directory to the WorldClock directory. Run the following command to build the plugin:

mvn clean install

You will notice that the car-maven-plugin is invoked and a WorldClock-1.0-SNAPSHOT.car file is created in the WorldClock/target directory. We have now completed the steps required to create an Apache Geronimo plugin. In the next section, we will see how we can install the plugin in Apache Geronimo.

Installing a plugin

We can install a plugin in three different ways. One way is to use the deploy.bat or deploy.sh script, another way is to use the install- plugin command in GShell, and the third way is to use the Administration Console to install a plugin from a plugin repository. We will discuss each of these methods:

  • Using deploy.bat or deploy.sh file: The deploy.bat or deploy.sh script is found in the <GERONIMO_HOME>/bindirectory. It has an option install-plugin, which can be used to install plugins onto the server. The command syntax is shown below:deploy install-plugin Running this command, and passing the path to the plugin .car archive on the disk, will result in the plugin being installed onto the Geronimo server. Once the installation has finished, an Installation Complete message will be displayed, and the command will exit.
  • Using GShell:Invoke the gsh command from the command prompt, after changing the current directory to <GERONIMO_HOME>/bin. This will bring up the GShell prompt. In the GShell prompt, type the following command to install the plugin:deploy/install-plugin Please note that, you should escape special characters in the path by using a leading “\” (back slash) before the character.Another way to install plugins that are available in remote plugin repository is by using the list-plugins command. The syntax of this command is as given below:deploy/list-plugins

    If a remote repository is not specified, then the one configured in Geronimo will be used instead. Once this command has been invoked, the list of available plugins in the remote repository is shown, along with their serial numbers, and you will be prompted to enter a comma separated list of the serial numbers of the plugins that you want to install.

  • Using the Administration Console:The Administration Console has a Plugins portlet that can be used to list the plugins available in a repository specified by the user. You can use the Administration Console to select and install the plugins that you want from this list. This portlet also has the capability to export applications or services in your server instance as Geronimo plugins, so that they can be installed on other server instances. See the Plugin portlet section for details of the usage of this portlet.

Available plugins

The web site http://geronimoplugins.com/ hosts Apache Geronimo plugins. It has many plugins listed for Apache Geronimo. There are plugins for Quartz, Apache Directory Server, and many other popular software packages. However, they are not always available for the latest versions of Apache Geronimo. A couple of fairly up-to-date plugins that are available for Apache Geronimo are the Windows Service Wrapper plugin and the Apache Tuscany plugin for Apache Geronimo. The Windows Service Wrapper provides the ability for Apache Geronimo to be registered as a windows service. The Tuscany plugin is an implementation of the SCA Java EE
Integration specification by integrating Apache Tuscany as an Apache Geronimo plugin. Both of these plugins are available from the Apache Geronimo web site.

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:

geronimo-1

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:
    &lt;dependency&gt;
    	&lt;groupId&gt;org.apache.geronimo.framework&lt;/groupId&gt;
    	&lt;artifactId&gt;geronimo-kernel&lt;/artifactId&gt;
    	&lt;version&gt;2.1.4&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
    	&lt;groupId&gt;com.packt.plugins&lt;/groupId&gt;
    	&lt;artifactId&gt;WorldClockModule&lt;/artifactId&gt;
    	&lt;version&gt;1.0&lt;/version&gt;
    &lt;/dependency&gt;
    

    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(&quot;text/html;charset=UTF-8&quot;);
    		// Get the writer to the response
    		PrintWriter out = response.getWriter();
    		Kernel kernel = KernelRegistry.getSingleKernel();
    		try {
    			Clock cl = (Clock)kernel.getGBean(&quot;ClockGBean&quot;);
    			String[] ids = TimeZone.getAvailableIDs();
    			for(int i=0;i&lt;ids.length;i++){
    				cl.setTimeZone(ids[i]);
    				out.println(cl.getTime());
    				out.println(&quot;&lt;br&gt;&quot;);
    			}
    		} 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:
    &lt;web-app&gt;
    	&lt;servlet&gt;
    		&lt;servlet-name&gt;WorldClockPortlet&lt;/servlet-name&gt;
    		&lt;servlet-class&gt;org.apache.pluto.core.PortletServlet
    			&lt;/servlet-class&gt;
    		&lt;init-param&gt;
    			&lt;param-name&gt;portlet-name&lt;/param-name&gt;
    			&lt;param-value&gt;WorldClockPortlet&lt;/param-value&gt;
    		&lt;/init-param&gt;
    		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    	&lt;/servlet&gt;
    	&lt;servlet-mapping&gt;
    		&lt;servlet-name&gt;WorldClockPortlet&lt;/servlet-name&gt;
    		&lt;url-pattern&gt;/PlutoInvoker/WorldClockPortlet&lt;/url-pattern&gt;
    	&lt;/servlet-mapping&gt;
    &lt;/web-app&gt;
    
  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:
    &lt;web-app xmlns=&quot;http://geronimo.apache.org/xml/ns/j2ee/web-1.2&quot;&gt;
    	&lt;environment&gt;
    		&lt;moduleId&gt;
    			&lt;groupId&gt;com.packt.plugins&lt;/groupId&gt;
    			&lt;artifactId&gt;WorldClockView&lt;/artifactId&gt;
    			&lt;version&gt;1.0&lt;/version&gt;
    			&lt;type&gt;war&lt;/type&gt;
    		&lt;/moduleId&gt;
    		&lt;dependencies&gt;
    			&lt;dependency&gt;
    				&lt;groupId&gt;org.apache.geronimo.plugins&lt;/groupId&gt;
    				&lt;artifactId&gt;pluto-support&lt;/artifactId&gt;
    				&lt;type&gt;car&lt;/type&gt;
    			&lt;/dependency&gt;
    			&lt;dependency&gt;
    				&lt;groupId&gt;com.packt.plugins&lt;/groupId&gt;
    				&lt;artifactId&gt;WorldClock&lt;/artifactId&gt;
    				&lt;type&gt;car&lt;/type&gt;
    			&lt;/dependency&gt;
    		&lt;/dependencies&gt;
    	&lt;/environment&gt;
    	&lt;!-- This is where the files are accessed from. (aka -
    		portletContext) --&gt;
    	&lt;context-root&gt;/WorldClockPortlet&lt;/context-root&gt;
    	&lt;!-- Start off a ACEGBean, this is the lifecycle for the
    		portlet --&gt;
    	&lt;gbean name=&quot;PlutoTest&quot; class=&quot;org.apache.geronimo.pluto.
    		AdminConsoleExtensionGBean&quot;&gt;
    		&lt;attribute name=&quot;pageTitle&quot;&gt;World Clock&lt;/attribute&gt;
    		&lt;attribute name=&quot;portletContext&quot;&gt;/WorldClockPortlet
    			&lt;/attribute&gt;
    		&lt;attribute name=&quot;portletList&quot;&gt;[WorldClockPortlet]
    			&lt;/attribute&gt;
    		&lt;reference name=&quot;PortalContainerServices&quot;&gt;
    			&lt;name&gt;PlutoPortalServices&lt;/name&gt;
    		&lt;/reference&gt;
    	&lt;/gbean&gt;
    &lt;/web-app&gt;
    

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

    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:

geronimo-2

Plugins portlet

The Plugins portlet enables a user to dynamically install new features into the Geronimo server, create plugins out of existing configurations on the server, and create server assemblies consisting of some or all of the existing plugins in the server. By using the Install Geronimo Plugins section, you can search for plugins in a plugin repository or add new repositories for plugin searches. You can also download running configurations from another Geronimo server, just as if you’re browsing and installing third-party plugins by using the repository URL http://remote-geronimo-server:8080/plugin/maven-repo/ and providing the administrator username and password.

In order to search for plugins, select the repository URL, and click on Show Plugins in selected repository. This will show all of the available plugins in that repository, as shown in the next screenshot:

geronimo-3A check mark in the Installable column for the plugin name indicates that the plugin is installable. You can click on the plugin name to view the details of the plugin. You can select one or more plugins, and click on Install to install the plugins. The portlet will show the status as the plugins are installing and display a confirmation message once completed.

The Create Geronimo Plugin section lets you create a new plugin out of an existing configuration on the server. Select the configuration to be exported as a plugin, and click on the Export Plugin button. On the next page, you can fill in various details, such as Download Repositories that need to be looked in for downloading Dependencies, a Description of the plugin, the Geronimo Versions on which the plugin can be installed, JVM versions, the dependencies of this plugin on other configurations or artifacts, Prerequisite configurations, and so on. The fields have detailed explanation on this page. After completing the fields, click on Save Plugin Data. On the next screen, click on the Export Plugin button to save the plugin to filesystem. The configuration will be saved as a configuration archive (CAR) file.

Custom server assemblies and server profiles

Apache Geronimo provides a feature known as custom server assemblies. This allows users to assemble servers that are customized to their needs. They can assemble the application servers that contain their applications or plugins prepackaged with only the additional dependent modules that their applications or plugins require. We will go through the steps to assemble a custom server that contains the World Clock plugin as follows:

  1. Log in to the Administration Console, and go to the Plugins portlet.
  2. In the Assemble Server portlet, click on the Assemble a server button. This will bring up the screen shown in the following screenshot:
  3. geronimo-4

  4. Enter the groupId, artifactId, version, and the target path where the assembly should be saved under the <GERONIMO_HOME> directory, and select the required format. Select the plugins that need to be included in the assembly, and click on the Assemble button. Always select Geronimo Assemblies :: Boilerplate Minimal. Select the WorldClock plugin. The WorldClock plugin does not need any other Apache Geronimo’s services, so we need not include any other assemblies.
  5. Click on the Assemble button at the bottom of the screen. This will bring up the screen shown in the next screenshot:
  6. geronimo-5

  7. Click on the Assemble button to assemble the custom server. Once the server assembly process is complete, a screen with the status and the location of the crea ted assembly will pop up.
  8. Now stop the current server, and start the server you just assembled. You will see that the WorldClock plugin is started, as the time will be printed out during startup. You can also assemble custom servers through deploy/assemble command in GShell.

Summary

In this chapter, we saw how Apache Geronimo’s plugin architecture provides the capability for users to extend the functionality of the server. We saw how we can develop a plugin and deploy it to the server. We also had a look at the pluggable administration console, and how to create and plug in a new Administration Console portlet. We also saw how Apache Geronimo allows users to export custom server assemblies. In conclusion, Apache Geronimo turns out to be a very modular, customizable, and flexible application server. In the next chapter, we will see how we can administer Apache Geronimo. We will look into administering the different resources, plugins, and applications that are deployed on the server, as well as other server configuration options.

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Comments

  1. car-maven-plugin fails to build car for Geronimo 3. Any suggestions ?

    [INFO] Started deployer: org.apache.geronimo.configs/j2ee-deployer/3.0.1/car
    [org.apache.geronimo.system.configuration.RepositoryConfigurationStore] : Configuration directory: /home/QEuser/PROJECTS/JAVA/Geronimo/WorldClock/target/repository/com/packt/plugins/WorldClock/1.0.0 is created
    [org.apache.geronimo.system.configuration.DependencyManager] : found geronimo-plugin.xml for bundle com.packt.plugins.WorldClock-DEPLOYMENT_1.0.0 [90]
    [org.apache.geronimo.kernel.config.Configuration] : Started configuration com.packt.plugins/WorldClock/1.0.0/car
    [org.apache.geronimo.kernel.config.Configuration] : Stopping configuration com.packt.plugins/WorldClock/1.0.0/car
    [main] ERROR org.apache.geronimo.deployment.Deployer – Deployment failed due to
    org.apache.geronimo.gbean.InvalidConfigurationException: Could not load class com.packt.clock.ClockGBean from bundle com.packt.plugins.WorldClock-DEPLOYMENT_1.0.0 [90] at location reference:file:/tmp/geronimo-fileutils5822359901809455737.tmpdir/
    at org.apache.geronimo.gbean.annotation.AnnotationGBeanInfoFactory.getGBeanInfo(AnnotationGBeanInfoFactory.java:42)

Speak Your Mind

*