Samples > Sample stores > Consumer direct sample store > IBM Gift Center for the Consumer direct sample store > IBM Gift Center message mapping > IBM Gift Center inbound messages


Enable IBM Gift Center inbound messages

Inbound messages are messages from an external system entering the IBM Gift Center system.

In GiftRegistryMessageMapper, the method createFromMessage creates a BOD object and other necessary value out of the given message. If the method argument is an instance of java.lang.String, the method will call the parser to convert the represented back-end XML message into the required BOD to execute the service. The converted BOD is set to the CommandProperty object with key being EC_GIFT_REGISTRY_MESSAGE_BOD, which is passed to the GiftRegistryServiceInvokerCmd.

The IBM Gift Center approach to inbound messaging is...

  1. Create a message mapper:

    public class GiftRegistryMessageMapper
                    extends com.ibm.commerce.programadapter.messagemapper.
                            MessageMapperGenericImpl
                    implements com.ibm.commerce.programadapter.messagemapper.
                            MessageMapper {
    

  2. Implement a method:

    public com.ibm.commerce.datatype.CommandProperty createFromMessage
                    (Object message) {
                    final String METHODNAME = "createFromMessage";                 // We always assume the given message is of String
                    if (message instanceof String) {
                            try {
                                    com.ibm.commerce.datatype.CommandProperty pcmd = null;                                 // Make sure the comand property can be instantiated
                                    if (xmlMessageTemplate != null) {
                                            pcmd = (new com.ibm.commerce.messaging.commandmapper.xml.
                                            ECSAXParser(xmlMessageTemplate)).parseBuf((String) message);                                 }
                                    
                                    if (pcmd == null) {
                                            return null;                                 }
                                    // Convert the given message to service request object
                                    GiftRegistryMessageMapperHelper helper = 
                                            GiftRegistryMessageMapperHelper.newInstance((String)message);                                 // Store the converted message object to the command properties
                                    pcmd.getRequestProperties().put(ECGiftRegistryConstants.
                                            EC_GIFT_REGISTRY_MESSAGE_BOD, helper.getMessageObject());                                 // Store the service name (service command) in the command properties
                                    pcmd.getRequestProperties().put(ECGiftRegistryConstants.
                                            EC_GIFT_REGISTRY_MESSAGE_SERVICE_NAME, helper.getServiceName());                                 // Store the ID of the store in which the message will be run
                                    pcmd.getRequestProperties().put(ECGiftRegistryConstants.
                                            EC_GIFT_REGISTRY_MESSAGE_STORE_ID, helper.getMessageStoreId()); 
                                    return pcmd; 
                            } catch (Exception e) {
                                    GiftRegistryTraceLogger.trace(getClass().getName(), 
                                            METHODNAME, e.getMessage());                                 GiftRegistryTraceLogger.trace(getClass().getName(), 
                                            METHODNAME, e.fillInStackTrace().toString());                         }
                    }
                    return null;         }
    

  3. Register the message mapper in the WebSphere Commerce configuration file, using the <MessageMapper> tag:

    <MessageMapper
                    classname="com.ibm.commerce.giftregistry.messaging.programadapter.
                    messagemapper.GiftRegistryMessageMapper".../>
    

  4. Use the GiftRegistryServiceInvokerCmd command to handle messages.

The GiftRegistryServiceInvokerCmd will be called upon any incoming IBM Gift Center messages. Being invoked, it will pick up the BOD instance created by GiftRegistryServiceMapper, and then invoke the IBM Gift Center service command accordingly. It can be configured in the messaging template file so that the messaging system calls it upon incoming messages.

The following is a sample messaging template:

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE ECTemplate SYSTEM 'ec_template.dtd' > 
<ECTemplate> 
       
<TemplateDocument> 
               
<DocumentType>UpdateGiftRegistryBOD</DocumentType> 
               
<StartElement>UpdateGiftRegistryBOD</StartElement> 
               
<TemplateTagName>GiftRegistry10Map</TemplateTagName> 
               
<CommandMapping> 
               
<Command CommandName='GiftRegistryServiceInvokerCmd' /> 
               
</CommandMapping> 
       
</TemplateDocument>   
<TemplateTag name='GiftRegistry10Map'></TemplateTag>        
<TemplateDocument> 
               
<DocumentType>UpdateGiftRegistryPurchaseRecordBOD</DocumentType> 
               
<StartElement>UpdateGiftRegistryPurchaseRecordBOD</StartElement> 
               
<TemplateTagName>GiftRegistry11Map</TemplateTagName> 
               
<CommandMapping> 
                       
<Command CommandName='GiftRegistryServiceInvokerCmd' /> 
               
</CommandMapping> 
       
</TemplateDocument>   
<TemplateTag name='GiftRegistry11Map'></TemplateTag>    
<TemplateDocument> 
               
<DocumentType>PostGiftRegistryAnnouncementBOD</DocumentType> 
               
<StartElement>PostGiftRegistryAnnouncementBOD</StartElement> 
               
<TemplateTagName>GiftRegistry12Map</TemplateTagName> 
               
<CommandMapping> 
                       
<Command CommandName='GiftRegistryServiceInvokerCmd' />                
</CommandMapping>                 
       
</TemplateDocument>        
<TemplateTag name='GiftRegistry12Map'></TemplateTag>
</ECTemplate>


Related concepts

IBM Gift Center for the Consumer direct sample store

IBM Gift Center architecture

Related reference

IBM Gift Center inbound messages

IBM Gift Center outbound messages

IBM Gift Center message mapping


+

Search Tips   |   Advanced Search