Outbound messaging system interface programming examples

The following Java code segment shows how interactions with the outbound messaging system can take place. Example 1 shows you how to build a new XML message and send it through the outbound messaging system. Example 2 shows you how to build an e-mail message and send it through the outbound messaging system:

Example 1

try

{

com.ibm.commerce.messaging.commands.SendMsgCmd api =

(com.ibm.commerce.messaging.commands.SendMsgCmd)

CommandFactory.createCommand(SendMsgCmd.NAME, getStoreId());

// Assume you have set the msgType in the MSGTYPES table to 100 and you are 
using

// storeId of 1.

api.setMsgType(new Integer(100));

api.setStoreID(new Integer(1));

 

// You have to choice on how to build the msg:

// First choice: build your XML msg in a String object and then use the 
setContent().

String OrderCreateMsg = new String("<?xml version="1.0" encoding="UTF-8"?> 
...");

api.setContent(OrderCreateMsg);

 

// Or, use the message composition services (compose()) by passing the 
template/view name

// This view name should be registered in VIEWREG and MSGTYPES tables referring 
to

// a JSP message layout template.

String viewName = new String("OrderCreateMsgView");

TypedProperty tp = new TypedProperty();

// get the orderRefNumber and put it into tp

tp.put("ORDER_REF_NUMBER", getOrderRn().toString());

// get the languageId and put it into tp

tp.put("LANGUAGE_ID", getCommandContext().getLanguageId());

// Pass the viewName, command Context and parameters stored in tp to compose 
services.

// Upon successful completion, a message is build according to message layout 
defined in the

// JSP message layout template referred by viewName.

api.compose(viewName, getCommandContext(), tp);

 

// Send out the message using sendTransacted send service.

api.sendTransacted();

// Set the command context obtained from the controller command.

api.setCommandContext(getCommandContext());

// Run the outbound messaging system services

api.execute();

}

catch (Exception ex )

{

ex.printStackTrace(System.err);

}

Example 2

try

{

com.ibm.commerce.messaging.commands.SendMsgCmd api =

(com.ibm.commerce.messaging.commands.SendMsgCmd)

CommandFactory.createCommand(SendMsgCmd.NAME, getStoreId());

// Assume you have set the msgType in the MSGTYPES table to 200 and you are 
using

// storeId of 1.

api.setMsgType(new Integer(200));

api.setStoreID(new Integer(1));

 

// You have to choice on how to build the msg:

// First choice: build your XML msg in a String object and then use the 
setContent().

String OrderNotifyMsg =

new String("Your Order has been received. Thank You for Shopping with us.");

api.setContent(OrderNotifyMsg);

 

// Or, use the message composition services (compose()) by passing the 
template/view name

// This view name should be registered in VIEWREG and MSGTYPES tables referring 
to

// a JSP message layout template.

String viewName = new String("OrderNotifyMsgView");

TypedProperty tp = null;

// Pass the viewName, command Context and null parameter stored in tp to compose 
services.

// Upon successful completion, a message is build according to message layout 
defined in the

// JSP message layout template referred by viewName.

api.compose(viewName, getCommandContext(), tp);

 

// Set the subject, recipient and sender information using Configurable message 
data services

api.setConfigData("subject","Your Order has been received");

api.setConfigData("recipient",getEmailAddress());

api.setConfigData("sender","storeAdmin@storeABC.com);

// Send out the message using sendImmediate send service.

api.sendImmediate();

// Set the command context obtained from the controller command.

api.setCommandContext(getCommandContext());

// Run the outbound messaging system services

api.execute();

}

catch (Exception ex )

{

ex.printStackTrace(System.err);