Runtime components : Channels components : SMS handler : Request handler : Channel policy
  
Channel policy
The request handler checks the channel policy framework to determine whether the request is permitted or not. The channel policy framework provides following embedded rule checking mechanism:
1 Rule Provider connector service that aligns with the UNICOM® Digital Transformation Toolkit (UDTT™) service architecture.
2 Global rule check mechanism: Application can define global business rule for all channel request. The channel driver rejects the request when rule check is not passed.
3 Operation Step level rule check mechanism: For specific transaction operation, UDTT provides abstract ruleCheckOpStep class which can be used by application. For example, add a transferLimitCheck operation step for transfer operation. RuleCheckOpStep supports to define the referenced rule provide service, and the data map definition to map context data to rule parameter.
Note All the rule check mechanism can be defined by XML configuration. Application only needs to implement the rule provider service by Java code or by ILog, and handle the input/output of the rule service.
Example
To configure the channel policy into SMS, you should add the channel policy handler and rule service into the SMS channel configuration in file btt.xml. Following is an example for the configuration:
<kColl id="sms">
<field id="encoding" value="UTF-8"/>
<field id="requestHandler"
value="com.ibm.btt.channel.sms.SMSRequestHandler"/>
<field id="presentationHandler"
value="com.ibm.btt.channel.sms.SMSPresentationHandler"/>
<!-- channel policy configuration --> <field id="channelPolicyHandler" value="com.ibm.btt.test.MyChannelPolicyHandler"/> <field id="ruleService" value="javaCodeChannelRuleService"/></kColl>
In this example, the rule service javaCodeChannelRuleService should be configured in service definition file:
<service.xml>
<com.ibm.btt.test.JavaCodeChannelRuleService
id="javaCodeChannelRuleService"/>

</service.xml>
The implementation class of channel policy handler com.ibm.btt.test.MyChannelPolicyHandler should extend “com.ibm.btt.channel.AbstractChannelPolicy” and override the two methods: protected Map<String> getInputParameter(ChannelContext ctx) and protected PolicyResult processResult(Map<String> resultMap). Following is the example code:
package com.ibm.btt.test;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import com.ibm.btt.channel.AbstractChannelPolicy;
import com.ibm.btt.channel.PolicyResult;
import com.ibm.btt.clientserver.ChannelContext;
public class MyChannelPolicyHandler extends AbstractChannelPolicy {
private PolicyResult result;
@Override
protected Map<String> getInputParameter(ChannelContext ctx) {
Map<String> input = new HashMap<String>();
result = new PolicyResult();
ChannelPolicyData data = new ChannelPolicyData();
data.setDeviceType(ctx.getDeviceType());
data.setNow(Calendar.getInstance());
input.put("data", data);
input.put("result", result);
return input;
}
@Override
protected PolicyResult processResult(Map<String> resultMap) {
return result; }
}
The implementation class of channel rule service com.ibm.btt.test.JavaCodeChannelRuleServiceshould extend com.ibm.btt.channel.ruleprovider.java.JavaCodeRuleProviderService, and override the method public Map<String> checkRule(Map<String> params). Following is the example code:
package com.ibm.btt.test;
import java.util.Calendar;
import java.util.Map;
import com.ibm.btt.channel.PolicyResult;
import com.ibm.btt.channel.ruleprovider.java.JavaCodeRuleProviderService;
public class JavaCodeChannelRuleService extends JavaCodeRuleProviderService {
public Map<String> checkRule(Map<String> params)
{
System.out.println("JavaCodeChannelRuleService: checking the channel rule...");
PolicyResult result = (PolicyResult) params.get("result");
ChannelPolicyData data = (ChannelPolicyData) params.get("data");
Calendar now = data.getNow();
int hours = now.get(Calendar.HOUR_OF_DAY);
if (hours >= 20 || hours < 9) {
result.reject();
String message = "The Internet Bank is just opening for 9:00-20:00, please try later.”;
result.addToMessages(message);
}
System.out.println("JavaCodeChannelRuleService: the result message is:" + result.getMessages());
return null; }
}
Go up to
Request handler