Thursday, November 24, 2011

MML with Java

A man-machine language or MML is a specification language. MML typically are defined to standardize the interfaces for managing a telecommunications or network device from a console.
If you are using on java below code sample helpful to MML utilisation with java.

This class used to get subscriber's account info


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.io.*;
import java.net.UnknownHostException;

public class MMLCommandGen{

/**
* @param args
*/
Socket inSocket = null;
//PrintWriter out = null;
BufferedOutputStream out1 = null;
BufferedReader in = null;
public static String strStartFlag="`SC`"; //4 bytes

String strMsgHeader=""; //28 bytes

public static String hdVrsnNo="1.02"; //4 bytes
static String hdTrmnlId="internal"; //8 bytes
String hdSrvcName="SRVM"; //8 bytes
static String hdLangType="english"; //8 bytes

String strSsnHeader=""; //18 bytes

String ssnId="";//8 bytes
String ssnCtrlChar="DLGLGN";//6 bytes
static String ssnRsrvdFld="0000";//4 bytes

String strTxnHeader=""; //18 bytes

String txnId="1";//8 bytes
String txnCtrlChar="TXBEG";//6 bytes
//static String txnRsrvdFld="00";//4 bytes
static String txnRsrvdFld="0000";//4 bytes

int msgLenth=0;
String strMsgLength=""; //4 bytes


String strOprInfo="DISP PPS ACNTINFO:MSISDN=0000000000"; //upto 64kb

String strChkSum=""; //8 bytes

String inCommand="";

public String getHdLangType() {
return hdLangType;
}

public static void setHdLangType(String LangType) {
int hdLangTypeLnth=LangType.length();
for (int i=0;i<8-hdLangTypeLnth; i++){
LangType=" "+LangType;
}
hdLangType = LangType;
}

public String getHdSrvcName() {
return hdSrvcName;
}

public void setHdSrvcName(String hdSrvcName) {
int hdSrvcNameLnth=hdSrvcName.length();
for (int i=0;i<8-hdSrvcNameLnth; i++){
hdSrvcName=" "+hdSrvcName;
}
this.hdSrvcName = hdSrvcName;
}

public String getHdTrmnlId() {
return hdTrmnlId;
}

public static void setHdTrmnlId(String hdTmnlId) {
int hdTrmnlIdLnth=hdTmnlId.length();
for (int i=0;i<8-hdTrmnlIdLnth; i++){
hdTmnlId=" "+hdTmnlId;
}
hdTrmnlId = hdTmnlId;
}

public String getHdVrsnNo() {
return hdVrsnNo;
}

public void setHdVrsnNo(String hdVrsnNo) {
this.hdVrsnNo = hdVrsnNo;
}

public String getStrMsgHeader() {
return strMsgHeader;
}

public void setStrMsgHeader(String hdSrvcName) {
setHdSrvcName(hdSrvcName);
this.strMsgHeader =hdVrsnNo+hdTrmnlId+this.hdSrvcName+hdLangType;
}

public String getSsnCtrlChar() {
return ssnCtrlChar;
}

public void setSsnCtrlChar(String ssnCtrlChar) {
int ssnCtrlCharLnth=ssnCtrlChar.length();
for (int i=0;i<6-ssnCtrlCharLnth; i++){
ssnCtrlChar=" "+ssnCtrlChar;
}
this.ssnCtrlChar = ssnCtrlChar;
}

public String getSsnId() {
return ssnId;
}

public void setSsnId(String ssnId) {
int ssnIdLnth=ssnId.length();
for (int i=0;i<8-ssnIdLnth; i++){//=(8-)
ssnId="0"+ssnId;
}
this.ssnId = ssnId;
}

public String getSsnRsrvdFld() {
return ssnRsrvdFld;
}

public static void setSsnRsrvdFld(String rsrvdFld) {
int ssnRsrvdFldLnth=rsrvdFld.length();
for (int i=0;i<4-ssnRsrvdFldLnth; i++){
rsrvdFld="0"+rsrvdFld;
}
ssnRsrvdFld = rsrvdFld;
}

public String getStrSsnHeader() {
return strSsnHeader;
}

public void setStrSsnHeader(String ssnId,String ssnCtrlChar) {
setSsnId(ssnId);
setSsnCtrlChar(ssnCtrlChar);
this.strSsnHeader=this.ssnId+this.ssnCtrlChar+ssnRsrvdFld;
}

public String getStrTxnHeader() {
return strTxnHeader;
}

public void setStrTxnHeader(String txnId,String txnCtrlChar,String txnRsrvdFld) {
setTxnId(txnId);
setTxnCtrlChar(txnCtrlChar);
setTxnRsrvdFld(txnRsrvdFld);
this.strTxnHeader =this.txnId+this.txnCtrlChar+this.txnRsrvdFld;
}

public String getTxnCtrlChar() {
return txnCtrlChar;
}

public void setTxnCtrlChar(String txnCtrlChar) {
int txnCtrlCharLnth=txnCtrlChar.length();
for (int i=0;i<6-txnCtrlCharLnth; i++){
txnCtrlChar=" "+txnCtrlChar;
}
this.txnCtrlChar = txnCtrlChar;
}

public String getTxnId() {
return txnId;
}

public void setTxnId(String txnId) {
int txnIdLnth=txnId.length();
for (int i=0;i<8-txnIdLnth; i++){
txnId="0"+txnId;
}
this.txnId = txnId;
}

public String getTxnRsrvdFld() {
return txnRsrvdFld;
}

public static void setTxnRsrvdFld(String tRsrvdFld) {
int txnRsrvdFldLnth=tRsrvdFld.length();
for (int i=0;i<4-txnRsrvdFldLnth; i++){
tRsrvdFld="0"+tRsrvdFld;
}
txnRsrvdFld = tRsrvdFld;
}

public int getMsgLenth() {
return msgLenth;
}

public void setMsgLenth(int msgLenth) {
this.msgLenth = strMsgHeader.length()+strSsnHeader.length()+strTxnHeader.length()+strOprInfo.length();
}

public String getStrOprInfo() {
return strOprInfo;
}

public void setStrOprInfo(String strOprInfo) {
int strOprInfoLnth=strOprInfo.length()%4;
for (int i=0;i<4-strOprInfoLnth; i++){
strOprInfo=strOprInfo+" ";
}
this.strOprInfo = strOprInfo;
}

public String getStrMsgLength() {
return strMsgLength;
}

public void setStrMsgLength() {
msgLenth = strMsgHeader.length()+strSsnHeader.length()+strTxnHeader.length()+strOprInfo.length();
this.strMsgLength = Integer.toHexString(0x10000|msgLenth).substring(1).toUpperCase();
}

public String getStrChkSum() {
return strChkSum;
}

public void setStrChkSum() {

StringBuffer chkSumSb = new StringBuffer(strMsgHeader+strSsnHeader+strTxnHeader+strOprInfo);

char []res=new char[4];

for (int j = 0; j < res.length; j++) {
for (int i = j; i < chkSumSb.length(); i = i + 4) {
res[j] = (char) (res[j] ^ chkSumSb.charAt(i));
}
res[j] = (char) ((~res[j]) & 0x00ff);
}

strChkSum="";

for(int i =0;i<4;i++){
strChkSum=strChkSum+Integer.toHexString((int)res[i]);
}
this.strChkSum=strChkSum.toUpperCase();
}

public String getInCommand() {
return inCommand;
}

public void setInCommand() {
System.out.println("strStartFlag+strMsgLength+strMsgHeader+strSsnHeader+strTxnHeader+strOprInfo+strChkSum"+strSsnHeader+strTxnHeader);
this.inCommand = strStartFlag+strMsgLength+strMsgHeader+strSsnHeader+strTxnHeader+strOprInfo+strChkSum;
}

public void setInCommand(String cmd) {
this.inCommand = cmd;
}

public void setSocketConnection()throws UnknownHostException,IOException{

inSocket = new Socket("127.0.0.1",8080);
}

public void socketWriter(String command)throws IOException{

out1 = new BufferedOutputStream(inSocket.getOutputStream());
OutputStreamWriter out = new OutputStreamWriter(out1, "US-ASCII");
out.write(getInCommand());

out.close();
}

public String socketReader()throws IOException{
String resp="";

in = new BufferedReader(new InputStreamReader(inSocket.getInputStream()));

resp=in.readLine();

return resp;
}



}

