Extending the client library

You can extend an existing client library to add more data to the current service request, handle new data in a service response, or add new behavior by building an entirely new service request.

To extend an existing client library:

  1. Start WebSphere Commerce Developer.

  2. Identify the client library to extend (for example, CommonOrderFacadeClient).

  3. Identify the behavior in the client library that you intend to add or change (for example, adding additional data to the UserData element of the Order noun).

    1. If the extension includes adding more data, identify the appropriate build ObjectName() method to override to add more data. Extend the class and override this method. For example, if you are adding engraving data to a set of order items, you would add the following code to the buildOrderItem() method
      protected OrderItemType[] buildOrderItem(Map parameters, String
      actionName) throws OrderException 
      
      {
      //Snippet below
      for (int i=0; i<orderItems.length; i++) //for all of the order
      items
      {
              OrderItemType orderItem = orderItems[i]; //get a particular
      order item
              //prepare the userData section
              UserDataType userData = orderItem.getUserData();
              if (userData == null)
              {
                      userData =
      CommerceFoundationFactory.eINSTANCE.createUserDataType();
              }
              orderItem.setUserData(userData);
              Map userDataFields  = userData.getUserDataField();
      
              //iterate through all the engraving parameters
              Set keys = parameters.keySet();
              Iterator it = keys.iterator();
              while (it.hasNext())
              {
                      String keyName = (String)it.next();
                      if (keyName.startsWith(ENGRAVINGKEYNAME))//if it is
      an engraving attribute
                      {
                              String[] values =
      (String[])parameters.get(keyName);
                              //create a new name, value pair type
                              userDataFields.put(keyName,values[i]);
                      }
              }
      }
      }
      

    2. If the extension includes adding new behavior, extend the client library and add a method to build a new Service Data Object request that represents the new behavior.

  4. Configure the presentation framework to register your extended client library, to allow the presentation layer to use your extended library instead of the default.

Related concepts

WebSphere Commerce services
WebSphere Commerce service module
Client library for WebSphere Commerce services
Web enablement for the client library

Related tasks

Create the client library
Deploying the client library