Chapter 6. Migrating WebSphere Application Server CE to WebSphere Application Server 199
Making necessary changes to the code
Follow these steps to make changes to the code:
1. Now you need to make a few changes to the code. You need to change code
in the following files:
com.ibm.websphere.samples.plantsbywebspherewar.Populate
OrderItemBean
Example 6-2 and Example 6-3 show the modifications that you need to make
to these files.
You also need to modify the doPopulate method of Populate.java. To use the
new method, change addImage(id, image, catalog,servletContext) to
addImage(id, image, catalog);.
Example 6-2 The addImage method of Populate.java after modification
public static void addImage(String itemID, String fileName, Catalog
catalog) throws FileNotFoundException, IOException {
URL url =
Thread.currentThread().getContextClassLoader().getResource("images/" +
fileName);
Util.debug("URL: " + url);
fileName = url.getPath();
Util.debug("Fully-qualified Filename: " + fileName);
File imgFile = new File(fileName);
// Open the input file as a stream of bytes
FileInputStream fis = new FileInputStream(imgFile);
DataInputStream dis = new DataInputStream(fis);
int dataSize = dis.available();
byte[] data = new byte[dataSize];
dis.readFully(data);
catalog.setItemImageBytes(itemID, data);
}
Example 6-3 The ejbPostCreate of OrderItemBean.java after modification
public void ejbPostCreate(Order order, String orderID, String
inventoryID,
String name, String pkginfo, float price,
float cost,
int quantity, int category, String
sellDate)
throws javax.ejb.CreateException
{
this.setOrder(order);
}
200 Migrating from WebSphere Application Server Community Edition to WebSphere Application Server
2. After saving these changes, you need to build the application. It should build
without any errors.
Mapping resource references
To map resource references, follow these steps:
1. Now you need to map the resource references to the JNDI names of the
respective resources that you deployed on the server instance:
a. Double-click the Deployment Descriptor of the Web module
PlantsByWebSphereWeb-1.1.1 to open up the page in the Deployment
Descriptor Editor as shown in Figure 6-44.
b. Select the References tab.
c. Map all the resource references to the JNDI names of the actual resources
that you have configured on the server. Perform the following steps:
i. Select the first resource reference, for example
jdbc/PlantsByWebSphere. In the JNDI name field in the WebSphere
Bindings section, add the JNDI name of the resource in the server, for
example jdbc/PlantsByWebSphere.
ii. Select the next resource reference, for example
mail/PlantsByWebSphere. In the JNDI name field in the WebSphere
Bindings section, add the JNDI name of the resource in the server, for
example mail/PlantsByWebSphere.
Chapter 6. Migrating WebSphere Application Server CE to WebSphere Application Server 201
2. After mapping the resource references, you need to map the EJB references
to the JNDI names of the EJBs or you need to give EJB links to the EJBs to
which they refer. Perform the following steps:
a. Double-click PlantsByWebSphereWeb-1.1.1 (the Deployment Descriptor
of the Web module) to open the page in the Deployment Descriptor Editor
as shown in Figure 6-44.
b. Select the References tab.
Figure 6-44 Project Explorer window
202 Migrating from WebSphere Application Server Community Edition to WebSphere Application Server
c. Map all the EJB references to the JNDI names of the actual EJBs that will
be deployed on the server. Complete the following instructions:
i. Select the first EJB reference, for example, ejb/Login, and in the JNDI
name field of the WebSphere Bindings section, enter ejb/Login, as
shown in Figure 6-45.
ii. Similarly, enter the same JNDI names for all EJBs as the resource
reference name. Remember when you assign JNDI names to the
different EJBs to give the same names.
Table 6-1 provides the names that you use. Table 6-2 shows the
resource reference to JNDI name mapping.
Table 6-1 EJB, JNDI, and EJB Ref Names mapping
Table 6-2 Resource reference to JNDI Name mappings
EJB Names JNDI Names EJB Ref Names
BackOrder ejb/BackOrder ejb/BackOrder
Customer ejb/Customer ejb/Customer
IdGenerator ejb/IdGenerator ejb/IdGenerator
Inventory ejb/Inventory ejb/Inventory
Order ejb/Order ejb/Order
OrderItem ejb/OrderItem ejb/OrderItem
Supplier ejb/Supplier ejb/Supplier
BackOrderStock ejb/BackOrderStock ejb/BackOrderStock
Catalog ejb/Catalog ejb/Catalog
Login ejb/Login ejb/Login
Mailer ejb/Mailer ejb/Mailer
ReportGenerator ejb/ReportGenerator ejb/ReportGenerator
ResetDB ejb/ResetDB ejb/ResetDB
ShoppingCart ejb/ShoppingCart ejb/ShoppingCart
Suppliers ejb/Suppliers ejb/Suppliers
Resource-Reference JNDI Name
plantsby/PlantsByWebSphereDataSource jdbc/PlantsByWebSphere
jdbc/PlantsByWebSphere jdbc/PlantsByWebSphere
mail/PlantsByWebSphere mail/PlantsByWebSphere

Get Migrating from WebSphere Application Server Community Edition to WebSphere Application Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.