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

< Previous | Next >


Implement the MyCompanyMember client API

In the step we will create the MyCompanyMember client API in the WebSphereCommerceServerExtensionsLogic project. This API uses the SDOs generated in the previous step to send request messages and handle response messages.

The API consists of the following artifacts:

To implement the API:


Procedure

  1. Update the build path for the WebSphereCommerceServerExtensionsLogic project to reference the MyCompanyMemberDataObjects project.

    1. In the Enterprise Explorer view, right-click on the WebSphereCommerceServerExtensionsLogic project.

    2. Select Properties.

    3. In the left pane, select Java Build Path.

    4. In the center pane, select the Projects tab.

    5. Select the MyCompanyMemberDataObjects project.

    6. Click OK.

  2. Create the MyCompanyPushUserInvocationServiceObjectImpl class to convert the request SDO (PushUser) to xml.

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

    2. Right-click on the src folder.

    3. Select New > Package.

      1. In the Name field, type: com.mycompany.commerce.member.services.invocation.

      2. Click Finish.

    4. Right-click on the com.mycompany.commerce.member.services.invocation package.

    5. Select New > Class

      1. In the Name field, type MyCompanyPushUserInvocationServiceObjectImpl.

      2. Next to the Superclass field, click Browse.

      3. Enter AbstractSDOInvocationServiceObjectImpl in the Choose a type input field.

      4. Click OK.

      5. Click Finish.

    6. Add the following import statement to the class:

      import org.eclipse.emf.ecore.sdo.EDataObject;
      import com.mycompany.commerce.member.facade.datatypes.DocumentRoot;
      import com.mycompany.commerce.member.facade.datatypes.MemberFactory;
      import com.mycompany.commerce.member.facade.datatypes.PushUserType;
      import com.mycompany.commerce.member.facade.datatypes.util.MemberResourceFactoryImpl;
      import com.mycompany.commerce.member.facade.datatypes.PushUserConfirmationType;
      import com.ibm.commerce.foundation.services.invocation.AbstractSDOInvocationServiceObjectImpl;
      

    7. Copy and paste the following constructor to the class:

      public MyCompanyPushUserInvocationServiceObjectImpl() {
              super(); 
      }
      

    8. Copy and paste the following getMemberFactory() method into the class:

      protected MemberFactory getMemberFactory() {
        return MemberFactory.INSTANCE;
      }
      

    9. Replace the body of the getResourceFactory() method with:

      return new MemberResourceFactoryImpl();
      

    10. Replace the body of the getDocumentRoot() method with:

      DocumentRoot documentRoot =getMemberFactory().createDocumentRoot();
      documentRoot.setPushUser((PushUserType) getDataObject());
      return (EDataObject) documentRoot;
      

    11. Replace the body of the setDocumentRoot(Object documentRoot) method with:

      setDataObject(((DocumentRoot)arg0).getPushUser());
      

      Verify the method parameters match.

    12. Save the file ( Ctrl S).

  3. Create the MyCompanyPushUserConfirmationInvocationServiceObjectImpl to convert the response XML to the response SDO (PushUserConfirmation).

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

    2. Select New > Class

      1. In the Name field, type: MyCompanyPushUserConfirmationInvocationServiceObjectImpl.

      2. Next to the Superclass field, click Browse.

      3. Enter AbstractSDOInvocationServiceObjectImpl.

      4. Click OK.

      5. Click Finish.

    3. Add the following import statement to the class:

      import org.eclipse.emf.ecore.sdo.EDataObject;
      import com.mycompany.commerce.member.facade.datatypes.DocumentRoot;
      import com.mycompany.commerce.member.facade.datatypes.MemberFactory;
      import com.mycompany.commerce.member.facade.datatypes.PushUserConfirmationType;
      import com.mycompany.commerce.member.facade.datatypes.util.MemberResourceFactoryImpl;
      

    4. Copy and paste the following constructor to the class:

      public MyCompanyPushUserConfirmationInvocationServiceObjectImpl() {
         super();
      }
      

    5. Copy and paste the following getMemberFactory() method to the class:

      protected MemberFactory getMemberFactory() {
          return MemberFactory.INSTANCE;
      }
      

    6. Replace the body of the getResourceFactory() method with:

      return new MemberResourceFactoryImpl();
      

    7. Replace the body of the getDocumentRoot() method with:

      DocumentRoot documentRoot = getMemberFactory().createDocumentRoot();
      documentRoot.setPushUserConfirmation((PushUserConfirmationType)getDataObject());
      return (EDataObject)documentRoot;
      

    8. Replace the body of the setDocumentRoot(Object documentRoot) method with:

      setDataObject(((DocumentRoot)documentRoot).getPushUserConfirmation());
      

      Verify the method parameters match.

  4. Create the MyCompanyMemberClientFacade class to transmit the request message.

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

    2. Right-click on the src folder.

    3. Select New > Package.

    4. In the Name field, type: com.mycompany.commerce.member.client.

    5. Click Finish.

    6. Right-click on the com.mycompany.commerce.member.client package.

    7. Select New > Class.

      1. In the Name field, type: MyCompanyMemberClientFacadeImpl

      2. Click Finish.

    8. Add the following import statements to the class:

      import com.ibm.commerce.foundation.services.invocation.InvocationService;
      import com.ibm.commerce.foundation.services.invocation.InvocationServiceObject;
      import com.ibm.commerce.foundation.services.invocation.exception.InvocationServiceException;
      import com.mycompany.commerce.member.facade.datatypes.PushUserConfirmationType;
      import com.mycompany.commerce.member.facade.datatypes.PushUserType;
      import com.mycompany.commerce.member.services.invocation.MyCompanyPushUserConfirmationInvocationServiceObjectImpl;
      import com.mycompany.commerce.member.services.invocation.MyCompanyPushUserInvocationServiceObjectImpl;
      

    9. Copy and paste the following into the class body:

      /**
       * The component ID of this client facade implementation.
       */
      public static final String COMPONENT_ID =
      "com.mycompany.commerce.member";
      
      private static MyCompanyMemberClientFacadeImpl instance = new
      MyCompanyMemberClientFacadeImpl();
      
      public MyCompanyMemberClientFacadeImpl() {
              super();
      }
      
      /**
       * Returns an instance of this client facade implementation.
       * @return an instance of this client facade implementation.
       */
      public static MyCompanyMemberClientFacadeImpl getInstance() {
              return instance;
      }
      
      /**
       * Makes the
      <code>pushUser</code> service request with
      the
       * invocation service action and specified
      <code>PushUser</code> SDO.
       * @param action the invocation service action.
       * @param pushUser the PushUserType SDO.
       * @return the PushUserConfirmationType SDO.
       * @throws InvocationServiceException
       */
      public PushUserConfirmationType pushUser(String action, PushUserType pushUser ) throws InvocationServiceException {
              InvocationService invocationService = new
      InvocationService(COMPONENT_ID, action);
              InvocationServiceObject requestDataObject = new
      MyCompanyPushUserInvocationServiceObjectImpl();
              requestDataObject.setDataObject(pushUser);
              InvocationServiceObject responseDataObject = new
      MyCompanyPushUserConfirmationInvocationServiceObjectImpl();
              invocationService.invoke(requestDataObject, responseDataObject);
              return (PushUserConfirmationType)
      responseDataObject.getDataObject();
      }
      

    10. Save the file ( Ctrl S).

< Previous | Next >


+

Search Tips   |   Advanced Search