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
- Create a package to contain your extension commands:
- In the Enterprise Explorer view , expand the WebSphereCommerceServerExtensionsLogic project.
- Right-click the src folder.
- Select New > Package.
- Name com.mycompany.commerce.member.commands.
- Click Finish.
- Create the Register command extension. This command instructs
the MyCompanyMember client API to transmit a message to register the
user to the external system.
- Right-click the com.mycompany.commerce.member.commands package.
- Select NewClass.
- In the field Name, type: MyCompanyPostUserRegistrationAddCmdImpl
- Click the Browse button next to the field Superclass.
- Enter PostUserRegistrationAddCmdImpl
- Click OK.
- Click Finish.
- 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;
- 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); } }
- Save the file.
- Create the Update command extension. This command instructs
the MyCompanyMember client API to transmit a message to update the
user in the external system.
- Right-click the com.mycompany.commerce.member.commands package.
- Select New > Class.
- In field the Name, type: MyCompanyPostUserRegistrationUpdateCmdImpl
- Click the Browse button next to the field Superclass.
- Enter PostUserRegistrationUpdateCmdImpl
- Click OK.
- Click Finish.
- 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;
- 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); } }
- Save and close the file.
- Register the extension commands to the command registry
by running the following SQL statements:
- INSERT INTO CMDREG (STOREENT_ID, INTERFACENAME, CLASSNAME, TARGET) VALUES (0, 'com.ibm.commerce.usermanagement.commands.PostUserRegistrationAddCmd', 'com.mycompany.commerce.member.commands.MyCompanyPostUserRegistrationAddCmdImpl', 'Local');
- 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: