Little-G: slim down your app Server

Source: Internet
Author: User
Tags apache tomcat
Do you often build simple applications, but you must use heavyweight application servers to deploy them? Do you know that we often use a few percent of the many features of Java platform and Enterprise Edition (Java ee? I guess it's only 10%. Apache Geronimo is a stable and open-source Java 2 platform, Enterprise Edition (J2EE) 1.4 Certified Application Server. However, it has many features and is too large. To build a simple, lightweight, but useful container for Web applications, Apache developers have created Apache Geronimo little-G, a simplified version of the original Geronimo application server. Although little-G is not a J2EE-certified server, it has the most common J2EE-compliant features, including a complete Web Container, Transaction Manager, and database connectivity. In this article, we will study the features of little-G and learn how to deploy and run Web applications on it.

Geronimo Platform

When discussing little-G and Geronimo, you must explain the underlying architecture. The Geronimo platform has a modular architecture. The core platform is a unit service component.GbeanRuntime container. Related gbeans are grouped into deployable units. Such units are calledConfiguration). The little-G server uses the modular architecture of the Geronimo platform to build a lightweight server. Figure 1 shows the internal structure of little-G.


Figure 1. Geronimo Platform Architecture

You can add new services and functions by deploying configurations on the Geronimo platform. The Geronimo kernel and basic Geronimo system configurations constitute the core platform of all the Geronimo servers. Little-G is built on this core and adds a remote Method Invocation (RMI) Naming configuration, which provides the naming service function. In addition, the RMI naming configuration provides a thread pool and plug-in installer. The Java EE server and Java EE security configuration are named after Rmi as their parent configuration. Java EE server configuration implements Java EE management objects, such as server domains and server objects. Java EE Security Configuration implements the Security Service and JAAS login module based on Java authentication and authorization Service (JAAS), and creates a security domain based on the configuration file, which can be accessed from the user application. Transaction configuration is built on the Java EE server, which provides the transaction processing function. Finally, the Apache Tomcat configuration adds the Tomcat web container to Geronimo.

In addition to the configurations shown in figure 1, little-G also includes the following deployers and configurations:

  • Geronimo/Geronimo-gbean-deployer/1.1.1/CAR Configuration-- Deploy the little-G Module
  • Geronimo/j2ee-deployer/1.1.1/CAR Configuration-- Process Java EE deployment of Web Applications
  • Geronimo/tomcat-deployer/1.1.1/CAR Configuration-- Deploy web applications to Tomcat web containers
  • Three configurations:
    • Geronimo/unavailable-EJB-deployer/1.1.1/Car-- Solve the Problem of Enterprise JavaBeans (EJB) Unavailability
    • Geronimo/unavailable-WebServices-deployer/1.1.1/Car-- Handle the problem of Web Service unavailability
    • Geronimo/unavailable-client-deployer/1.1.1/Car-- Solve the problem that the client application deployer is unavailable




Little-G services and features

Little-G provides the following services and features:

  • A tomcat or jetty-based Web Container
  • A Java EE basic Server
  • A jaas-based security implementation
  • A Naming Service Based on RMI
  • A deployment tool that can deploy gbean configurations
  • A deployer that can deploy Web Applications
  • Through the JDBC connectivity implemented by tranql code, tranql is an open source implementation used to create a persistence Engine
  • Used to create and deploy the Geronimo plug-in

    Note:The Geronimo plug-in is similar to the Eclipse plug-in, which contains packaged applications or additional features. The Geronimo plug-in encapsulates all deployment information. Therefore, you can install them easily without worrying about the environment-specific settings.




Getting started with little-G

You can set little-g in either of the following ways:

  • Download and install the server archive file.
  • Build a server using source code.

If you want to build a server using the source code, you must download the source code file and run a specific Maven target to build and create the server. However, in this article, you will install the archive file. Therefore, you need to use subversion to download the Geronimo source code.

Download and install little-G

First download Geronimo. Here you can find UNIX and Microsoft Windows files on the Geronimo server and little-G. Download the little-G Apache Tomcat compressed file and decompress it to the geronimo_home folder, as shown in figure 2.


Figure 2. Little-G directory

The directory structure of little-G installation is similar to that of Geronimo installation. After all, it is just a Geronimo installation.

Test the installation of little-G

