Tutorials > Program model > Web services > Create an outbound Web service client for WebSphere Commerce

< Previous | Next >


Integrate the MyCompanyMember client API with WebSphere Commerce

This section is related to integrating the MyCompanyMember client API with WebSphere Commerce.

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

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


Procedure

  1. Create a package to contain the extension commands:

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

    2. Right-click on 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 will instruct the MyCompanyMember client API to transmit a message to register the user to the external system.

    1. Right-click on the com.mycompany.commerce.member.commands package.

    2. Select New > Class.

      1. In the Name field, type: MyCompanyPostUserRegistrationAddCmdImpl

      2. Next to the Superclass field, click Browse.

      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:

      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 ( Ctrl S).

  3. Create the Update command extension. This command will instruct the MyCompanyMember client API to transmit a message to update the user in the external system.

    1. Right-click on the com.mycompany.commerce.member.commands package.

    2. Select New > Class.

      1. In the Name field, type: MyCompanyPostUserRegistrationUpdateCmdImpl

      2. Next to the Superclass field, click Browse.

      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:

      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 the file ( Ctrl S).

  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:

< Previous | Next >


+

Search Tips   |   Advanced Search