Red Hat APPLICATION SERVER - JONAS Tutorial

Jonas
Hide thumbs Also See for APPLICATION SERVER - JONAS:
Table of Contents

Advertisement

Quick Links

Red Hat Application Server
JOnAS Tutorial

Advertisement

Table of Contents
loading

Summary of Contents for Red Hat APPLICATION SERVER - JONAS

  • Page 1 Red Hat Application Server JOnAS Tutorial...
  • Page 2 All other trademarks and copyrights referred to are the property of their respective owners. The GPG fingerprint of the security@redhat.com key is: CA 20 86 86 2B D6 9D FC 65 F6 EC C4 21 91 80 CD DB 42 A6 0E...
  • Page 3: Table Of Contents

    Table of Contents 1. Introduction............................. 1 1.1. About this Guide ........................ 1 1.2. Enterprise JavaBeans ......................1 1.2.1. What Does What? ....................1 1.2.2. JOnAS Features ....................3 1.2.3. Software Requirements..................4 2. Quick Start ............................5 2.1. Setting Up the Red Hat Application Server Environment ..........5 2.2.
  • Page 4 10. The Alarm Application....................... 41 10.1. Application Architecture Overview ................41 10.2. Finding the Alarm Application ..................42 10.3. Setting Up the Application..................... 42 10.4. Configuring Database Access ..................43 10.5. Running the Alarm Demo....................43 10.6. Known Bugs or Limitations................... 45 11.
  • Page 5: Introduction

    Chapter 1. Introduction This tutorial explains how to configure and run the Red Hat Application Server server. In addition, it explains how to run the examples provided in the Red Hat Application Server distribution. It is assumed that a JDK is already installed. For installation details, refer to the Red Hat Application Server Installation Guide.
  • Page 6 Chapter 1. Introduction Web server. The Web server is responsible for accepting client requests and sending HTML replies back to the client. HTML pages can be static files that reside on the Web server filesystem or dynam- ically built with Servlets or JSPs from data generated by the beans. Servlet/JSP server.
  • Page 7: Jonas Features

    Chapter 1. Introduction Jeremie: the RMI personality of an Object Request Broker called Jonathan, which also provides • a CORBA (Common Object Request Broker Architecture) personality. Jeremie allows JOnAS to benefit from the optimization of local RMI calls. RMI/IIOP: JOnAS now provides support for both RMI/IIOP (Java Remote Method Invocation over •...
  • Page 8: Software Requirements

    Chapter 1. Introduction JDBC Service: JDBC 2.0 support including XA (Distributed transaction mode for JDBC 2.0) re- • sources and connection pooling. Security Service: This service implements the authorization mechanisms for accessing EJB com- • ponents, as specified in the EJB specification. EJB security is based on the notion of roles. Transaction Service: This is a Java Transaction Monitor called JOnAS JTM, which ensures the •...
  • Page 9: Quick Start

    Chapter 2. Quick Start This chapter will help you set up Red Hat Application Server and run your first EJB application. If you do not understand all the steps, you should read the next two chapters to familiarize yourself with the details of setting up Red Hat Application Server.
  • Page 10: Building The Examples

    Chapter 2. Quick Start 2.2.1. Building the Examples The simplest way to compile all examples is to start in the directory $JONAS_ROOT/examples/src and enter the following command line as user jonas ant -find build.xml install This command compiles all examples in the directory.
  • Page 11 Chapter 2. Quick Start Figure 2-2. JOnAS Administration Login Log in with User Name and Password jonas jonas Figure 2-3. JOnAS Administration Web Interface b. Click Deployments > EJB Modules (JAR).
  • Page 12 Chapter 2. Quick Start Figure 2-4. Deploy the sb.jar Example c. On the in the Deployable list box on the left side, Click Deploy, then click sb.jar Apply. d. A Confirm dialog appears; click Confirm. Figure 2-5. Confirm the sb.jar Deployment e.
  • Page 13 Chapter 2. Quick Start Figure 2-6. Results of the sb.jar Deployment f. If you click Deployments > EJB Modules (JAR) again, will appear in the sb.jar right list box, which lists the deployed files. 3. Start the Java Client: jclient sb.ClientOp A successful run should output: Create a bean Start a first transaction...
  • Page 14 Chapter 2. Quick Start...
  • Page 15: Configuring Your Environment

    Chapter 3. Configuring Your Environment In this chapter, we will put all the pieces together that are required to configure a complete J2EE platform. Note that you can find a more detailed description in the documentation provided with each software component. 3.1.
  • Page 16 Chapter 3. Configuring Your Environment 3.1.2. Configuring Your JOnAS Environment You have to set up the environment variable prior to using JOnAS or any of its tools. JONAS_ROOT You also have to update your PATH Assuming that you installed JOnAS in the directory, enter the following com- /usr/share/jonas mands:...
  • Page 17: Getting Started With Jonas

    Chapter 4. Getting Started With JOnAS This chapter will help you to understand the various JOnAS components as well as how to start and manage a JOnAS server. 4.1. Overview of the Tools JOnAS comes with a set of tools that are briefly described below. starts the JOnAS server.
  • Page 18 Chapter 4. Getting Started With JOnAS 4.1.2. JOnAS Configuration Files This section is a guide for the JOnAS configuration files. If you need more in-depth information, check the JOnAS Configuration chapter of the Red Hat Application Server User Guide. The JOnAS distribution contains configuration files that reside in the directory: $JONAS_ROOT/conf is used to configure the JOnAS server and the different services that it may...
  • Page 19 Chapter 4. Getting Started With JOnAS # list of services for JOnAS as a EJB server jonas.services registry,jmx,jtm,dbm,security,jms,resource,ejb,web,ear ###################### JOnAS Registry service configuration Set the name of the implementation class of the Registry service jonas.service.registry.class org.objectweb.jonas.registry.RegistryServiceImpl Set the Registry launching mode If set to ’automatic’, the registry is launched in the same JVM as the Application Server, if it’s not already started.
  • Page 20 Chapter 4. Getting Started With JOnAS Set the maximun size of the thread pool used for message driven beans jonas.service.ejb.mdbmaxthreadpoolsize 25 ###################### JOnAS Web container service configuration Set the name of the implementation class of the web container service. jonas.service.web.class org.objectweb.jonas.web.catalina41.CatalinaJWebContainerServiceImpl #jonas.service.web.class org.objectweb.jonas.web.jetty.JettyJWebContainerServiceImpl...
  • Page 21 Chapter 4. Getting Started With JOnAS jonas.service.ws.file1.class org.objectweb.jonas.ws.handler.FileWSDLHandler jonas.service.ws.file1.params location # Where WSDLs will be published ? jonas.service.ws.file1.location /tmp # Set the Generator to use with wsgen jonas.wsgen.generator.class org.objectweb.jonas_ws.wsgen.axis.AxisConfigGenerator ###################### JOnAS EAR service configuration Set the name of the implementation class of the ear service. jonas.service.ear.class org.objectweb.jonas.ear.EarServiceImpl Set the list of directories that contains ears that must...
  • Page 22 Chapter 4. Getting Started With JOnAS Ex: MailSession1,MailMimePartDS1 (while the properties file names are MailSession1.properties and MailMimePartDS1.properties) jonas.service.mail.factories ###################### JOnAS JTM Transaction service configuration Set the name of the implementation class of the jtm service jonas.service.jtm.class org.objectweb.jonas.jtm.TransactionServiceImpl Set the Transaction Manager launching mode. If set to ’true’, TM is remote: TM must be already launched in another JVM.
  • Page 23 Chapter 4. Getting Started With JOnAS ###################### JOnAS J2CA resource service configuration Set the name of the implementation class of the J2CA resource service jonas.service.resource.class org.objectweb.jonas.resource.ResourceServiceImpl Set the list of directories that contains rars that must be deployed by the JOnAS Server at launch time. Give a comma-separated list of directories.
  • Page 24: Database Access

    Chapter 4. Getting Started With JOnAS # Groupname for Javagroups. No need to change if not known. carol.cmi.multicast.groupname=G1 # Factor used for this server in wheighted round robin algorithms carol.cmi.rr.factor=100 # If enabled, cluster stubs will print messages on some error cases carol.cmi.stub.debug=false # If true, local call with jrmp are optimized.
  • Page 25: Loading Beans Using Jonas.properties

    Chapter 4. Getting Started With JOnAS a line such as in your jonas.service.dbm.datasources postgresql jonas.properties file. 4.1.4. Loading Beans Using jonas.properties You can statically define the beans you want to load at JOnAS startup by updating the file. Here are some examples: jonas.properties If you want to load the beans defined in a single file, and not packaged in an ejb-jar...
  • Page 26: Unloading Beans

    Chapter 4. Getting Started With JOnAS You can find a complete description of JOnAS in the JOnAS Command Reference section of Admin the Red Hat Application Server User Guide. 4.1.7. Unloading Beans Beans can be unloaded either by stopping JOnAS or using the command line .
  • Page 27: Session Beans

    Chapter 5. Session Beans The JOnAS distribution comes with several example applications. In the following example, we will use a java client that accesses a Stateful Session bean and invokes the method of the bean trans- action twice. 5.1. Finding the Example Application The Session Bean example application is located in the directory.
  • Page 28: Understanding Session Beans

    Chapter 5. Session Beans 1. As , start the Red Hat Application Server server with the following command: root /sbin/service jonas start 2. Start the Java Client: jclient sb.ClientOp A successful run should output: Create a bean Start a first transaction First request on the new bean Second request on the bean Commit the transaction...
  • Page 29 Chapter 5. Session Beans env-entry-type java.lang.String /env-entry-type £ £ ¤ ¤ env-entry-value prop1 value /env-entry-value £ £ ¤ ¤ /env-entry £ ¤ /session £ ¤ /enterprise-beans £ ¤ assembly-descriptor £ ¤ container-transaction £ ¤ method £ ¤ ejb-name /ejb-name £ £...
  • Page 30 Chapter 5. Session Beans...
  • Page 31: Entity Beans

    Chapter 6. Entity Beans In this example, two beans share the same interface (Account), one uses bean-managed persistence (explicit persistence), the other uses container-managed persistence (implicit persistence). This is a good example of the two persistence techniques. 6.1. Finding the Example Application The Entity Bean example application is located in the directory.
  • Page 32: Building The Example

    Chapter 6. Entity Beans 6.1.2. Building the Example The simplest way to compile this and all examples is to go to the $JONAS_ROOT/examples/src directory and enter the following command line as user jonas ant -find build.xml install This command compiles all examples in the directory.
  • Page 33: Running The Eb Example

    Chapter 6. Entity Beans 6.1.4. Running the EB Example To do a complete and clean run of this example, you will have to first start the JOnAS server and then run the two Java clients. At the end of the execution, you may stop the JOnAS server. Note The following example assumes that the current directory is $JONAS_ROOT/examples/src/eb...
  • Page 34 Chapter 6. Entity Beans...
  • Page 35: Message-Driven Beans

    Chapter 7. Message-Driven Beans Two message-driven beans examples are provided with JOnAS. The first and simplest is located in ; it contains a Message Driven bean listening to a $JONAS_ROOT/examples/src/mdb/samplemdb topic and an MdbClient, which is a pure JMS Client that sends 10 messages on the corresponding topic.
  • Page 36: Understanding Message-Driven Beans

    Chapter 7. Message-Driven Beans Note can also be deployed using the web interface. The steps are similar to those described in Section 2.2.2 Quick Start to the SB Example, but using the file samplemdb.jar To run the example, you will have to first start the JOnAS server and then run the Java sampleappli client.
  • Page 37 Chapter 7. Message-Driven Beans • run.bat contains the message driven bean. • MdbBean.java contains the Client that accesses the Mdb bean. • MdbClient.java is the JOnAS specific part of the deployment descriptor. • jonas-samplemdb.xml contains the generic deployment descriptor. • samplemdb.xml directory contains the following files: $JONAS_ROOT/examples/src/mdb/sampleappli...
  • Page 38 Chapter 7. Message-Driven Beans...
  • Page 39: Accessing Beans From A Servlet

    Chapter 8. Accessing Beans From a Servlet 8.1. Quick Introduction to Servlets According to Java Servlet Programming, 2nd Edition—O’Reilly A servlet is a generic server extension—a Java class that can be loaded dynamically to expand the func- tionality of a server. Servlets are commonly used with web servers, where they can take the place of CGI scripts.
  • Page 40 Chapter 8. Accessing Beans From a Servlet "-//w3c//dtd html 4.0 transitional//en" "); § out.println(" html "); ¨ § out.println(" body "); ¨ § out.println("RegionServlet - Looking for the initial context ") ¨ § Context initialContext = null; initialContext = new InitialContext(); catch (Exception e) out.println("RegionServlet - Cannot get initial context for JNDI: "...
  • Page 41: Initiating A Transaction From A Servlet

    Chapter 8. Accessing Beans From a Servlet 8.3. Initiating a Transaction From a Servlet It is better to initiate the transactions from the beans, however in some cases you want the transaction to be initiated from the servlet. In this case, proceed as follows: Context initialContext = new InitialContext();...
  • Page 42 Chapter 8. Accessing Beans From a Servlet...
  • Page 43: Accessing Beans From A Jsp

    Chapter 9. Accessing Beans From a JSP directory contains JSP samples for the $JONAS_ROOT/examples/alarm/web/secured/ Alarm application. JavaServer Pages (JSP) was Sun’s reponse to Microsoft ASP. It looks like a scripting language that basically combines standard HTML and scripting tags. On its first invocation, a JSP is tranlated into a Java servlet.
  • Page 44 Chapter 9. Accessing Beans From a JSP...
  • Page 45: The Alarm Application

    Chapter 10. The Alarm Application Alarm is a simple J2EE application developed on top of JOnAS. This application is delivered with the JOnAS distribution and resides in the directory. This example $JONAS_ROOT/examples/alarm illustrates how to use JOnAS, Tomcat, and Joram together to create a complete application using EJBs, servlets, html, JSPs, and message driven beans.
  • Page 46: Finding The Alarm Application

    Chapter 10. The Alarm Application Figure 10-1. Alarm application architecture overview 10.2. Finding the Alarm Application The Alarm application is located in the directory. It is structured $JONAS_ROOT/examples/alarm as follows: : application description. • etc/web.xml directory: JSPs, images, html files. •...
  • Page 47: Configuring Database Access

    Chapter 10. The Alarm Application Note Make sure that the file is in the directory. bcel.jar $ANT_HOME/lib 10.4. Configuring Database Access You must have configured a Database. The jndi name used in the bean is . See Section 4.1.3 jdbc_1 Database Access in this tutorial or the Configuring Database Service section of the Red Hat Applica- tion Server User Guide.
  • Page 48 Chapter 10. The Alarm Application Figure 10-2. Deploy the alarm.ear Example b. On the in the Deployable list box on the left side, Click Deploy, then click alarm.ear Apply. c. A Confirm dialog appears; click Confirm. Figure 10-3. Confirm the alarm.ear Deployment d.
  • Page 49: Known Bugs Or Limitations

    Chapter 10. The Alarm Application Figure 10-4. Results of the alarm.ear Deployment e. If you click Deployments > Applications (EAR) again, will appear in the alarm.ear right list box, which lists the deployed files. If you click Application Container, EJB container, or Web Container under Services, you will see in the tree.
  • Page 50 Chapter 10. The Alarm Application...
  • Page 51: Documentation

    Chapter 11. Documentation This chapter describes additional sources of information about Red Hat Application Server. 11.1. Documentation For more information about JOnAS, please read the documentation that comes with the Red Hat Application Server distribution. Note that the latest release JOnAS documentation can always be found online. 11.1.1.
  • Page 52: Jonas Team Mailing List

    Chapter 11. Documentation The traffic of this mailing list is moderate. Don’t hesitate to register in order to be informed of the latest JOnAS news. To do this, simply send a blank e-mail to: jonas-subscribe@objectweb.org. You can also use the online Sympa interface (Sympa is the mailing list software management used by ObjectWeb).
  • Page 53: Glossary

    Glossary Ant, from Apache, is a Java-based build tool (see http://ant.apache.org/). BCEL (Byte Code Engineering Library) The BCEL package, from Apache, is required for correct operation of the Ant build scripts used by JOnAS. BCEL gives users a convenient way to analyze, create, and manipulate (binary) Java files.
  • Page 54 Glossary defined Enterprise JavaBeans specification (see http://java.sun.com/products/ejb/2.0.html). CORBA (Common Object Request Broker Architecture) CORBA is Object Management Group’s open, vendor-independent architecture and infrastruc- ture that computer applications use to work together over networks. Using the standard protocol IIOP, a CORBA-based program can interoperate with any other CORBA-based program. See http://www.omg.org/gettingstarted/corbafaq.htm.
  • Page 55 Glossary JAAS (Java Authentication and Authorization Service) JAAS is a set of APIs that enable services to authenticate and enforce user-based authorization. JACC (Java Authorization Contract for Containers ) JOnAS implements the Java Authorization Contract for Containers (JACC 1.0) specification. This enables you to manage authorizations as Java security permissions, and to plug in any secu- rity policy provider.
  • Page 56 Glossary JNDI (Java Naming and Directory Interface) JNDI provides Java applications with a unified interface to naming and directory services. See http://java.sun.com/products/jndi. JOnAS JOnAS (Java Open Application Server) is a distributed platform compliant with the EJB spec- ifications (see http://www.objectweb.org/jonas/index.html). JOnAS provides object distribution, security, distributed transactions, and object-persistence support according to these specifica- tions.
  • Page 57 Glossary JVM (Java Virtual Machine) A JVM is a kind of translator that turns general Java platform instructions into tailored commands for devices. MOM (Message Oriented Middleware) MOM is a specific class of middleware that supports the exchange of general-purpose messages in a distributed application environment.
  • Page 58 Glossary Tomcat A Web Container Service is a servlet/JSP engine in the JVM of the Red Hat Application Server server and the loading of web applications (“WAR files”) within this engine. Currently this ser- vice can be configured to use Tomcat or Jetty, although only Tomcat is supplied with Red Hat Application Server.
  • Page 59: Index

    Index EJB Container Service JOnAS service, 3 Enterprise JavaBeans overview, 1 Entity Beans Alarm example application, 27 architecture overview, 41 Entity Beans example configuring database access, 43 building, 28 example application, 41 configuring database access, 28 finding, 42 creating the database, 28 limitations, 45 defining a datasource, 28 running, 43...
  • Page 60 overview, 2 OrderBean.java overview, 3 message driven bean, 33 JmsServer starts the JMS server, 13 overview, 3 JNDI RAConfig overview, 3 Resource Adapter deployment tool, 13 JOnAS Red Hat Application Server environment configuration files, 14 setting up, 5 configuring, 12 registry starting, 13 starts the JNDI, 13...
  • Page 61 stock bean’s home interface, 33 Transaction Service JOnAS service, 4 Web Container Service JOnAS service, 3 web server overview, 1...

This manual is also suitable for:

Application server

Table of Contents