Little-G does not have a console application, so you cannot test the installation by accessing the console application (http: // localhost: 8080/console) in a browser. For little-G, you must use command-line interface (CLI) to interact with the server. Run one of the following commands from the geronimo_home/bin directory to start the server:


GERONIMO_HOME/bin> java –jar server.jar

Or:

GERONIMO_HOME/bin> startup

Start the server and display the startup information in the Command window, as shown in 3.


Figure 3. Little-G startup message

If you see these messages, the installation of little-G is normal.

Little-G starts the following listeners:

  • Name Service of listening port 1099
  • Listener port 4242 remote login listener
  • Tomcat accelerated graphics port (AGP) connector for Apache Web server integration
  • HTTP and HTTP over Secure Sockets Layer (https) listeners, listening to ports 8080 and 8443 respectively
  • Java Management extension (JMX) connector, which is used by deployment tools to deploy applications

How do you knowStartServer. To close it smoothly, you should issue the following command from the command window:


GERONIMO_HOME/bin> shutdown –user system –password manager



Modify little-G settings

You can use little-g to easily modify most system settings (such as log level and Web Listener port ). The geronimo_home/var/config. xml file contains persistent settings. For example, if you need to modify the Tomcat HTTP listening port, modifyTomcatWebConnectorGbeanportThe attribute value, as shown in Listing 1.


Listing 1. config. xml

<module name="geronimo/tomcat/1.1.1/car">
<gbean name="TomcatResources"/>
<gbean name="TomcatWebConnector">
<attribute name="host">0.0.0.0</attribute>
<attribute name="port">8080</attribute>
<attribute name="redirectPort">8443</attribute>
</gbean>
<gbean name="TomcatAJPConnector">
<attribute name="host">0.0.0.0</attribute>
<attribute name="port">8009</attribute>
<attribute name="redirectPort">8443</attribute>
</gbean>
<gbean name="TomcatWebSSLConnector">
<attribute name="host">0.0.0.0</attribute>
<attribute name="port">8443</attribute>
</gbean>
<gbean name="geronimo/tomcat/1.1.1/car?ServiceModule=geronimo/tomcat/1.1.1/car,
j2eeType=GBean,name=TomcatWebContainer">
<attribute name="catalinaHome">var/catalina</attribute>
</gbean>
</module>


Similarly, you can modifyTomcatWebSSLConnectorGbeanportElement value to modify the HTTPS listener port. The config. xml file is read every time the server is started. These attribute values are applied to the corresponding gbean. When you deploy a new application or cancel the deployment, the server updates the file to reflect the changes. In general, you can specify the corresponding entries in this file to provide new values or modify existing values for any gbean in the module. However, if you need to modify the log settings, the operations are different. Must be modified in the geronimo_home/var/log/server-log4j.properties file.




Download, deploy, and run the sample application

Because little-G does not include sample applications, they must be downloaded and deployed separately. Therefore, you need to learn how to deploy and run Web applications in little-G.

Download the sample application

ClickSample applicationsLink to display the list of sample applications. ClickWeb Application Security sampleDownload the sample application. (Timereport.zip ). In this example application, employees can enter their time card information, and managers can enter time card information and add new employees. This application uses a database-based security domain to implement Web Application Security.

Set Database

Note:I used a PostgreSQL v8.0 database (see references ). You can use any other database, but my example list is applicable to PostgreSQL settings.

Run the SQL script (config/timereportdb. SQL, which can be found in timereport.zip provided in the download section) after a ready-to-run database is created ). This script creates user and group tables. You will use these tables to set database-based security domains.

Install the database driver in the little-G Repository

You have seen the directory structure of little-G: geronimo_home/repository contains all external libraries. Install the database driver. jar file in this directory. The repository directory structure contains external libraries in subdirectories. These subdirectories comply with the maven naming conventions, as shown in figure 4.


Figure 4. Little-G Repository

You can see the commons-digester-1.6.jar file in the Commons-digester/commons-digester/1.6 directory. This means that if the groupid of a project is cglib, The artifactid is cglib-nodep, the version is 2.1_3, And the type is jar, then little-G looks for the file cglib-nodep-2.1_3.jar in the javasimo_home/Repository/cglib/cglin-nodep/2.1 _ 3 folder. To install the postgresql-8.0.jar file, place it in the PostgreSQL/8.0 subdirectory of the repository folder.

