apache geronimo 2.1 quick reference - home | packt publishing

24
Apache Geronimo 2.1 Quick Reference Vamsavardhana Reddy Chillakuru Manu T. George Chapter No. 9 "Geronimo Plugins"

Upload: others

Post on 03-Feb-2022

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Apache Geronimo 2.1Quick Reference

Vamsavardhana ReddyChillakuruManu T. George

Chapter No. 9"Geronimo Plugins"

Page 2: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

In this package, you will find:A Biography of the authors of the book

A preview chapter from the book, Chapter NO.9 "Geronimo Plugins"

A synopsis of the book’s content

Information on where to buy this book

About the AuthorsVamsavardhana Reddy Chillakuru, a.k.a. Vamsi, is an Advisory SoftwareEngineer who has been working with IBM India Private Limited since 1996, and is partof the IBM worldwide Level 3 support team for Apache Geronimo and IBM WebSphereApplication Server Community Edition (WASCE). He is proficient in Java and Java EEtechnologies, having more than 13 years experience in the IT Industry. His interestsinclude application security in general, and cryptographic security in particular. He haspresented sessions Apache conferences on various Apache Geronimo topics, rangingfrom security to server administration. He has authored many articles within IBM ondeveloperWorks, and has also co-authored an IBM Redbook on Migration from WASCEto WebSphere Application Server (WAS). Considered as a security expert in theGeronimo community, he is actively involved in adding new security features toGeronimo. Associated with the Apache Geronimo project since July 2005, he is acommitter on Apache Geronimo and Apache Tuscany projects, and is a member of theApache Geronimo PMC. He is involved in the standards development for ServiceComponent Architecture (SCA) and is a member of the OASIS (Organization for theAdvancement of Structured Information Standards) SCA-Assembly, SCA-Java, andSCA-Policy Technical Committees, and the SCA-J Java EE Subcommittee. He receivedhis B.Stat. (Hons.) and M.Stat. degrees from the Indian Statistical Institute, Kolkata,India in 1994 and 1996 respectively.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 3: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

I thank my wife Sushma and my son Susanth for their supportthroughout this book project. I thank my manager Sriram Mahalingamand director Kalpana Margabandhu at IBM India Private Limited forfacilitating my authorship of this book. I thank my co-author Manu forhis cooperation and the grace with which he handled the project. Ithank the Apache Geronimo community for their support in myproficiency development with Geronimo. Finally, I am grateful toPackt Publishing for giving me this opportunity to author this book andthank Kshipra Singh, Rashmi Phadnis, Rajashree Hamine, DarshanaShinde, and Mayuri Kokate at Packt Publishing for their valuablesupport time and again.

Manu T. George is a Staff Software Engineer at IBM India Software Labs inBangalore, India. He has eight years of experience in the IT field, most of it in Java andJ2EE technologies. He is a committer on the Apache Geronimo and Apache OpenEJBprojects, and has been a part of the IBM WebSphere Application Server CommunityEdition Level 3 Support Team for the past three years. He has been with IBM for aroundfive years. Prior to that, he was an employee of Cognizant Technology Solutions IndiaLtd., and has worked on many services engagements there.

His interests include Application Servers, especially in relation to Scalability, Transactionprocessing, EIS connectivity, and The Java Virtual Machine. He has also authoredarticles in IBM developer works, and has co-authored an IBM Redbook on Migration toWebSphere Application Server.

He received his Bachelor of Technology in Applied Electronics from the College ofEngineering Thiruvananthapuram in 2001.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 4: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

I am very grateful to my employer IBM, manager Sriram Mahalingam,and Director Kalpana Margabandhu for supporting me in writing thisbook and to Packt Publishing for giving me this opportunity. I wouldlike to thank all the Packt staff that worked with us on this book. Iwould also like to thank my family, and especially my wife Nityafor the support that she provided and for her patience with me when Iwas authoring this book. I would like to thank both the ApacheGeronimo and Apache OpenEJB communities for the support and helpthey gave me in understanding their respective projects. I would alsolike to mention my deep gratitude to David Blevins of ApacheOpenEJB whose guidance and help both technical and non technical,was instrumental in helping me learn and understand the internals ofOpenEJB as well as EJB technology. Finally, I would like to thankVamsi, my co-author, for giving me the opportunity to work with himon this book.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 5: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Apache Geronimo 2.1Quick ReferenceApache Geronimo is an open source application server that is suitable for use oneverything from development environments to enterprise-level deployments.Geronimo brings together the best-of-breed open source technologies to deliver fullJava EE 5 compliance. Distributed under the ASL2.0 license, one of the most liberalopen source licenses, Geronimo becomes an application server of choice for enterprisesand solution vendors.

This book provides the reader with a comprehensive reference to the Apache GeronimoApplication Server from the Apache Server Foundation. The authors have provided areference for the average Apache Geronimo user that provides the user with the stepsrequired to configure anything and everything in Apache Geronimo. This book coverseverything from where to download the server software to how to customize it usingcustom GBeans. After reading this book, the user will be familiar with most of thefeatures of Apache Geronimo v2.1.

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

