1. Trang chủ
  2. » Công Nghệ Thông Tin

WebSphere Studio Application Developer Version 5 Programming Guide part 65 ppsx

10 180 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

614 WebSphere Studio Application Developer Version 5 Programming Guide Building an application client module Our application client module (ItsoProGuideJavaClient) contains one program, CustomerListingDS. This program is basically a copy of the CustomerListing program developed in Chapter 5, “Developing Java applications” (see source listing in Figure 5-10 on page 102). The difference in the application client module is that we use a data source to connect to the database: protected static Connection connect() { Connection con = null; try { javax.naming.InitialContext ctx = new javax.naming.InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/mybank"); con = ds.getConnection(); } catch (javax.naming.NamingException e) { System.err.println("Naming-Exception: " + e.getMessage()); } catch (java.sql.SQLException e) { System.err.println("SQL-Exception: " + e.getMessage()); } return con; } Here are some short instructions on how we built the application client module:  Create a new project of type J2EE -> Application Client Project. Enter a name of ItsoProGuideJavaClient and use the existing ItsoProGuide enterprise application.  Create the class itso.javadb.CustomerListingDS and use the source in: \sg246957\sampcode\deploy-app\client\CustomerListingDS  Open the deployment descriptor and on the References page define a resource environment reference named java:comp/env/jdbc/mybank, pointing to our jdbc/ejbbank data source (as shown in Figure 18-5).  Define the CustomerListingDS program as the main application of the module (Figure 18-6). Click Edit to locate the main class. Note: You have to use a resource environment reference. Defining a resource reference in Application Developer does not work when running the program. Resource references can currently only be defined using the Application Client Resource Configuration Tool (clientConfig.bat) of WebSphere Application Server outside of Application Developer to update the client deployment descriptor. Chapter 18. Deploying enterprise applications 615 Figure 18-6 Defining the main program  To test the application you have to run the program in a WebSphere application client container. Start the ItsoServer (it defines the data source), then create a launch configuration as explained in “Running your programs” on page 103. However, this time create a WebSphere v5 Application Client launch configuration (Figure 18-7). On the Classpath tab, click Advanced , then Add Variables , and select the DB2JAVA variable. Figure 18-7 Launch configuration for a J2EE application client  When you run the program, you can see the start of the client container and the binding of the JDBC reference in the Console view. The database records are displayed as the result of the program execution. DB2JAVA 616 WebSphere Studio Application Developer Version 5 Programming Guide Exporting an enterprise application After the deployment descriptors have been customized for our environment, the enterprise application can be exported to an EAR file:  In the J2EE Perspective, J2EE Hierarchy view expand Enterprise Applications and select the ItsoProGuide project. Then select Export EAR File from its context menu. The EAR Export dialog shown in Figure 18-8 is displayed. Figure 18-8 Exporting an EAR file  Enter the EAR filename to export the resources to. A possible location is the installableApps directory of the WebSphere Application Server, but you can export to anywhere in the file system.  Make sure that the three options are unchecked. Because the EAR file will be used in a production system we do not want to include the source files or the Application Developer meta-data.  Click Finish to export the EAR file. The next step is to prepare our WebSphere Application Server environment. Note: You may want to make the changes to the applications as noted in “Changing the applications to run on a remote server” on page 538 before exporting. Chapter 18. Deploying enterprise applications 617 Configuring WebSphere Application Server In this section we configure WebSphere Application Server 5.0 to install and run the sample application. This consists of the following tasks:  Configure the JDBC driver  Set up a data source  Configure a J2C authentication alias to access the database  Install the EAR file  Start the application The administrative actions are performed using the WebSphere Application Server 5.0 administrative console. Start the server and the administrative console To configure the server we use the administrative console:  Start the WebSphere Application Server 5.0 server (from the program group, from First Steps, or as a service).  Start the administrative console (from the program group or from First Steps).  Login with your normal user ID (Figure 18-9). Figure 18-9 Administrative Console Login 618 WebSphere Studio Application Developer Version 5 Programming Guide  Select Servers and Applications to expand the tree (Figure 18-10). Select Application Servers and you can see the default server (server1). Select Enterprise Applications and you can see the sample applications. Figure 18-10 Administrative Console Configuring a server (optional) With WebSphere Application Server Network Deployment we suggest to configure a separate server and not use the default server. With the base WebSphere Application Server we use the default server (server1) for our sample application. Configuring a JDBC driver and data source In this section we configure a JDBC driver for DB2 and the data source for the EJBBANK database. JDBC driver path  Select Environment (left side) and Managed WebSphere Variables .  Select DB2 JDBC DRIVER PATH .  Verify or enter the directory of the db2java.zip file (c:\SQLLIB\java).  Click OK . Chapter 18. Deploying enterprise applications 619 JDBC driver  Select Resources (left side) and select JDBC Providers .  Select Node (should be preselected)  Click New (under JDBC Providers): – Select DB2 JDBC Provider from the pull-down and click Apply . – All the defaults should be fine. Check that the implementation class is COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource. Note that the classpath entry points to ${DB2_JDBC_DRIVER_PATH}/db2java.zip (Figure 18-11). – Click Apply . Figure 18-11 Defining a JDBC provider Data source  Under Additional Properties select Data Sources . – Click New (Figure 18-12). – Enter EJBBANK as name and jdbc/ejbbank as JNDI name (to match what we defined in the EJB deployment descriptor). 620 WebSphere Studio Application Developer Version 5 Programming Guide – Select Use this Data Source in container-managed persistence (CMP) . – The data source helper class should be filled in as com.ibm.websphere.rsadapter.DB2DataStoreHelper. – Click Apply . Figure 18-12 Defining the data source for the EJBBANK database  Under Additional Properties select Custom Properties , then select databaseName , enter EJBBANK as value and click OK .  Go back to the data source (select EJBBANK at the top of the page). Under related Items select J2C Authentication Data Entries , then click New (Figure 18-13): – Enter DB2user as alias. – Enter a valid user ID and password, for example what was used to install DB2. – Click OK . – The new alias appears in the list, prefixed with the node name. Chapter 18. Deploying enterprise applications 621 Figure 18-13 Defining an authentication alias  Go back to the data source (select EJBBANK at the top of the page): – For component- and container-managed authentication alias, select the {node}/DB2user from the pull-down and click OK (Figure 18-14). Figure 18-14 Defining container authentication for the data source  If you select Security (left side) and JAAS Configuration you can find the new alias by selecting J2C Authentication Data . Save the configuration Save the configuration. There should be no problems. Note: Due to Web browser caching, the alias may not appear in the pull-down list. If this happens, refresh your Web browser by pressing F5 and then navigate to this entry again. 622 WebSphere Studio Application Developer Version 5 Programming Guide Installing an enterprise application To install an enterprise application from an EAR file:  Select Applications and Install New Application .  For the local path, click Browse and locate the EAR file that you exported from Application Developer (Figure 18-15): c:\ItsoProGuide.ear d:\WebSphere\AppServer\installableApps\ItsoProGuide.ear Click Next . Figure 18-15 Enterprise application installation  On the panel, Preparing for the application installation, all the defaults should be fine: – You do not want to overwrite existing bindings, everything was configured in Application Developer – You can choose the virtual host (instead of default_host) Click Next . Installation process steps Installation of our enterprise application is a multi-step process, in our case, 9 steps (the actual number of steps vary depending on the content and requirements of your application). Unless otherwise noted, review the options and then click Next for each step. Because we configured all the deployment information in Application Developer there is almost no need to change the options. c:\ItsoProGuide.ear Chapter 18. Deploying enterprise applications 623 1. Provide options to perform the installation (Figure 18-16): Figure 18-16 Enterprise application installation: step 1 – You may want to select Pre-compile JSP (although we set this in our Web applications it is not picked up as a default). – Do not select Deploy EJBs ; deployment code was generated in Application Developer. 2. Provide JNDI Names for Beans (Figure 18-17). All the JDNI names for our entity and sessions beans have been set. Figure 18-17 Enterprise application installation: step 2 3. Provide default data source mapping for modules containing EJB 2.0 entity beans (Figure 18-18). We configured the jdbc/ejbbank data source previously. . 614 WebSphere Studio Application Developer Version 5 Programming Guide Building an application client module Our application client module (ItsoProGuideJavaClient) contains. pressing F5 and then navigate to this entry again. 622 WebSphere Studio Application Developer Version 5 Programming Guide Installing an enterprise application To install an enterprise application. Administrative Console Login 618 WebSphere Studio Application Developer Version 5 Programming Guide  Select Servers and Applications to expand the tree (Figure 18-10). Select Application Servers and

Ngày đăng: 03/07/2014, 20:20

Xem thêm: WebSphere Studio Application Developer Version 5 Programming Guide part 65 ppsx