You need to do the tutorials in this book in the order shown by the Tutorials Map.
In this chapter, you generate an EJB and JSP client for the interface you mapped in the earlier tutorials. You then deploy the EJB and client to a J2EE application server. You also deploy a J2EE resource adapter.
An EJB running a COBOL service runs in two places: the COBOL service runs under an enterprise server, and the EJB and client run under a third party J2EE application server, such as WebSphere or WebLogic. In the chapter Deploying a Service you deployed the COBOL service. In this chapter, you generate the EJB and its client, deploy them, and then run the JSP client.
In this tutorial, you:
When you run the JSP client, it takes a request from the end user and passes it to the EJB you generated. The EJB in turn passes the request to the enterprise server, ESDEMO. The original COBOL program runs on the enterprise server and processes the request, returning the results back to the JSP.
Two enterprise archive files are supplied: JMapServ-WL.ear for WebLogic and JMapServ-WS.ear for WebSphere. Each file contains the generated EJB and client and also the necessary deployment descriptors for WebLogic and WebSphere respectively. You can deploy these .ear files to the relevant application server without generating the EJB and client yourself.
You need to install and configure one of the following third-party J2EE application servers: BEA WebLogic and IBM WebSphere. We give instructions specific to WebLogic 8.1 and WebSphere 5.0 Advanced Edition, which use the J2EE 1.3 specification. If you have another supported version of WebLogic or WebSphere there will be minor differences, but it will work in essentially the same way.
You also need a Java Development Kit (JDK) 1.3.x (or higher) installed. We recommend that you use the JDK supplied with your J2EE application server. Make sure that your PATH environment variable points to the bin directory of the correct JDK. You set the PATH using a command such as:
set path=jdk-installation\bin;%path%
If Net Express, the project Mapdemo, and the Service Interfaces window aren't open, open them now - to open the Service Interfaces window, click File > Open Service Interfaces, then select mapdemo.mpr from Examples\Net Express IDE\Mapdemo and click Open.
Make sure the ESDEMO enterprise server is started and the JMapServ service is deployed in it, as described in the chapter Deploying a Service.
To generate the EJB and its client:
This creates both the EJB and the JSP client and packages them into the file JMapServ.ear. The Output window shows progress on the Java compilation.
When you generate the client and the EJB, the files are generated in the directory structure under Examples\Net Express IDE\mapdemo\mapdemo\repos\JMapServ.deploy.
The files are packaged into the following archive files:
This .ear file contains everything to deploy the EJB.
You can view the contents of these archive files using the jar command or a zip utility such as Winzip. For more information see the section Jar, War and Ear Files Generated in the chapter Mapping a Java Interface and Using Resource Adapters in your Java and COBOL book.
WebLogic comes with a Server Console, which you use to deploy EJB and resource adapters. Instructions on how to use the console are available online from the console. You use the console by navigating the tree in the left-hand pane and clicking an item on the left to display the required page on the right.
Setting up WebLogic involves setting up a domain to hold the EJBs and resource adapters being deployed, and also setting up the environment for WebLogic to run.
Set up and start WebLogic Server as follows:
Details required | Details that you select or supply |
---|---|
Domain template name | WLS domain |
Domain name | MicroFocus |
Server type | Single Server (Standalone Server) |
Server name | MFserver |
Install directory | bea_installation\user_projects |
Listen address | You can leave this blank, and it is then populated with localhost |
Listen port | 7001 |
SSL listen port | 7002 |
Windows service | yes |
Windows start menu | yes |
Username | Create a username here |
Password | Create a password here |
set MF_HOME=NetExpress\base\bin set JAVA_HOME=bea-jdk set classpath=%JAVA_HOME%\lib\tools.jar; %MF_HOME%\jar_path\mfconnector.jar; %MF_HOME%\mfcobolpure.jar
where:
To deploy the resource adapter, go to the WebLogic Server Console and then:
You do not need to create a connection factory or specify the JNDI name of the resource adapter, because these are already specified in the deployment descriptor for the connection factory. Here are the relevant lines from that deployment descriptor, weblogic-ra.xml:
<connection-factory-name> CCIMFCobol_v1.0 </connection-factory-name> <jndi-name> eis/MFCobol_v1.0 </jndi-name>
If you want to view weblogic-ra.xml, find mfcobol-notx.rar in the location given above and extract weblogic-ra.xml from it.
To deploy your EJB:
When prompted for: | Do this: |
---|---|
Path to the .ear file |
Specify mapdemo\repos\JMapServ.deploy\JMapServ.ear within your mapdemo directory |
Target server | Enter MFserver |
You do not need to specify the JNDI name of the EJB or map the JNDI name of the resource adapter, because these are already specified in the deployment descriptors. Here are the relevant lines from those deployment descriptors, weblogic-ejb-jar.xml and weblogic.xml :
<resource-description> <res-ref-name>CCIMFCobol_v1.0</res-ref-name> <jndi-name>eis/MFCobol_v1.0</jndi-name> </resource-description> ... <jndi-name>ejb/JMapServEJB</jndi-name>
If you want to view weblogic-ra.xml, find JMapServ.ear in the location given above, extract JMapServ.jar and then extract weblogic-ra.xml from it.
When you have changed the modules deployed on the server, the BEA WebLogic documentation recommends stopping and restarting the server. To do this:
The WebLogic Server Console will not be available until you restart the server.
Note: If you reboot your machine, you need to restart the WebLogic server. You must start the WebLogic server from the Start menu. You cannot start it using Services in the Windows Control Panel and you cannot configure it in the Control Panel to start automatically when you reboot the machine.
WebSphere comes with an Administrative Console, which you use to deploy EJBs and resource adapters. The console takes you step by step through deployment and provides full information online on how to do this. You use the console by navigating the tree in the left-hand pane and clicking an item on the left to display the required page on the right.
Start WebSphere Server and the Administrative Console as follows:
websphere_installation\bin\startServer
To deploy the resource adapter, go to the WebSphere Administrative Console and then:
When prompted for: | Do this: |
---|---|
Path to the resource adapter | Specify Net Express\Base\Bin\mfcobol-notx.rar |
Name of the resource adapter | Enter any name you want, such as Micro Focus resource adapter |
To deploy your EJB:
When prompted for: | Do this: |
---|---|
Path to the .ear file | Specify mapdemo\repos\JMapServ.deploy\JMapServ.ear within your mapdemo directory |
Application name | Enter any name, such as My MapDemo EJB |
Precompile JSPs | Don't check this |
Deploy EJBs | Check this |
Map modules to application servers | Check both modules |
When you have changed the modules deployed on the server, the IBM WebSphere documentation recommends stopping and restarting the server.
To do this, go the WebSphere Administrative Console and then:
websphere_installation\bin\stopServer
The client JSP and its servlet are generated in the directory structure under Examples\Net Express IDE\mapdemo\mapdemo\repos\JMapServ.deploy\Client .
The files include:
To see how the EJB is invoked from the servlet, look at the file JMapServServlet.java, which is in the directory JMapServ.deploy\Client\WEB-INF\com\mypackage\JMapServ. Open the file in your Java development tool or a text editor, and examine the following lines:
InitialContext initCtx = new InitialContext(); Object objRef = initCtx.lookup("java:comp/env/ejb/JMapServEJB"); hi = (com.mypackage.JMapServ.JMapServHome) javax.rmi.PortableRemoteObject.narrow( objRef, com.mypackage.JMapServ.JMapServHome.class);
These lines look up the EJB in JNDI when the EJB is first needed.
ri = hi.create(); JMapServSessionMonitor.setClientRequest(session, ri);
These lines create an instance of the EJB and start a session for handling the request.
ri = JMapServSessionMonitor.getClientRequest(session)
This line gets the EJB on subsequent occurrences.
The demonstration application uses a simple book database file . Recall from the chapter Creating a Service that the file as supplied contains records 1111 and 2222, and you might have added a record yourself, number 4444, if you used the example data suggested in that chapter.
To run the JSP:
For WebSphere, enter the URL http://localhost:9080/JMapServ/JMapServMain.jsp.
After a few moments, the client displays the name and content of each field in the requested record. This demonstrates a request being passed by your EJB interface, through the resource adapter, to an enterprise server, and demonstrates the COBOL service, BOOK.Read, handling the request, looking up the record in the file and sending a response back to the JSP.
To see how to debug this service, continue at the chapter Debugging a Service.
If you want to take a break first, you can close your development system or just the project.
Copyright © 2006 Micro Focus (IP) Ltd. All rights reserved.