[ Team LiB ] Previous Section Next Section

J2EE Connector Architecture Example

The first J2EE Connector Architecture example found under the JDBC directory on the CD uses a simple sample resource adapter from Sun Microsystems to connect to a database. The second example uses the resource adapter from SAP to connect to an SAP system and retrieve materials.

Both examples contain two JSP files, one for input and one for output, which are included in a Web application that uses an EJB to talk to the J2EE-CA adapter. The first example inserts records and sends the contents out to a screen for display. The second example enables you to query SAP for materials (if you have an SAP system available, that is). The associated instructions enable you to become familiar with deploying a resource adapter in WebLogic. You can also familiarize yourself with the configuration and look at the sample code used to connect to resource adapters.

The following is a JDBC example. You might be wondering, "Aren't there JDBC drivers for doing this?" Yes, there are, and this adapter is a demonstration of how to write one. We're using this kind of adapter because you probably don't have an EIS server running on your development computer, and it would be impossible for you to really learn about J2EE-CA without deploying one.

Setting Up the JDBC Example

To compile and run the example, a database is required. We'll use the PointBase EXAMPLES.BANDS database for our example. PointBase comes with WebLogic Server 8.1, but it has to be started. The command to start PointBase is


<weblogic home dir>\common\eval\pointbase\tools\startPointBase.cmd

This command should be placed in your startup script for WebLogic Server.

After the database has been installed, download the source directory into the temporary directory of your choice. In the source directory are three directories and two XML files: application.xml and build.xml. Each directory contains a separate component, as listed here:

  • EJB— This directory contains all the files required to build the EJB that calls the resource adapter. It is called by the JSPs in the Web application.

  • jca— This directory contains the J2EE-CA adapter that we'll use to connect to the PointBase database.

  • root— This directory contains the Web application.

  • application.xml— The file for deployment of the .ear file.

The build.xml file is an Ant script that builds and packages the entire application. This file needs the location of the weblogic.jar file to compile the EJB. This is set up in the weblogicjar property at the beginning of the file. Also, make sure the bin directory of your JDK is in your PATH for compilation.

To deploy the application, start the WebLogic console. The default location is http://localhost:7001/console. Go to the correct server on the domain and deploy the application EAR file as shown in Figure 31.7.

Figure 31.7. WebLogic console application deployment.

graphics/31fig07.jpg

After the application has been deployed, create a credential mapping for the J2EE-CA to log in to the database. This is done by simply right-clicking on the gamsJCA.rar tree node on the left interface. Choose the last selection labeled Define Credential Mappings as shown in Figure 31.8.

Figure 31.8. WebLogic resource adapter credential mapping screen.

graphics/31fig08.jpg

Once you're inside, define a default credential mapping for the local user (weblogic_ra_default) and the remote user (pbpublic with the password pbpublic). After these have been defined, you can run the application to insert bands into a database and display all the bands in that database as shown in Figures 31.9 (the input screen) and 31.10 (the output screen).

Figure 31.9. Band input screen.

graphics/31fig09.gif

Figure 31.10. Band output screen.

graphics/31fig10.gif

Setting Up the SAP Example

The second example requires SAP system access and the ability to obtain the SAP resource adapter and the SAP Java Connector (JCo) version 2.0 or greater. The resource adapter and Java Connector are free for all of SAP's partners and customers. They are available from a secured SAP site at http://service.sap.com/connectors. After obtaining the resource adapter, it must be configured for use with WebLogic and your SAP system. The following steps must be followed:

  1. Un-jar the sapjra.rar file into a temporary staging directory.

  2. Modify the ra.xml file located in the META-INF directory with the appropriate login configuration. The login configuration settings are contained in the <config-property> tags. Each has a name type and a value associated with it. If you don't have this information, ask a basis person at your company to help you. The values must be filled out with your SAP system information as follows:

    • SAPClient— The number of the SAP client that you're connecting to

    • UserName— The background SAP username needed for the connection

    • Password— The password of the background SAP username

    • Language— The language you're connecting with; for example, EN

    • ServerName— The name or the IP address of the SAP server

    • PortNumber— The system number of your SAP system; for example, 00

  3. Follow the directions to install JCo on your system. Then move the sapjco.jar file into the staging directory root with the sapjra.jar file. For help, see Chapter 32, "Using SAP's Java Connector with WebLogic Server."

  4. Create a .rar file by issuing the following command with the Java jar utility:

    
    
    jar -cf saprar.rar *
    
  5. After the .rar file has been created, import it into WebLogic using the console. To do this, simply log in to the console and click on Connector Modules, which is listed under the Deployments tab on the left side of the screen. Figure 31.11 shows what this should like.

    Figure 31.11. Deploying a standalone connector.

    graphics/31fig11.jpg

  6. Copy the contents of the SAP directory on the CD to a staging directory on your hard drive.

  7. Move the sapjca.jar file from the staging directory you set up for the .rar file into the SAP staging directory you just created.

  8. Build the application .ear file for the SAP application. The SAP directory on the CD contains an Ant script called build.xml for this task. You must configure two properties for this script:

    • weblogicjar— Corresponds to the location of the weblogic.jar file

    • sapjcajar— Corresponds to the location of the sapjca.jar file contained in the staging directory you set up

    The build script will build an application file called JCASAPSample.ear that will be contained in the staging directory (this is a temporary directory created by the Ant script).

  9. Deploy this application using the WebLogic console and then run the application to query materials by entering in this address in your Web browser: http:localhost:7001/SAPMaterials. Doing so brings up a screen that looks like Figure 31.12.

    Figure 31.12. Sample SAP application search screen.

    graphics/31fig12.gif

    On this screen, enter any search criterion for materials in your SAP system, or enter * to get a full list. (The list will be truncated to 100 materials for performance reasons.) After you click the search button, a screen similar to the one shown in Figure 31.13 is displayed.

    Figure 31.13. Sample SAP application display screen.

    graphics/31fig13.gif

    [ Team LiB ] Previous Section Next Section