What This Book CoversChapter 1: Introduction - This chapter introduces the reader to the Apache GeronimoApplication Server, lists the features that it provides, and the steps that the user has tofollow in order to download, install, and start the server.

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

Chapter 3: Database connectivity - This chapter talks about Geronimo's databaseconnectivity features. It lists the databases supported, and explains how to create databasepools 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 anduse JMS resources.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 6: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

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

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

Chapter 7: CORBA - This chapter covers configuring the EJBs running in Geronimo sothat they are available through CORBA, and also covers configuring remote EJBreferences 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 showsus how the global JNDI environment can be leveraged for user's applications.

Chapter 9: Plugins - This chapter educates the user in creating and deploying Geronimoplugins, creating custom server assemblies, and extending Administration Consolethrough plugins.

Chapter 10: Administration - This chapter walks the user through the commonadministration 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 variousfeatures of the GEP and shows how to develop a sample application by using theGeronimo Eclipse Plugin.

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

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

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

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

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

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 7: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Geronimo PluginsApache 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 pluginsExtending the Administration Console through pluginsCreating 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 projectGenerating the plugin project, using maven2Writing the plugin interface and implementationCreating a deployment plan

Installing the plugin

°

°

°

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 8: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Geronimo Plugins

[ 232 ]

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 fi lled 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:

mvn archetype:create -DgroupId=com.packt.plugins -DartifactId=WorldClockModule

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 modifi ed 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">

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 9: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Chapter 9

[ 233 ]

<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;

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 10: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Geronimo Plugins

[ 234 ]

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; }}

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 11: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Chapter 9

[ 235 ]

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 fi nd a WorldClockModule-1.0-SNAPSHOT.jar in the WorldClockModule/target directory.

Now change the directory to WorldClock, and open the generated pom.xml fi le. 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 fi le. The car-maven-plugin is used to build Apache Geronimo confi guration archives without starting the server.

The fi nal 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/>

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 12: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Geronimo Plugins

[ 236 ]

</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 fi le 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 fi le:The deploy.bat or deploy.sh script is found in the <GERONIMO_HOME>/bin directory. 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 <path to the plugin car file>

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 fi nished, 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 <path to the plugin car file>

Please note that, you should escape special characters in the path by using a leading "\" (back slash) before the character.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 13: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Chapter 9

[ 237 ]

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 <URI of the remote repository>

If a remote repository is not specifi ed, then the one confi gured 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 specifi ed 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 specifi cation 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.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 14: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Geronimo Plugins

[ 238 ]

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 specifi ed in the Geronimo-specifi c deployment plan of your web application or plugin, that is, geronimo-web.xml. The architecture is shown in the following fi gure:

Apache Geronimo

PlutoPortalServices

Portlet

WAR

Pluto API

Pluto Impl

ACE

Developing an Administration Console extensionW e 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.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 15: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Chapter 9

[ 239 ]

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>

W e 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();

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 16: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Geronimo Plugins

[ 240 ]

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 fi les, 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>

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 17: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Chapter 9

[ 241 ]

5. In the web.xml fi le shown above, we confi gure 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 fi le.

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>

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 18: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Geronimo Plugins

[ 242 ]

In the geronimo-web.xml fi le, 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 fi le, as shown below, which specifi es 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 fi les, build the web application by invoking the following command from the ClockWebApp directory:mvn clean install

8. Deploy the WAR fi le created to the Apache Geronimo server where you had previously deployed the World Clock plugin.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 19: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Chapter 9

[ 243 ]

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:

Plugins portletT he Plugins portlet enables a user to dynamically install new features into the Geronimo server, create plugins out of existing confi gurations 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 confi gurations 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.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 20: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Geronimo Plugins

[ 244 ]

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:

A 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 confi rmation message once completed.

Th e Create Geronimo Plugin section lets you create a new plugin out of an existing confi guration on the server. Select the confi guration to be exported as a plugin, and click on the Export Plugin button. On the next page, you can fi ll 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 confi gurations or artifacts, Prerequisite confi gurations, and so on. The fi elds have detailed explanation on this page. After completing the fi elds, click on Save Plugin Data. On the next screen, click on the Export Plugin button to save the plugin to fi lesystem. The confi guration will be saved as a confi guration archive (CAR) fi le.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 21: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Chapter 9

[ 245 ]

Custom server assemblies and server profiles Ap ache 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:

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 22: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Geronimo Plugins

[ 246 ]

3. 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.

4. Click on the Assemble button at the bottom of the screen. This will bring up the screen shown in the next screenshot:

5. 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.

6. 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.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 23: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Chapter 9

[ 247 ]

Sum maryIn 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 fl exible 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 confi guration options.

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Page 24: Apache Geronimo 2.1 Quick Reference - Home | Packt Publishing

Where to buy this bookYou can buy Apache Geronimo 2.1 Quick Reference from the Packt Publishing website:http://www.packtpub.com/apache-geronimo-2-2-quick-reference/book

Free shipping to the US, UK, Europe and selected Asian countries. For more information, pleaseread our shipping policy.

Alternatively, you can buy the book from Amazon, BN.com, Computer Manuals andmost internet book retailers.

www.PacktPub.com

For More Information:www.packtpub.com/apache-geronimo-2-2-quick-reference/book