Tutorials > Program model > Web services > Create an outbound Web service client for WebSphere Commerce
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
- Create a package to contain the extension commands:
- In the Enterprise Explorer view, expand the WebSphereCommerceServerExtensionsLogic project.
- Right-click on the src folder.
- Select New > Package.
- Name com.mycompany.commerce.member.commands.
- Click Finish.
- 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.
- Right-click on the com.mycompany.commerce.member.commands package.
- Select New > Class.
- In the Name field, type: MyCompanyPostUserRegistrationAddCmdImpl
- Next to the Superclass field, click Browse.
- 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:
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 ( Ctrl S).
- 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.
- Right-click on the com.mycompany.commerce.member.commands package.
- Select New > Class.
- In the Name field, type: MyCompanyPostUserRegistrationUpdateCmdImpl
- Next to the Superclass field, click Browse.
- 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:
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 the file ( Ctrl S).
- Register the extension commands to the command registry by running the following SQL statements:
You can view the database access JSP file from the following URL:
- 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');