Customize existing outbound service requests

With WebSphere Commerce, we can customize the existing outbound service requests, such as extending them to include additional user data.


Procedure

  1. Identify the client task command responsible for making the outbound service request. The mappings between service requests and client task commands are found in Outbound service message mappings enabled for service-oriented integration . For example, the order client task command com.ibm.commerce.order.client.commands.ProcessOrderCmd is responsible for composing the ProcessOrder SDO and calling the order client facade implementation to make TransferOrder outbound service requests.

  2. Extend the default implementation of the client task command and register the custom implementation. For example, to customize the TransferOrder outbound service request, extend the default implementation of com.ibm.commerce.order.client.commands.ProcessOrderCmd:

      import com.ibm.commerce.order.client.commands.ProcessOrderCmdImpl;
      
      public class MyProcessOrderCmdImpl extends ProcessOrderCmdImpl {
      }

  3. Override one or more of the protected methods responsible for composing the request BOD and its components. For example, the com.ibm.commerce.order.client.commands.ProcessOrderCmdImpl.composeProcessOrder() method can be overridden to modify the ProcessOrder SDO being composed:

      import com.ibm.commerce.exception.ECException;
      import com.ibm.commerce.order.client.commands.ProcessOrderCmdImpl;
      import com.ibm.commerce.order.datatypes.ProcessOrderType;
      
      public class MyProcessOrderCmdImpl extends ProcessOrderCmdImpl {
              protected ProcessOrderType composeProcessOrder() throws
      ECException {
                      ProcessOrderType processOrder =
      super.composeProcessOrder();
                      //custom code here
                      return processOrder;
              }
      }

    The custom code can modify the SDO by adding new components or modifying existing components. In particular, custom user data can be added to the SDO by utilizing one of its user data areas. For example, the following code will add the user data field foo with value bar to the user data area of the order header:

      public class MyProcessOrderCmdImpl extends ProcessOrderCmdImpl {
              protected ProcessOrderType composeProcessOrder() throws
      ECException {
                      ProcessOrderType processOrder =
      super.composeProcessOrder();
                      OrderType order =
      (OrderType)processOrder.getDataArea().getOrder().get(0);
                      UserDataType userData =
      order.getOrderHeader().getUserData();
                      if(userData == null) {
                              userData =
      getCommerceFoundationFactory().createUserDataType();
                             
      order.getOrderHeader().setUserData(userData);
                      }
                      UserDataFieldType userDataField =
      getCommerceFoundationFactory().createUserDataFieldType();
                      userDataField.setName("foo");
                      userDataField.setValue("bar");
                     
      order.getOrderHeader().getUserData().getUserDataField().add(userDataField);
                      return processOrder;
              }
      }

    This will translate to the following in the ProcessOrder BOD:

      <ord:ProcessOrder>
              <wcf:ApplicationArea>...</wcf:ApplicationArea>
              <ord:DataArea>
                      <wcf:Process>...</wcf:Process>
                      <ord:Order>
                              ...
                              <wcf:UserData>
                                      <wcf:UserDataField
      name="foo">bar</wcf:UserDataField>
                              </wcf:UserData>
                      </ord:Order>
              </ord:DataArea>
      </ord:ProcessOrder>


Related concepts
Understanding the WebSphere Commerce Web service framework
WebSphere Commerce Web services with JSP pages
WebSphere Commerce as a service consumer


Related tasks
Creating a Web service client API for WebSphere Commerce
Enable WebSphere Commerce as a service consumer


Related reference
Additional information about Web services