Customizing existing outbound service requests
With HCL Commerce, you can customize the existing outbound service requests, such as extending them to include additional user data.
Procedure
- 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 theProcessOrder
SDO and calling the order client facade implementation to makeTransferOrder
outbound service requests. -
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 ofcom.ibm.commerce.order.client.commands.ProcessOrderCmd
:import com.ibm.commerce.order.client.commands.ProcessOrderCmdImpl; public class MyProcessOrderCmdImpl extends ProcessOrderCmdImpl { }
- 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 theProcessOrder
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 valuebar
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>