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);
}