Deploy security domains

This example application uses a database-based security domain, which must be installed before the web application is installed. Edit the security domain deployment plan-config/timereportrealm. XML -- specify the dependency as the PostgreSQL database driver. JAR file, JDBC Driver Class, and JDBC connection URL configured by the login module, as shown in List 2.


List 2. security domain configuration and deployment plan

<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
<environment>
<moduleId>
<groupId>console</groupId>
<artifactId>TimeReportRealm</artifactId>
<version>1.0</version>
<type>car</type>
</moduleId>
<dependencies>
<dependency>
<groupId>geronimo</groupId>
<artifactId>j2ee-security</artifactId>
<type>car</type>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.0</version>
<type>jar</type>
</dependency>
</dependencies>
</environment>
<gbean name="TimeReportRealm"
class="org.apache.geronimo.security.realm.GenericSecurityRealm">
<attribute name="realmName">TimeReportRealm</attribute>
<reference name="ServerInfo">
<name>ServerInfo</name>
</reference>
<reference name="LoginService">
<name>JaasLoginService</name>
</reference>
<xml-reference name="LoginModuleConfiguration">
<log:login-config
xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-1.1">
<log:login-module control-flag="REQUIRED"
server-side="true" wrap-principals="false">
<log:login-domain-name>TimeReportRealm</log:login-domain-name>
<log:login-module-class>
org.apache.geronimo.security.realm.providers.SQLLoginModule<
/log:login-module-class>
<log:option name="jdbcDriver">org.postgresql.Driver</log:option>
<log:option name="jdbcUser">postgres</log:option>
<log:option name="userSelect">
select userid, password from users where userid=?
</log:option>
<log:option name="groupSelect">
select userid, groupname from usergroups where userid=?
</log:option>
<log:option name="jdbcURL">
jdbc:postgresql://localhost:5432/TimeReportDB
</log:option>
</log:login-module>
</log:login-config>
</xml-reference>
</gbean>
</module>


moduleIdElement for this deployment unit (also knownConfiguration) Specifies a Maven-style name. This means that you can use the Uniform Resource Identifier (URI) Common/timereportrealm/1.0/CAR to reference this configuration from other configurations. Note that I have specified a Maven-style dependency definition for the PostgreSQL. jar file in the repository. The JDBC Driver Class, database username, and Connection database are also specified.usersAndusergroupTable.

After modifying the deployment plan, run the following command to deploy the Configuration:


deploy –user system –password manager deploy TimeReportRealm.xml

This command deploys the security domain as the console/timereportrealm/1.0/CAR configuration. To cancel the deployment of this security domain, run the following command:


deploy –user system –password manager undeploy console/TimeReportRealm/1.0/car

Deploy Web Applications

You can obtain the web application. War file from the release directory or the download section of this article. To deploy the. War file, run the following command:


deploy –user system –password manager deploy TimeReport.war

This command will deploy the web application. You can access http: // localhost: 8080/timereport in the browser to call this program. You can enteremp1As user name,pass1As the password to log on as an employee. To log on as a manager, entermgm1pass3As the password. You can also open web. xml and geronimo-web.xml deployment descriptors to learn more about how authentication is defined and how it is mapped to a security domain. As user name,




Little-G

If Web applications only need transaction processing facilities and database connectivity, then little-G can be used. In this regard, little-G provides a complete Web Container with all relevant and necessary Java EE features. You have seen how a simple web application uses the built-in Web security features of little-G. For simple small Web applications, little-G is very suitable.




Conclusion

This article introduces little-G and its services for Java EE applications, and explains how the modular nature of the Apache Geronimo platform supports creating small and lightweight versions of Geronimo. We also configured, deployed, and run a sample Web Application in little-G. Little-G provides a simplified version of Geronimo that can take advantage of the modular nature of Geronimo to start building applications on little-G.

Exercise: Add new configurations to provide the services you want to support. This is the power of Geronimo!


Download

Description Name Size Download Method
Sample Application of the time report used in this article Timereport.zip 95kb HTTP


About the author


Kishore Kumar is the Java Center of Excellence director of US technology. He loves open source systems, flags, and classical music. He used to be a software engineer and J2EE architect, or author of many books and articles, includingPro Apache Geronimo.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.