14 comments:

  1. Would be great to have a usage case... would you mind?

    ReplyDelete
  2. usage case mean?sorry i didn't get

    ReplyDelete
  3. usage case mean an example of main program using that Class

    ReplyDelete
  4. i just used for mobile billing server communication with my web application.

    ReplyDelete
  5. Yes example will be wellcommed...

    ReplyDelete
  6. Could you explain your specifications for MML too which were provided to you by your service provider? Secondly, can this client work with a server accepting TCP/IP connections and is written in .NET? What would be the call sequence in your client case as you built a kind of utility class which generates your input you need to send to your server. Please elaborate further as its a very little-explored/documented topic on the web.

    ReplyDelete
  7. Hi Aruna, this is very helpful

    Can you email me at saad@reticlesystems.com, need to talk to you about a potential integeration you might be able to build for us with MML Command and Charging system

    Please let me know

    Thanks.

    ReplyDelete
  8. Hi Aruna,

    I was checking this blog and need to develop a simple billing application using MML language. It would be really helpful to me if you share sample program to my mail id i.e. parichaya1984@gmail.com . Also, can you provide me document on how acutally MML works as i am new on MML language.

    Regards,

    Parichaya

    ReplyDelete
  9. Hi Dear,
    I also need to develop a billing application using MML in PHP so is there any one to share a sample code in php please!? Really appreciated!


    Best Regards,
    MahPari

    ReplyDelete
  10. Hello Dear,

    Can you please guide, how do we call these method and on which sequence.

    ReplyDelete
  11. Hi Aruna

    Could you please share billing integration code with MML interface. gyan.bhatnagar@gmail.com

    ReplyDelete
    Replies
    1. Can you help me..its critical for me.. thx in advance

      Delete