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...
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.
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.
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 •...
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 •...
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.
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...
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:...
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.
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.
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...
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 .
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.
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...
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.
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.
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...
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.
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...
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: "...
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...
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.
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.
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. •...
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.
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.
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.
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).
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.
Need help?
Do you have a question about the APPLICATION SERVER - JONAS and is the answer not in the manual?
Questions and answers