Outbound Message Handler is a utility class that send message to SMS. Following is the Outbound Message Handler interface:
public interface OutBoundMessageHandler { /** * @param message object to be sent * @return message ID return from SMS Gateway, * it can be used to query DLR status * @throws SMSHandlerException */ public String sendMessage(Object message, String toNumber) throws SMSHandlerException; }
BTT provides one default implementation in the class com.ibm.btt.channel.sms.outbound.BTTOutboundMessageHandler, the application can use the sendMessage() API directly to send SMS message.
Following is the Outbound Message Handler configuration:
ParameterNames Configuration:
Following is an example for Outbound Message Handler configuration in application/x-www-form-urlencoded type:
https://gateway-server:port/api?action=sendmessage&messagetype=SMS:TEXT&username=user01&password=password&recipient=13651033060&messagedata=FT user01 payee01 399.99
<com.ibm.btt.test.ExtendOutboundMessageHandler id="formoutbound"> <com.ibm.btt.channel.sms.config.OutboundHandlerConfiguration Injection="config" hostName="yourgatewayserver" port="9501" programName="api?action=sendmessage" account="tester2" password="q1w2e3r4" xmlHttp="false" httpsEnabled="false" encoding="utf-8" from="13720059660"> <com.ibm.btt.channel.sms.config.ParameterNames Injection="parameterNames" accountParamName="username" passwordParamName="password" messageParamName="messagedata" toParamName="recipient" fromParamName="sender"> <ref Injection="dlrConfig" refId="formDLR"> <map Injection="selfDefineParameters"> <entry key="messagetype" value="SMS:TEXT"> </entry></map> </ref></com.ibm.btt.channel.sms.config.ParameterNames></com.ibm.btt.channel.sms.config.OutboundHandlerConfiguration></com.ibm.btt.test.ExtendOutboundMessageHandler><?Pub Caret?>
Following is an example for Outbound Message Handler configuration in xml/text type:
Example of HTTP content in XML/HTTP type:
<MTRequest> <Usuario>xxxx</Usuario> <Password>yyyyy</Password> <Servicio> nnnn.operador.pais</Servicio> <MSISDN>+8613980949473</MSISDN> <ContentType>0</ContentType> <Contenido>message content</Contenido> <Fecha>yyyy-MM-dd hh:mm:ss</Fecha> <IdCliente>yyyyy</IdCliente> </MTRequest>
Example of Outbound Handler Configuration:
<com.ibm.btt.test.MovilgateOutboundMessageHandler id="xmlOutbound"> <com.ibm.btt.channel.sms.OutboundHandlerConfiguration Injection="config" xmlHttp="true" hostName="localhost" port="9084" programName="MEPWeb/servlet/MovilgateInboundMessageHandler" account=""> <map Injection="selfDefineParameters"> <entry key="ContentType" value="0"></entry> <entry key="Servicio" value="nnnn.operador.pais"></entry> </map> <ref Injection="dlrConfig" refId="xmlDLR"/> <com.ibm.btt.channel.sms.config.OutboundHandlerConfiguration></com.ibm.btt.channel.sms.config.OutboundHandlerConfiguration> </com.ibm.btt.channel.sms.OutboundHandlerConfiguration></com.ibm.btt.test.MovilgateOutboundMessageHandler>
protected String getContent(Object message , String toNumber)In the example above in xml/text type, the extension Outbound Message Handler implementation class is com.ibm.btt.test.MovilgateOutboundMessageHandler, following is the example code:
package com.ibm.btt.test; import java.util.Iterator; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import com.ibm.btt.channel.sms.outbound.BTTOutboundMessageHandler; public class MovilgateOutboundMessageHandler extends BTTOutboundMessageHandler { private static SAXParserFactory sf; private static SAXParser saxp; @Override protected String getContent(Object message, String toNumber) { StringBuilder sb = new StringBuilder(); sb.append(" "); sb.append("<MTRequest>"); sb.append("<Usuario>"); sb.append(getConfig().getAccount()); sb.append("</Usuario>"); sb.append("<Password>"); sb.append(getConfig().getPassword()); sb.append("</Password>"); sb.append("<MSISDN>"); sb.append(toNumber); sb.append("</MSISDN>"); sb.append("<contenido>"); sb.append(message); sb.append("</contenido>"); // add self-defined parameters if (getConfig().getSelfDefineParameters() != null) { Iterator it = getConfig().getSelfDefineParameters().keySet() .iterator(); while (it.hasNext()) { String paramName = (String) it.next(); String paramValue = (String) getConfig() .getSelfDefineParameters().get(paramName); sb.append("<" + paramName + ">"); sb.append(paramValue); sb.append("</" + paramName + ">"); } } sb.append("</MTRequest>"); return sb.toString(); } }BTTOutboundMessageHandler provides a default implementation to handle the outbound response from gateway that indicates whether the outbound message sending request is accepted or rejected by gateway. It uses the DLR Configuration to parse the response data and store the delivery status by DLRStore interface. For more information, see Delivery report handler. In most cases, the default implementation can fulfill the requirements. Anyway, the application can extend the default implementation method for special requirements.
To extend the response handling, you can extend the class com.ibm.btt.channel.sms.outbound.BTTOutboundMessageHandler and override the following method:
protected String handleResponseData(InputStream responseStream, String toNumber)