Integrating the MyCompanyMember client API with WebSphere Commerce

In this lesson, you integrate the MyCompanyMember client API with WebSphere Commerce.

About this task

Custom post user registration commands are needed to instruct the MyCompanyMember client API to build and send the appropriate message. In this lesson, you extend the following WebSphere Commerce integration points:

Message Type Interface Class name Extension
Register PostUserRegistrationAddCmd PostUserRegistrationAddCmdImpl MyCompanyPostUserRegistrationAddCmdImpl
Update PostUserRegistrationUpdateCmd PostUserRegistrationUpdateCmdImpl MyCompanyPostUserRegistrationUpdateCmdImpl

Procedure

  1. Create a package to contain your extension commands:
    1. In the Enterprise Explorer view , expand the WebSphereCommerceServerExtensionsLogic project.
    2. Right-click the src folder.
    3. Select New > Package.
    4. Name com.mycompany.commerce.member.commands.
    5. Click Finish.
  2. Create the Register command extension. This command instructs the MyCompanyMember client API to transmit a message to register the user to the external system.
    1. Right-click the com.mycompany.commerce.member.commands package.
    2. Select NewClass.
      1. In the field Name, type: MyCompanyPostUserRegistrationAddCmdImpl
      2. Click the Browse button next to the field Superclass.
      3. Enter PostUserRegistrationAddCmdImpl
      4. Click OK.
      5. Click Finish.
    3. Add the following import statements to the class:
      
      import java.rmi.RemoteException;
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import javax.naming.NamingException;
      import com.ibm.commerce.command.CommandFactory;
      import com.ibm.commerce.exception.ECException;
      import com.ibm.commerce.exception.ECSystemException;
      import com.ibm.commerce.member.constants.ECMemberConstants;
      import com.ibm.commerce.ras.ECMessage;
      import com.ibm.commerce.user.objects.UserAccessBean;
      import
      com.mycompany.commerce.member.client.commands.MyCompanyPushUserCmd;
      
    4. Replace the body of the class with the following code:
      
      public MyCompanyPostUserRegistrationAddCmdImpl() {
              super();
      }
      /**
       * Executes the business logic of this command implementation.
       * @exception ECException
       */
      public void performExecute() throws ECException {
      final String METHODNAME = "performExecute";
          try {
              super.performExecute();
              Long userID =
      getResponseProperties().getLong(ECMemberConstants.EC_USERID);
              UserAccessBean user = new UserAccessBean();
              user.setInitKey_MemberId(userID.toString());
              user.refreshCopyHelper();
              MyCompanyPushUserCmd cmd = (MyCompanyPushUserCmd)
      CommandFactory.createCommand(MyCompanyPushUserCmd.NAME,
      getCommandContext().getStoreId());
              cmd.setCommandContext(getCommandContext());
                     
      cmd.setAction(MyCompanyPushUserCmd.ACTION_CREATE_USER);
              cmd.setPushUser(user); 
              cmd.execute();
              } catch (NamingException e) {
                      throw new
      ECSystemException(ECMessage._ERR_NAMING_EXCEPTION,
      getClass().getName(), METHODNAME, new Object[] {e.toString()}, e);
              } catch (RemoteException e) {
                      throw new
      ECSystemException(ECMessage._ERR_REMOTE_EXCEPTION,
      getClass().getName(), METHODNAME, new Object[] {e.toString()}, e);
              } catch (CreateException e) {
                      throw new
      ECSystemException(ECMessage._ERR_CREATE_EXCEPTION,
      getClass().getName(), METHODNAME, new Object[] {e.toString()}, e);
              } catch (FinderException e) {
                      throw new
      ECSystemException(ECMessage._ERR_FINDER_EXCEPTION,
      getClass().getName(), METHODNAME, new Object[] {e.toString() }, e);
              }
      }
      
    5. Save the file.
  3. Create the Update command extension. This command instructs the MyCompanyMember client API to transmit a message to update the user in the external system.
    1. Right-click the com.mycompany.commerce.member.commands package.
    2. Select New > Class.
      1. In field the Name, type: MyCompanyPostUserRegistrationUpdateCmdImpl
      2. Click the Browse button next to the field Superclass.
      3. Enter PostUserRegistrationUpdateCmdImpl
      4. Click OK.
      5. Click Finish.
    3. Add the following import statements to the class:
      
      import java.rmi.RemoteException;
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import javax.naming.NamingException;
      import com.ibm.commerce.command.CommandFactory;
      import com.ibm.commerce.exception.ECException;
      import com.ibm.commerce.exception.ECSystemException;
      import com.ibm.commerce.member.constants.ECMemberConstants;
      import com.ibm.commerce.ras.ECMessage;
      import com.ibm.commerce.user.objects.UserAccessBean;
      import
      com.mycompany.commerce.member.client.commands.MyCompanyPushUserCmd;
      
    4. Replace the body of the class with the following code:
      
      public MyCompanyPostUserRegistrationUpdateCmdImpl() {
              super();
      }
      /**
       * Executes the business logic of this command implementation.
       * @exception ECException
       */
      public void performExecute() throws ECException {
      final String METHODNAME = "performExecute";
          try {
              super.performExecute();
              Long userID =
      getResponseProperties().getLong(ECMemberConstants.EC_USERID);
              UserAccessBean user = new UserAccessBean();
              user.setInitKey_MemberId(userID.toString());
              user.refreshCopyHelper();
              MyCompanyPushUserCmd cmd = (MyCompanyPushUserCmd)
      CommandFactory.createCommand(MyCompanyPushUserCmd.NAME,
      getCommandContext().getStoreId());
              cmd.setCommandContext(getCommandContext());
                     
      cmd.setAction(MyCompanyPushUserCmd.ACTION_UPDATE_USER);
              cmd.setPushUser(user);
              cmd.execute();
              } catch (NamingException e) {
                      throw new
      ECSystemException(ECMessage._ERR_NAMING_EXCEPTION,
      getClass().getName(), METHODNAME, new Object[] {e.toString()}, e);
              } catch (RemoteException e) {
                      throw new
      ECSystemException(ECMessage._ERR_REMOTE_EXCEPTION,
      getClass().getName(), METHODNAME, new Object[] {e.toString()}, e);
              } catch (CreateException e) {
                      throw new
      ECSystemException(ECMessage._ERR_CREATE_EXCEPTION,
      getClass().getName(), METHODNAME, new Object[] {e.toString()}, e);
              } catch (FinderException e) {
                      throw new
      ECSystemException(ECMessage._ERR_FINDER_EXCEPTION,
      getClass().getName(), METHODNAME, new Object[] {e.toString() }, e);
              }
      }
      
    5. Save and close the file.
  4. Register the extension commands to the command registry by running the following SQL statements:
    1. INSERT INTO CMDREG (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.ibm.commerce.usermanagement.commands.PostUserRegistrationAddCmd', 'com.mycompany.commerce.member.commands.MyCompanyPostUserRegistrationAddCmdImpl', 'Local');
    2. INSERT INTO CMDREG (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.ibm.commerce.usermanagement.commands.PostUserRegistrationUpdateCmd', 'com.mycompany.commerce.member.commands.MyCompanyPostUserRegistrationUpdateCmdImpl', 'Local');
    You can view the database access JSP file from the following URL: