Example: Using the messaging system composition service

The following example shows how you might use the messaging system composition service. If you have a store named MyStore, and you want to assign two transports, e-mail and file, to the CompanyAOrderCreateMsg message type, you would:

Add an entry to Struts configuration files for the JSP file to use for composing this outbound message. The keys for the Struts configuration files are the view name, the store ID, and the device format ID which can be identified from the name attribute "OrderCreateXMLFormatView/0/-3" For example,

 <forward className="com.ibm.commerce.struts.ECActionForward"
 name="OrderCreateXMLFormatView/0/-3" path="/OrderCreateXML.jsp">
 <set-property property="resourceClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/>
 <set-property property="properties" value="storeDir=no"/>
 <set-property property="interfaceName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommand"/>
 <set-property property="implClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/>
 <set-property property="direct" value="true"/>
 </forward>
Important: Each view created to be used by the Messaging System's compose service must use the Messaging View Command for the interface and class name fields. It must also contain the name of the JSP file and any sub-directory relative to the Stores.war and store directory in the path field. To summarize:
INTERFACENAME
com.ibm.commerce.messaging.viewcommands.MessagingViewCommand
CLASSNAME
com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl
PATH
The parameter containing the JSP file name pre-pended with any sub-directory relative to the store directory.
PROPERTIES
Use the following format to point to the JSP file 'docname=jsp file'.
Note: In the struts configuration, PROPERTIES is optional and needed if and only if the value is "storeDir=no". This property is needed if the jsp is located at the default Stores.war directory.
DEVICEFMT_ID
Represents the device format and should use the value -3 (the standard device format) unless using custom device formats for your application. The DEVICEFMT_ID must correspond to the device format selected when assigning a message type to a transport.

In the following example the MyStore STOREENT_ID is 10001 and the viewname is CompanyAOrderAuthorizedView. To avoid possible migration problems, ensure that you prefix the both the view name and the message type name with a unique prefix. In hhe name attribute, "CompanyAOrderAuthorizedView/10001/-3" represents viewname, store ID and device format ID respectively.


 <forward className="com.ibm.commerce.struts.ECActionForward"
 name="CompanyAOrderAuthorizedView/10001/-3" path="/Store_10001_Dir/OrderCreateXML.jsp">
 <set-property property="resourceClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/>
 <set-property property="interfaceName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommand"/>
 <set-property property="implClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/>
 <set-property property="direct" value="true"/>
 </forward>
 

Use the Administration Console to assign the e-mail and file transports to the CompanyAOrderCreateMsg message and configure the settings. This can be done using either site or store level administration authority. Creating settings on site level will make it accessible to all stores.

In the implementation of a command, instantiate the SendMsgCmd command to use messaging services and call the setMsgType() and setStoreID() methods, using the message type name of the CompanyAOrderCreateMsg message type and the store ID of storeent_id of 10001. Place the CompanyAOrderCreateMsg.jsp file in the store's root directory.

To use site-level configuration, do the following:

  1. Specify the STOREENT_ID as 0.
  2. Add PROPERTIES of storeDir=no to the JSP file name.
  3. Place the JSP file in the WC_eardir/Stores.war directory.
  4. Invoke the compose method of the outbound messaging system interface and pass any additional parameters in the form of a TypedProperty object. Refer to the topic Message content setting services.
  5. Call sendImediate or sendTransacted on SendMsgCmd if you want the message to be sent immediately or after the transaction has successfully been committed. Refer to the Messaging System documentation for a further explanation of the use of each method.
  6. Call execute method of the SendMsgCmd to execute sending.