Tutorials > Program model > Create new business logic

< Previous | Next >


Deploy the bonus points logic

This step describes how to deploy the new business logic into a store running on a remote WebSphere Commerce Server. You must have created a store, based upon the consumer direct sample store, on the remote WebSphere Commerce Server before starting these deployment steps.

There are three general types of assets that must be deployed to the target WebSphere Commerce Server:

The following steps will overwrite any existing WebSphereCommerceServerExtensionsLogic.jar and WebSphereCommerceServerExtensionsData.jar files on the target WebSphere Commerce Server. Before proceeding, ensure all previous customizations made to these files on the remote WebSphere Commerce Server are included in the files that you export from Rational Application Developer.


Create the command and data bean JAR file

This section describes how to create the JAR file that contains the controller command, task command, and data bean logic.

To create this JAR file, perform the following steps on the development machine:


Procedure

  1. Create a directory on the local file system called drive:\ExportTemp.

  2. In Rational Application Developer, switch to the Enterprise Explorer view.

  3. Navigate to WebSphereCommerceServerExtensionsLogic

  4. From the WebSphereCommerceServerExtensionsLogic project's pop-up menu, select Export.

  5. In the Export wizard:

    1. Select Java > JAR file and click Next.

    2. The project WebSphereCommerceServerExtensionsLogic is selected by default. Leave this value.

    3. In the right pane, ensure that resources that begin with a period are not selected. For example:

      • .classpath

      • .project

      • .serverPreference

      • .classpath.template

      • .runtime

    4. Ensure that Export generated class files and resources is selected.

    5. Do not select Export Java source files and resources.

    6. In the Select the export destination field, enter the fully-qualified JAR file name to use. In this case, enter drive:\ExportTemp\WebSphereCommerceServerExtensionsLogic.jar.

    7. Click Finish.

  6. Create the EJB JAR file:

    1. In the Enterprise Explorer view, expand the WebSphereCommerceServerExtensionsData project.

    2. Double-click the Deployment Descriptor to open the Deployment Descriptor editor.

    3. With the Overview tab selected, scroll to the bottom of the pane, to locate the JNDI - CMP Connection Factory Binding section.

    4. In the JNDI name field, enter the datasource JNDI name of the target WebSphere Commerce Server. For example:

      • jdbc/WebSphere Commerce DB2 DataSource myInstance where the target WebSphere Commerce Server is using a DB2 or DB2/400 database, and the WCS instance name is myInstance

      • jdbc/WebSphere Commerce Oracle DataSource myInstance where the target WebSphere Commerce Server is using an Oracle database, and the WCS instance name is myInstance.

      Tip: The value for the DataSource JNDI name field is created by adding "jdbc/" to the data source name of the target WebSphere Commerce Server. You can verify the data source name by opening the WebSphere Commerce configuration file on the target WebSphere Commerce Server and searching for DatasourceName= in the file.

      If you specify a different data source for the custom enterprise beans than that used by the WebSphere Commerce enterprise beans, a two-phase commit will be required. Therefore, if the custom enterprise beans use the same database as the WebSphere Commerce enterprise beans, use the same data source name to avoid a two-phase commit. In general, using two-phase commit JDBC drivers with WebSphere Commerce is not recommended.

    5. Save the deployment descriptor changes.

    6. In the Enterprise Explorer view, from the WebSphereCommerceServerExtensionsData project's pop-up menu, select Export > EJB JAR file.

    7. In the Export wizard:

      1. The value for EJB project is pre-populated with the name of the EJB project. Leave this value.

      2. In the Destination field, enter the fully-qualified JAR file name to use. In this case, enter drive:\ExportTemp\WebSphereCommerceServerExtensionsData.jar.

      3. Select Optimized for a specific server runtime and select was.base.v7

      4. Click Finish.

    8. After the JAR file has been created, undo the changes to the local deployment descriptor that were made in 6.d step, to restore the setting that is required for the local test server.

  7. Export store assets.

    Store assets include the JSP pages and properties files that display in the store. WebSphere Application Server expects the files to be in a directory structure that matches the target file structure. In this step, after you export the files from Rational Application Developer we will modify the file structure to match the file structure on the target machine.

    1. In the Enterprise Explorer view, navigate to the Stores folder.

    2. Right-click the Stores folder and select Export > Export.

    3. In the Export wizard:

      1. Select General > File System and click Next.

      2. Click Deselect All.

      3. Select the following assets:

        • Stores\WebContent\WEB-INF\classes\ConsumerDirect_name\TutorialNLS_en_US.properties

        • Stores\WebContent\WEB-INF\classes\ConsumerDirect_name\TutorialNLS.properties

        • Stores\WebContent\ConsumerDirect_name\MyNewJSPTemplate.jsp

      4. In the To directory field, enter a temporary directory, for example drive:\ExportTemp.

      5. Ensure the Create directory structure for files option is selected.

      6. Click Finish.

    4. In the file system, navigate to the temporary directory, for example drive:\ExportTemp.

    5. Rename the Stores directory to Stores.war.

    6. Navigate to the Stores.war\WebContent directory.

    7. Move the ConsumerDirect_name and WEB-INF directories and their contents under the Stores.war directory.

    8. Delete the now empty WebContent directory. The resulting file structure should look like the following:

      • Stores.war\WEB-INF\classes\ConsumerDirect_name\TutorialNLS_en_US.properties

      • Stores.war\WEB-INF\classes\ConsumerDirect_name\TutorialNLS.properties

      • Stores.war\ConsumerDirect_name\MyNewJSPTemplate.jsp

    9. If applicable, rename all the ConsumerDirect_name folders to match the name of the consumer direct sample store on your target machine.

  8. Update the struts-config-ext.xml file on the target WebSphere Commerce Server

    The struts-config-ext.xml file is updated every time you publish a store. Although it is possible to export the struts-config-ext.xml file from the development machine and deploy it to the target WebSphere Commerce Server, problems may arise when the store ids on the development machine do not exactly match the store ids on the target machine.

    To avoid this mismatch, the following steps update the struts-config-ext.xml file on the target WebSphere Commerce Server instead of deploying the development version.

    To update the struts-config-ext.xml file on the target server:

    1. On the target server, navigate to WC_eardi../images/locale/screensnap/Stores.war/WEB-INF

    2. Place a copy of the struts-config-ext.xml file in the Stores.war/WEB-INF folder of the temporary directory on the development machine, for example drive:\ExportTemp\Stores.war\WEB-INF.

    3. Open the struts-config-ext.xml file in a text editor.

    4. Locate the following tag: </global-forwards>.

    5. Insert the following text just before the </global-forwards> tag:

      <forward
      name="MyNewView" path="/MyNewJSPTemplate.jsp" className="com.ibm.commerce.struts.ECActionForward">
      
      </forward> 
      

      The resulting text should look like the following:

      <forward
      name="MyNewView" path="/MyNewJSPTemplate.jsp" className="com.ibm.commerce.struts.ECActionForward"> 
      </forward> 
      </global-forwards>
      

    6. Locate the following tag: </action-mappings>.

    7. Insert the following text just before the </action-mappings> tag:

      <action path="/MyNewView" type="com.ibm.commerce.struts.BaseAction">
      </action>
      <action path="/MyNewControllerCmd" type="com.ibm.commerce.struts.BaseAction" parameter="com.ibm.commerce.sample.commands.MyNewControllerCmd">
      </action>
      

      The resulting text should look like the following:

      <action path="/MyNewView" type="com.ibm.commerce.struts.BaseAction">
      </action>
      <action path="/MyNewControllerCmd" type="com.ibm.commerce.struts.BaseAction" parameter="com.ibm.commerce.sample.commands.MyNewControllerCmd">
      </action>
      </action-mappings>
      

    8. Save and close the file, ensuring the changes are made successfully.

  9. Compress the store assets into one file

    In this section we will compress all four store asset changes into one file so they can be deployed together. In the temporary directory, for example drive:\ExportTemp\, use a ZIP utility to create a compressed file with Stores.war as the root directory in the compressed file. Name the file StoreAssets.zip, for exampledrive:\ExportTemp\StoreAssets.zip. The compressed file should contain the following files in the following directories:

    • Stores.war\WEB-INF\classes\ConsumerDirect_name\TutorialNLS_en_US.properties

    • Stores.war\WEB-INF\classes\ConsumerDirect_name\TutorialNLS.properties

    • Stores.war\ConsumerDirect_name\MyNewJSPTemplate.jsp

    • Stores.war\WEB-INF\struts-config-ext.xml

  10. Package access control policies

    In this section, we will copy the access control policies that were created for the new resources into the drive:\ExportTemp directory,...

    1. Navigate to the WC_EAR\xml\policies\xml directory.

    2. Copy the following files into the drive:\ExportTemp\ACPolicies directory:

      • MyNewViewACPolicy.xml

      • MyNewControllerCmdACPolicy.xml

      • SampleACPolicy_template.xml

      • SampleACPolicy_template_en_US.xml

  11. Transfer assets to the target WebSphere Commerce Server

    In this step, we will create a temporary directory on the target WebSphere Commerce Server and then copy the bonus point assets into this directory.

    To copy the files from the development machine to the target WebSphere Commerce Server:

    1. On the target WebSphere Commerce Server, create a temporary directory called drive:\ImportTemp.

    2. Determine how we will copy the files from one computer to another. You can do this by mapping a drive on the target WebSphere Commerce Server to the development machine, or by using an FTP application.

    3. From the development machine, copy the contents of drive:\ExportTemp into drive:\ImportTemp on the target WebSphere Commerce Server.

  12. Stop the target WebSphere Commerce application

    Open the WebSphere Application Server administration console and stop the WebSphere Commerce application:

    1. Open the WebSphere Application Server Administrative Console.

    2. Click Applications > Application Types > WebSphere Enterprise Applications to see a list of installed applications.

    3. Select the WebSphere Commerce application, for example WC_demo, and click Stop.

  13. Update the database on the target WebSphere Commerce Server

    Before updating the target database, verify the store entity ID for the store to which you are deploying the customized logic. The following SQL statement can be used to determine this value:

    select STOREENT_ID from STOREENT where IDENTIFIER='ConsumerDirect_name'
    

    where ConsumerDirect_name is the name of the store to which you are deploying the code.

  14. Register the new controller command in the database

    Update the target database with information about the new controller command:

    1. Connect to the DB2 database.

    2. Create the required entry in the CMDREG table, by running the following SQL query:

              
      insert into CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION,  CLASSNAME, TARGET)
      values (CD_storeent_ID, 'com.ibm.commerce.sample.commands.MyNewControllerCmd', 
      'This is a new controller command for the business logic tutorial.',       
      'com.ibm.commerce.sample.commands.MyNewControllerCmdImpl',         
      'local');
      

      where CD_storeent_ID is the unique identifier for the store that is based on the consumer direct sample store.

    1. Connect to the Oracle database

    2. In the SQL Plus window, enter the following SQL statement:

      insert into CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION, 
         CLASSNAME, TARGET)
      values (CD_storeent_ID, 
         'com.ibm.commerce.sample.commands.MyNewControllerCmd', 
         'This is a new controller command for the business logic tutorial.', 
         'com.ibm.commerce.sample.commands.MyNewControllerCmdImpl','local');
      

      where CD_storeent_ID is the unique identifier for the store that is based on the consumer direct sample store.

      Press Enter to run the SQL statement.

    3. Press Enter and type commit; to commit the database changes.

  15. Create the XBONUS table

    In this step, you will create the XBONUS table in the database used by the target WebSphere Commerce Server.

    1. Ensure you are logged in as the WCS instance user.

    2. Connect to the DB2 database.

    3. In the Script window, run the following SQL statement:

      create table XBONUS (MEMBERID BIGINT NOT NULL, 
              BONUSPOINT INTEGER NOT NULL, OPTCOUNTER SMALLINT NOT NULL, 
              constraint p_xbonus primary key (MEMBERID), 
              constraint f_xbonus foreign key (MEMBERID) 
              references users (users_id) on delete cascade);
      

    1. Connect to the Oracle database.

    2. In the SQL Plus window, enter the following SQL statement:

      create table XBONUS (MEMBERID NUMBER NOT NULL, 
              BONUSPOINT INTEGER NOT NULL, OPTCOUNTER SMALLINT NOT NULL,         constraint p_xbonus primary key (MEMBERID), 
              constraint f_xbonus foreign key (MEMBERID) 
              references users (users_id) on delete cascade);
      

      and press Enter to run the SQL statement.

    3. Enter the following to commit the database changes:

      commit;
      

      and press Enter to run the SQL statement.

  16. Load access control policies on the target WebSphere Commerce Server

    In this step, we will load the access control policies for the new resources onto the target WebSphere Commerce Server.

    To load the new policy:

    1. Update the access control policies to reflect the values specific to the target WebSphere Commerce Server,...

      1. Determine the member ID value for the consumer direct store,...

          1. Connect to the target database

          2. Run the following SQL statement:

            select member_id from storeent where storeent_id=CD_storeent_ID
            

            where CD_storeent_ID is the store entity ID for the consumer direct store. For example, you could enter:

            select member_id from storeent where storeent_id=10001
            

            Make note of the member ID value: ________________________

        • If you are using an Oracle database:

          1. Open the Oracle SQL Plus command window ((Start > Programs > Oracle - oracle_home > Application Development > SQL Plus, where oracle_home is the name of the oracle home to use.).

          2. In the User Name field, enter the Oracle user name.

          3. In the Password field, enter the Oracle password.

          4. In the Host String field, enter the connect string.

          5. In the SQL Plus window, enter the following SQL statement: column member_id format 99999999999999999999999999999999999; (thirty-five nines) This SQL statement sets the display of the member_id column wide enough to view the entire value of the next SQL statement.

          6. Issue the following SQL statement:

            select member_id from storeent where storeent_id=CD_storeent_ID;
            

            where CD_storeent_ID is the store entity ID for the consumer direct store. For example, you can enter:

            select member_id from storeent where storeent_id=10001;
            

            Make note of the member ID value: ________________________

          7. Reset the display width of the member_id column by entering the following statement:

            column member_id clear;
            

      2. Navigate to the following directory: drive:\ImportTemp\ACPolicies

      3. Use a text editor, open the SampleACPolicy_template.xml file and replace ConsumerDirectMemberId with the member ID value for the consumer direct store, as determined in step a. Save the modified file as SampleACPolicy.xml.

      4. Use a text editor, open the SampleACPolicy_template_en_US.xml file and replace ConsumerDirectMemberId with the member ID value for the consumer direct store, as determined in step step a. Save the modified file as SampleACPolicy_en_US.xml.

    2. Copy the following access control policies into the WC_INSTALL\xml\policies\xml directory:

      • MyNewViewACPolicy.xml

      • MyNewControllerCmdACPolicy.xml

      • SampleACPolicy.xml

      • SampleACPolicy_en_US.xml

    3. At a command prompt, navigate to the following directory: WC_INSTALL\bin

    4. Ensure you are logged in as wasuser_ID, where wasuser_ID is the non-root user ID created before installing WebSphere Commerce. The default WebSphere Application Server user name is wasuser.

    5. Ensure the four input XML files have the same permissions and ownership as other files in the WC_INSTAL../images/locale/screensnap/xml/policies/xml directory.

    6. Ensure you are logged in a profile that can read, write, and execute files under WC_INSTAL../images/locale/screensnap/xml/policies, WC_USE../images/locale/screensnap/instances and WC_USE../images/locale/screensnap/instances/instanceName/logs. For example, define the profile with USRCLS *SECOFR.

    7. Issue the acpload command, which has the following form:

      acpload targetDB dbuser dbpassword inputXMLFile schema_name
      

      Where:

      targetDB

      is the name of the development database.

      dbuser

      is the name of the database user.

      dbpassword

      is the password for the database user.

      inputXMLFile

      is the XML file containing the access control policy specification. In this case, specify MyNewViewACPolicy.xml.

      schema_name

      is

      • the database user who created the database and owns the schema

      • the user who owns the tables

      • This parameter is not required.

      The following example demonstrates the command with variables specified:

      acpload Demo_Dev db2admin db2admin MyNewViewACPolicy.xml DBUSER
      

    8. Repeat the previous step for each of the following access control policies:

      • MyNewControllerCmdACPolicy.xml

      • SampleACPolicy.xml

    9. To load the policy description (which is contained in the SampleACPolicy_en_US.xml file), issue the acpnlsload command, which has the following form:

      acpnlsload db_name db_user db_password inputXMLFile schema_name
      

      For example, you can issue the following command:

      acpnlsload Demo_dev user password SampleACPolicy_en_US.xml DBUSER
      

    10. Check for any error logs that might have been generated while the access control policies were loaded:

  17. Export a backup copy the EAR

    Export a backup copy of the EAR, so that you can revert to the old version in the future if desired:

    1. In the WebSphere Application Server administrative console, click Applications > Application Types > WebSphere Enterprise Applications to see a list of installed applications.

    2. Select the WebSphere Commerce application, for example WC_demo, and click Export.

    3. Follow the wizard and save the EAR file in a backup directory. If the EAR file is large in size, this action might take some time.

  18. Update store assets on the target WebSphere Commerce Server

    Update the store with the modified store assets using the WebSphere Application Server administrative console:

    1. In the WebSphere Application Server administrative console, click Applications > Application Types > WebSphere Enterprise Applications.

    2. Select the application name, for example WC_demo, and click Update.

    3. Select Replace or add multiple files.

    4. In the Specify the path to the file section:

      • If you are running the WebSphere Application Server administrative console on the target machine, select Local file system, as the files are local to the browser.

      • If you are running the WebSphere Application Server administrative console on a different machine, select Remote file system, as the files are remote to the browser.

      Specify the path to drive:\ImportTemp\StoreAssets.zip

    5. Click Next.

    6. Click OK.

    7. When the update completes click Manage Applications. Leave the WebSphere Application Server administrative console open.

  19. Update the command and data bean JAR file on the target WebSphere Commerce Server

    In this section we will update the target WebSphere Commerce Server to use the new command and data bean JAR file,...

    1. In the WebSphere Application Server administrative console, select your application name, for example WC_demo, and click Update.

    2. Select Replace or add a single file.

    3. In the Specify the path beginning with the installed application archive file to the file to be replaced or added field, enter WebSphereCommerceServerExtensionsLogic.jar.

    4. If you are running the WebSphere Application Server administrative console on the target machine, select Local file system, as the files are local to the browser.

      If you are running the WebSphere Application Server administrative console on a different machine, select Remote file system, as the files are remote to the browser.

    5. In the Specify the path to the module section, specify the path to WebSphereCommerceServerExtensionsLogic.jar. For example, drive:\ImportTemp\WebSphereCommerceServerExtensionsLogic.jar.

    6. Click Next.

    7. Click OK.

    8. When the update completes click Manage Applications. Leave the WebSphere Application Server administrative console open.

    It is possible to update both the store assets and the WebSphereCommerceServerExtensionsLogic.jar in one partial application update. In this tutorial the updates are separated for clarity. However in a production environment it is likely more efficient to combine the two updates into one update.

    Tip: If you see a class cast exception, you likely chose the wrong type of update, for example, you choose Single Module instead of Single File.

  20. Update the EJB JAR file on the target WebSphere Commerce Server

    In this section you update the target WebSphere Commerce Server to use the new EJB JAR file:

    1. In the WebSphere Application Server administrative console, select your application name, for example WC_demo, and click Update.

    2. Select Replace or add a single module.

    3. In the Specify the path beginning with the installed application archive file to the module to be replaced or added field, enter WebSphereCommerceServerExtensionsData.jar.

    4. If you are running the WebSphere Application Server administrative console on the target machine, select Local file system, as the files are local to the browser.

      If you are running the WebSphere Application Server administrative console on a different machine, select Remote file system, as the files are remote to the browser.

    5. In the Specify the path to the module section, specify the path to WebSphereCommerceServerExtensionsData.jar. For example, drive:\ImportTemp\WebSphereCommerceServerExtensionsData.jar.

    6. Click Next.

    7. In the Preparing for the application update page:

      1. Select Fast Path - Prompt only when additional information is required.

      2. In the Specify bindings to use field, ensure that merge new and existing bindings is selected; then click Next.

      3. In the How do to install the application section, check Detailed - Show all installation options and parameters.

      4. In the Specify bindings to use field, select use new bindings.

      5. Check Generate Default Bindings.

      6. Check Override existing bindings.

      7. Check Default bindings for EJB 1.1 CMP beans. Complete the fields:

        Option Description
        JNDI name Enter the datasource JNDI name of the target WebSphere Commerce Server. For example:

        • jdbc/WebSphere Commerce DB2 DataSource myInstance where the target WebSphere Commerce Server is using a DB2 database, and the WCS instance name is myInstance

        • jdbc/WebSphere Commerce Oracle DataSource myInstance where the target WebSphere Commerce Server is using an Oracle database, and the WCS instance name is myInstance.

        username Enter the user name of the database user.
        password and verify password Enter the password of the database user.

      Your screen should be similar to the following:

    8. Leave all other default values and click Next.

    9. On the Application Security Warnings screen, click Continue.

    10. Select any steps marked with a star and enter the JNDI name in the appropriate field.

    11. On the Install New Application screen, click Step 10: Summary.

    12. A summary of changes displays. Click Finish.

    13. When the update completes successfully, click Save to Master Configuration.

    14. On the WebSphere Enterprise Applications screen, click Save to save the changes to the master configuration. All the changes are saved, including updating the store assets, command and data bean file and the EJB jar file.

    15. Close the WebSphere Application Server administration console.

  21. Stop and start the WebSphere Application Server.

  22. Verify bonus points logic on the target WebSphere Commerce Server

    In this step, you verify that the bonus points logic has been successfully deployed to the target WebSphere Commerce Server:

    1. Open a Web browser and enter the URL to launch the store that is based on the consumer direct sample store.

    2. Create a new registered user, by doing the following:

      1. Click Sign in.

      2. Click Register to create a new customer.

      3. In the registration form, enter appropriate values into all of the mandatory fields. Make note of the value for the logon id: _________________________.

      4. Once the values have been entered, click Submit.

    3. Once the login has completed, enter the following URL in the same browser:

      http://hostname/webapp/wcs/stores/servlet/MyNewControllerCmd?
         input1=user_logon&input2=100
      

      where hostname is the host name and user_logon is the logon id for the user that you created in step 2. You are presented with a page that contains all of the previous output parameters as well as a new form that allows you to update the balance of bonus points for the user.

    4. Now, into the Logon ID field enter the logon id and in the Bonus Point field, enter 500. Click Submit. You are presented with a page similar to the following one that shows that the balance of bonus points is updated.

< Previous | Next >


+

Search Tips   |   Advanced Search