diff --git a/AF-Demo/.classpath b/AF-Demo/.classpath new file mode 100644 index 0000000..8e77e9a --- /dev/null +++ b/AF-Demo/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/AF-Demo/.project b/AF-Demo/.project new file mode 100644 index 0000000..10f2979 --- /dev/null +++ b/AF-Demo/.project @@ -0,0 +1,17 @@ + + + AFDemo + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/AF-Demo/.settings/org.eclipse.jdt.core.prefs b/AF-Demo/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..148aba0 --- /dev/null +++ b/AF-Demo/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Tue Feb 11 08:46:18 ICT 2014 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/AF-Demo/bin/.gitignore b/AF-Demo/bin/.gitignore new file mode 100644 index 0000000..3ca62b4 --- /dev/null +++ b/AF-Demo/bin/.gitignore @@ -0,0 +1 @@ +/af/ diff --git a/AF-Demo/conf/AF_E01_20131111 b/AF-Demo/conf/AF_E01_20131111 new file mode 100644 index 0000000..5572ad0 --- /dev/null +++ b/AF-Demo/conf/AF_E01_20131111 @@ -0,0 +1 @@ +DATA<0>TEST<1>def<2>def<3>def<4>defSUCCESS diff --git a/AF-Demo/conf/af/AF.E00.x.0 b/AF-Demo/conf/af/AF.E00.x.0 new file mode 100644 index 0000000..6d5e486 --- /dev/null +++ b/AF-Demo/conf/af/AF.E00.x.0 @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/af/AF.E01.0.0 b/AF-Demo/conf/af/AF.E01.0.0 new file mode 100644 index 0000000..d140b40 --- /dev/null +++ b/AF-Demo/conf/af/AF.E01.0.0 @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/af/AF.E11.0.0 b/AF-Demo/conf/af/AF.E11.0.0 new file mode 100644 index 0000000..37fd9bc --- /dev/null +++ b/AF-Demo/conf/af/AF.E11.0.0 @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/af/AF.E11.0.1 b/AF-Demo/conf/af/AF.E11.0.1 new file mode 100644 index 0000000..e0ff524 --- /dev/null +++ b/AF-Demo/conf/af/AF.E11.0.1 @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/af/AF.EC02.AF.0 b/AF-Demo/conf/af/AF.EC02.AF.0 new file mode 100644 index 0000000..a81838b --- /dev/null +++ b/AF-Demo/conf/af/AF.EC02.AF.0 @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/af/AF.ES00.0.0 b/AF-Demo/conf/af/AF.ES00.0.0 new file mode 100644 index 0000000..5b85583 --- /dev/null +++ b/AF-Demo/conf/af/AF.ES00.0.0 @@ -0,0 +1,44 @@ + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/af/AF.ES04.A.0 b/AF-Demo/conf/af/AF.ES04.A.0 new file mode 100644 index 0000000..c0726c7 --- /dev/null +++ b/AF-Demo/conf/af/AF.ES04.A.0 @@ -0,0 +1,43 @@ + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/af/AF.ES05.SERV.0 b/AF-Demo/conf/af/AF.ES05.SERV.0 new file mode 100644 index 0000000..2cb6f42 --- /dev/null +++ b/AF-Demo/conf/af/AF.ES05.SERV.0 @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/af_testamentor.so b/AF-Demo/conf/af_testamentor.so new file mode 100644 index 0000000..a883180 Binary files /dev/null and b/AF-Demo/conf/af_testamentor.so differ diff --git a/AF-Demo/conf/testamentor/gw.E00.x.0 b/AF-Demo/conf/testamentor/gw.E00.x.0 new file mode 100644 index 0000000..dc6569a --- /dev/null +++ b/AF-Demo/conf/testamentor/gw.E00.x.0 @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/testamentor/gw.E11.0.0 b/AF-Demo/conf/testamentor/gw.E11.0.0 new file mode 100644 index 0000000..8951bcf --- /dev/null +++ b/AF-Demo/conf/testamentor/gw.E11.0.0 @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/testamentor/gw.EC00.0.0 b/AF-Demo/conf/testamentor/gw.EC00.0.0 new file mode 100644 index 0000000..4ba70dd --- /dev/null +++ b/AF-Demo/conf/testamentor/gw.EC00.0.0 @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/testamentor/gw.ES00.0.0 b/AF-Demo/conf/testamentor/gw.ES00.0.0 new file mode 100644 index 0000000..92d0a32 --- /dev/null +++ b/AF-Demo/conf/testamentor/gw.ES00.0.0 @@ -0,0 +1,44 @@ + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/testamentor/gw.ES04.AF.0 b/AF-Demo/conf/testamentor/gw.ES04.AF.0 new file mode 100644 index 0000000..e05ea62 --- /dev/null +++ b/AF-Demo/conf/testamentor/gw.ES04.AF.0 @@ -0,0 +1,43 @@ + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/testamentor/gw.ES04.INJ.0 b/AF-Demo/conf/testamentor/gw.ES04.INJ.0 new file mode 100644 index 0000000..1ef3a73 --- /dev/null +++ b/AF-Demo/conf/testamentor/gw.ES04.INJ.0 @@ -0,0 +1,45 @@ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/testamentor/gw.ES05.INJ.0 b/AF-Demo/conf/testamentor/gw.ES05.INJ.0 new file mode 100644 index 0000000..78618fb --- /dev/null +++ b/AF-Demo/conf/testamentor/gw.ES05.INJ.0 @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/conf/testamentor/gw.ES05.SERV.0 b/AF-Demo/conf/testamentor/gw.ES05.SERV.0 new file mode 100644 index 0000000..c430d77 --- /dev/null +++ b/AF-Demo/conf/testamentor/gw.ES05.SERV.0 @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AF-Demo/lib/XMLParser.jar b/AF-Demo/lib/XMLParser.jar new file mode 100644 index 0000000..b767194 Binary files /dev/null and b/AF-Demo/lib/XMLParser.jar differ diff --git a/AF-Demo/lib/af_demo.jar b/AF-Demo/lib/af_demo.jar new file mode 100644 index 0000000..7aafce3 Binary files /dev/null and b/AF-Demo/lib/af_demo.jar differ diff --git a/AF-Demo/lib/af_demo_oam.jar b/AF-Demo/lib/af_demo_oam.jar new file mode 100644 index 0000000..feb7023 Binary files /dev/null and b/AF-Demo/lib/af_demo_oam.jar differ diff --git a/AF-Demo/lib/ec02_library_V3.2.0.jar b/AF-Demo/lib/ec02_library_V3.2.0.jar new file mode 100644 index 0000000..9bbd8a4 Binary files /dev/null and b/AF-Demo/lib/ec02_library_V3.2.0.jar differ diff --git a/AF-Demo/lib/gson-2.2.2.jar b/AF-Demo/lib/gson-2.2.2.jar new file mode 100644 index 0000000..f2108e0 Binary files /dev/null and b/AF-Demo/lib/gson-2.2.2.jar differ diff --git a/AF-Demo/src/af/control/AFMain.java b/AF-Demo/src/af/control/AFMain.java new file mode 100644 index 0000000..996ffad --- /dev/null +++ b/AF-Demo/src/af/control/AFMain.java @@ -0,0 +1,141 @@ +package af.control; + +import java.util.ArrayList; +import com.google.gson.Gson; +import af.instatnce.AFInstance; +import af.instatnce.EC02Instance; +import af.interfaces.AFEvent; +import af.utils.Zip; +import ec02.af.abstracts.AbstractAF; +import ec02.af.data.ECDialogue; +import ec02.af.data.EquinoxProperties; +import ec02.af.data.EquinoxRawData; +import ec02.af.exception.ActionProcessException; +import ec02.af.exception.ComposeInstanceException; +import ec02.af.exception.ConstructRawDataException; +import ec02.af.exception.ExtractInstanceException; +import ec02.af.exception.ExtractRawDataException; +import ec02.interfaces.IEC02; +import ec02.utils.AppLog; +import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; + +public class AFMain extends AbstractAF implements IEC02{ + + @Override + public ECDialogue actionProcess(EquinoxProperties eqxProp, ArrayList eqxRawDataList, Object instance) + throws ActionProcessException { + + AppLog.i("[CURRENT STATE] : " + eqxProp.getState()); + EC02Instance ec02Ins = (EC02Instance) instance; + ec02Ins.setEquinoxProperties(eqxProp); + ec02Ins.setAbstractAF((AbstractAF) this); + StateManager sm = new StateManager(eqxProp.getState()); + String eqxState = sm.doAction((AbstractAF) this, ec02Ins, eqxRawDataList); + EquinoxProperties newEqxProp = new EquinoxProperties(); + newEqxProp.setState(eqxState); + AppLog.i("[NEXT STATE] : " + eqxState); + newEqxProp.setTimeout(ec02Ins.getTimeout()); + AppLog.i("[TIMEOUT] : " + ec02Ins.getTimeout()); + ECDialogue ecDialogue = new ECDialogue(newEqxProp, ec02Ins); + + return ecDialogue; + } + + @Override + public boolean verifyAFConfiguration(String arg0) { + return true; + } + + @Override + public String composeInstance(Object instance) throws ComposeInstanceException { + EC02Instance ec02Instance = (EC02Instance) instance; + AFInstance afInstance = ec02Instance.getAFInstance(); + String encodeString = ""; + + try { + encodeString = encodeInstance(afInstance); + } + catch (Exception e) { + e.printStackTrace(); + } + + return encodeString; + } + + @Override + public ArrayList constructRawData(Object instance) + throws ConstructRawDataException { + EC02Instance ins = (EC02Instance) instance; + return ins.getEqxRawDataList(); + } + + @Override + public Object extractInstance(String instance) throws ExtractInstanceException { + EC02Instance ec02Instance = new EC02Instance(); + AFInstance afInstance = null; + + if ((instance == null) || instance.isEmpty()) { + afInstance = new AFInstance(); + } + else { + try { + afInstance = decodeInstance(instance); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + ec02Instance.setAFInstance(afInstance); + return (Object) ec02Instance; + } + + @Override + public void extractRawData(Object instanceData, ArrayList rawDatas) + throws ExtractRawDataException { + + for (EquinoxRawData r : rawDatas) { + String type = r.getRawDataAttribute("type"); + String ctype = r.getRawDataAttribute("ctype"); + + if(r.getRawEventType().equals(AFEvent.Unknown)){ + if(ctype.equals("text/plain") && type.equals("request")) { + r.setRawMessage(r.getRawDataAttribute("val").trim()); + r.setRawEventType(AFEvent.Incoming_HTTP_Request); + } + else if(ctype.equals("text/xml") && type.equals("response")) { + r.setRawEventType(AFEvent.Incoming_A_Response); + } + } + AppLog.i("[EVENT TYPE] : " + r.getRawEventType()); + } + } + + private String encodeInstance(AFInstance instance) { + String encodeString = ""; + try { + Gson gson = new Gson(); + String str = gson.toJson(instance); + byte[] bytes = str.getBytes(); + byte[] zipBytes = Zip.compressBytes(bytes); + encodeString = Base64.encode(zipBytes); + } + catch (Exception e) { + AppLog.e("Encode fail!! " + e); + } + return encodeString; + } + + private AFInstance decodeInstance(String instance) { + AFInstance afInstance = null; + try { + byte[] simpleString = Base64.decode(instance); + byte[] unZipString = Zip.extractBytes(simpleString); + Gson gson = new Gson(); + afInstance = gson.fromJson(new String(unZipString), AFInstance.class); + } catch (Exception e) { + AppLog.e("Decode fail!! " + e); + } + return afInstance; + } +} diff --git a/AF-Demo/src/af/control/StateManager.java b/AF-Demo/src/af/control/StateManager.java new file mode 100644 index 0000000..95ffc2d --- /dev/null +++ b/AF-Demo/src/af/control/StateManager.java @@ -0,0 +1,22 @@ +package af.control; + +import af.interfaces.AFState; +import af.state.StateIdle; +import af.state.StateWaitE01; +import af.state.StateWaitA; +import ec02.af.abstracts.AbstractAFStateManager; + +public class StateManager extends AbstractAFStateManager { + public StateManager(String state) { + this.afState = null; + if (state.equals(AFState.IDLE)) { + this.afState = new StateIdle(); + } + else if (state.equals(AFState.W_E01Res)) { + this.afState = new StateWaitE01(); + } + else if (state.equals(AFState.W_ARes)) { + this.afState = new StateWaitA(); + } + } +} diff --git a/AF-Demo/src/af/instatnce/AFInstance.java b/AF-Demo/src/af/instatnce/AFInstance.java new file mode 100644 index 0000000..83c13d4 --- /dev/null +++ b/AF-Demo/src/af/instatnce/AFInstance.java @@ -0,0 +1,23 @@ +package af.instatnce; + +public class AFInstance { + + private String orig = ""; + private String invoke = ""; + + + public String getOrig(){ + return this.orig; + } + public void setOrig(String orig){ + this.orig = orig; + } + public void setInvoke(String invoke) { + this.invoke = invoke; + } + public String getInvoke(){ + return this.invoke; + } + + +} diff --git a/AF-Demo/src/af/instatnce/E01Instance.java b/AF-Demo/src/af/instatnce/E01Instance.java new file mode 100644 index 0000000..9b9e8a2 --- /dev/null +++ b/AF-Demo/src/af/instatnce/E01Instance.java @@ -0,0 +1,42 @@ +package af.instatnce; + +import java.util.ArrayList; + +public class E01Instance { + private String cmd = ""; + private String objType = ""; + private String data = ""; + private String id = ""; + private ArrayList key = null; + + public String getCmd() { + return cmd; + } + public void setCmd(String cmd) { + this.cmd = cmd; + } + public String getObjType() { + return objType; + } + public void setObjType(String objType) { + this.objType = objType; + } + public String getData() { + return data; + } + public void setData(String data) { + this.data = data; + } + public ArrayList getKey() { + return key; + } + public void setKey(ArrayList key) { + this.key = key; + } + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } +} diff --git a/AF-Demo/src/af/instatnce/EC02Instance.java b/AF-Demo/src/af/instatnce/EC02Instance.java new file mode 100644 index 0000000..baaaa3e --- /dev/null +++ b/AF-Demo/src/af/instatnce/EC02Instance.java @@ -0,0 +1,67 @@ +package af.instatnce; + +import java.util.ArrayList; + +import ec02.af.abstracts.AbstractAF; +import ec02.af.data.EquinoxProperties; +import ec02.af.data.EquinoxRawData; + +public class EC02Instance { + private String orig = ""; + private String timeout = ""; + private String e01data = ""; + private ArrayList eqxRawDataList = null; + private AFInstance afIns = null; + private EquinoxProperties eqxProp = null; + private AbstractAF abstractAF = null; + private E01Instance e01Ins = null; + + public String getOrig() { + return orig; + } + public void setOrig(String orig) { + this.orig = orig; + } + public String getTimeout() { + return timeout; + } + public void setTimeout(String timeout) { + this.timeout = timeout; + } + public ArrayList getEqxRawDataList() { + return eqxRawDataList; + } + public void setEqxRawDataList(ArrayList eqxRawDataList) { + this.eqxRawDataList = eqxRawDataList; + } + public AFInstance getAFInstance() { + return afIns; + } + public void setAFInstance(AFInstance afIns) { + this.afIns = afIns; + } + public EquinoxProperties getEquinoxProperties() { + return eqxProp; + } + public void setEquinoxProperties(EquinoxProperties eqxProp) { + this.eqxProp = eqxProp; + } + public AbstractAF getAbstractAF() { + return abstractAF; + } + public void setAbstractAF(AbstractAF abstractAF) { + this.abstractAF = abstractAF; + } + public String getE01data() { + return e01data; + } + public void setE01data(String e01data) { + this.e01data = e01data; + } + public E01Instance getE01Ins() { + return e01Ins; + } + public void setE01Ins(E01Instance e01Ins) { + this.e01Ins = e01Ins; + } +} diff --git a/AF-Demo/src/af/instatnce/EQXRawInstance.java b/AF-Demo/src/af/instatnce/EQXRawInstance.java new file mode 100644 index 0000000..8cfaf65 --- /dev/null +++ b/AF-Demo/src/af/instatnce/EQXRawInstance.java @@ -0,0 +1,54 @@ +package af.instatnce; + +public class EQXRawInstance { + private String to = null; + private String type = null; + private String ctype = null; + private String oid = null; + private String uri = null; + private String ecode = null; + private String message = null; + + public String getTo() { + return to; + } + public void setTo(String to) { + this.to = to; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getCtype() { + return ctype; + } + public void setCtype(String ctype) { + this.ctype = ctype; + } + public String getOid() { + return oid; + } + public void setOid(String oid) { + this.oid = oid; + } + public String getUri() { + return uri; + } + public void setUri(String uri) { + this.uri = uri; + } + public String getEcode() { + return ecode; + } + public void setEcode(String ecode) { + this.ecode = ecode; + } + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } +} diff --git a/AF-Demo/src/af/interfaces/AFEvent.java b/AF-Demo/src/af/interfaces/AFEvent.java new file mode 100644 index 0000000..4fa983e --- /dev/null +++ b/AF-Demo/src/af/interfaces/AFEvent.java @@ -0,0 +1,11 @@ +package af.interfaces; + +public interface AFEvent { + public String Unknown ="Unknown"; + public String Incoming_HTTP_Request ="Incoming HTTP Request"; + public String TEST ="TEST"; + public String Incoming_A_Response ="Incoming A Response"; + public String ERROR = "EQUINOX_EVENT_ERROR"; + public String REJECT = "EQUINOX_EVENT_REJECT"; + public String ABORT = "EQUINOX_EVENT_ABORT"; +} diff --git a/AF-Demo/src/af/interfaces/AFState.java b/AF-Demo/src/af/interfaces/AFState.java new file mode 100644 index 0000000..63f5cca --- /dev/null +++ b/AF-Demo/src/af/interfaces/AFState.java @@ -0,0 +1,7 @@ +package af.interfaces; + +public interface AFState { + public String IDLE = "IDLE"; + public String W_E01Res = "W_DBRes"; + public String W_ARes = "W_ARes"; +} diff --git a/AF-Demo/src/af/interfaces/EQXMsg.java b/AF-Demo/src/af/interfaces/EQXMsg.java new file mode 100644 index 0000000..a919b9b --- /dev/null +++ b/AF-Demo/src/af/interfaces/EQXMsg.java @@ -0,0 +1,39 @@ +package af.interfaces; + +public interface EQXMsg { + public String ORIG = "orig"; + + public String INVOKE = "invoke"; + public String TYPE = "type"; + public String CTYPE = "ctype"; + public String NAME = "name"; + public String OID = "oid"; + public String VAL = "val"; + public String ECODE = "ecode"; + + public String OID_CODE = ""; + + //type + public String REQUEST = "request"; + public String RESPONSE = "response"; + + //http + public String HTTP = "HTTP"; + public String TEXTPLAIN = "text/plain"; + public String TEXTXML = "text/xml"; + public String TEXTHTML = "text/html"; + + //ldap + public String LDAP = "LDAP"; + public String SEARCH = "search"; + public String MODIFY = "modify"; + public String DELETE = "delete"; + public String EXTENDED = "extended"; + public String EXECUTE = "execute"; + + //smpp + public String SMPP = "SMPP"; + + //diameter + public String DIAMETER = "DIAMETER"; +} diff --git a/AF-Demo/src/af/message/EC02Builder.java b/AF-Demo/src/af/message/EC02Builder.java new file mode 100644 index 0000000..14b373a --- /dev/null +++ b/AF-Demo/src/af/message/EC02Builder.java @@ -0,0 +1,143 @@ +package af.message; + +import java.util.ArrayList; +import af.instatnce.EC02Instance; +import af.instatnce.EQXRawInstance; +import af.interfaces.EQXMsg; +import ec02.af.abstracts.AbstractAF; +import ec02.af.data.EquinoxRawData; +import ec02.af.data.KeyObject; + +public class EC02Builder { + private EC02Instance ec02Ins = null; + private AbstractAF abstractAF = null; + private EquinoxRawData eqxRawData =null; + private EC02MSGBuilder msgBuilder = null; + + + public void setEquinoxRawData(AbstractAF abstractAF, EC02Instance ec02Ins){ + this.abstractAF = abstractAF; + this.ec02Ins = ec02Ins; + } + public void setEquinoxRawData(EquinoxRawData eqxRawData, AbstractAF abstractAF, EC02Instance ec02Ins){ + this.eqxRawData = eqxRawData; + this.abstractAF = abstractAF; + this.ec02Ins = ec02Ins; + } + + public ArrayList getHTTPRequest(ArrayList eqxRawList){ + ArrayList eqxRawDataList = new ArrayList(); + for (int i = 0; i < eqxRawList.size(); i++) { + eqxRawList.get(i).setType(EQXMsg.REQUEST); + this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i)); + this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i); + eqxRawDataList.add(this.msgBuilder.getHttpMessage()); + } + String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("HTTP-timeout").get(0); + String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf; + this.ec02Ins.setTimeout(timeout); + return eqxRawDataList; + } + + public EquinoxRawData getHTTPResponse(EQXRawInstance eqxRaw){ + eqxRaw.setType(EQXMsg.RESPONSE); + this.msgBuilder = new EC02MSGBuilder(eqxRaw); + this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke()); + return this.msgBuilder.getHttpMessage(); + } + + public ArrayList getLDAPRequest(ArrayList eqxRawList){ + ArrayList eqxRawDataList = new ArrayList(); + for (int i = 0; i < eqxRawList.size(); i++) { + eqxRawList.get(i).setType(EQXMsg.REQUEST); + this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i)); + this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i); + eqxRawDataList.add(this.msgBuilder.getLdapMessage()); + } + String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("LDAP-timeout").get(0); + String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf; + this.ec02Ins.setTimeout(timeout); + + return eqxRawDataList; + } + + public EquinoxRawData getLDAPResponse(EQXRawInstance eqxRaw){ + eqxRaw.setType(EQXMsg.RESPONSE); + this.msgBuilder = new EC02MSGBuilder(eqxRaw); + this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke()); + return this.msgBuilder.getLdapMessage(); + } + + + public ArrayList getDiameterRequest(ArrayList eqxRawList){ + ArrayList eqxRawDataList = new ArrayList(); + for (int i = 0; i < eqxRawList.size(); i++) { + eqxRawList.get(i).setType(EQXMsg.REQUEST); + this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i)); + this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i); + eqxRawDataList.add(this.msgBuilder.getDiameterMessage()); + } + String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("Diameter-timeout").get(0); + String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf; + this.ec02Ins.setTimeout(timeout); + + return eqxRawDataList; + } + + public EquinoxRawData getDiameterResponse(EQXRawInstance eqxRaw){ + eqxRaw.setType(EQXMsg.RESPONSE); + this.msgBuilder = new EC02MSGBuilder(eqxRaw); + this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke()); + return this.msgBuilder.getDiameterMessage(); + } + + public ArrayList getSMPPRequest(ArrayList eqxRawList){ + ArrayList eqxRawDataList = new ArrayList(); + for (int i = 0; i < eqxRawList.size(); i++) { + eqxRawList.get(i).setType(EQXMsg.REQUEST); + this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i)); + this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i); + eqxRawDataList.add(this.msgBuilder.getSMPPMessage()); + } + String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("SMPP-timeout").get(0); + String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf; + this.ec02Ins.setTimeout(timeout); + + return eqxRawDataList; + } + + public EquinoxRawData getSMPPResponse(EQXRawInstance eqxRaw){ + eqxRaw.setType(EQXMsg.RESPONSE); + this.msgBuilder = new EC02MSGBuilder(eqxRaw); + this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke()); + return this.msgBuilder.getSMPPMessage(); + } + + public void getE01Request(){ + KeyObject keyobj = new KeyObject(); + keyobj.setObjectType(this.ec02Ins.getE01Ins().getObjType()); + ArrayList keyList = this.ec02Ins.getE01Ins().getKey(); + for (int i = 0; i < keyList.size(); i++) { + keyobj.setKey(String.valueOf(i), keyList.get(i)); + } + if(this.ec02Ins.getE01Ins().getCmd().equals("search")){ + this.abstractAF.getUtils().getGlobalData().search(keyobj); + } + else if(this.ec02Ins.getE01Ins().getCmd().equals("delete")){ + this.abstractAF.getUtils().getGlobalData().delete(keyobj); + } + else if(this.ec02Ins.getE01Ins().getCmd().equals("add")){ + this.abstractAF.getUtils().getGlobalData().add(keyobj, this.ec02Ins.getE01Ins().getData()); + } + else if(this.ec02Ins.getE01Ins().getCmd().equals("replace")){ + this.abstractAF.getUtils().getGlobalData().replace(keyobj, this.ec02Ins.getE01Ins().getData()); + } + this.abstractAF.getUtils().getGlobalData().setMessageId(this.eqxRawData.getInvoke()); + } + + public EquinoxRawData getUpdateIns(){ + this.msgBuilder = new EC02MSGBuilder(); + this.ec02Ins.setTimeout(this.abstractAF.getUtils().getHmWarmConfig().get("Update-Instance-timeout").get(0)); + return this.msgBuilder.getUpdateIns(); + } +} diff --git a/AF-Demo/src/af/message/EC02MSGBuilder.java b/AF-Demo/src/af/message/EC02MSGBuilder.java new file mode 100644 index 0000000..24cecbb --- /dev/null +++ b/AF-Demo/src/af/message/EC02MSGBuilder.java @@ -0,0 +1,118 @@ +package af.message; + +import java.util.HashMap; +import java.util.Map; +import af.instatnce.EQXRawInstance; +import af.interfaces.EQXMsg; +import ec02.af.data.EquinoxRawData; + +public class EC02MSGBuilder { + private String message = null; + private EQXRawInstance eqxRawIns = null; + private EquinoxRawData eqxRawDatas = null; + private Map map = new HashMap(); + private String invoke = null; + + public EC02MSGBuilder(){ + this.eqxRawDatas = new EquinoxRawData(); + } + + public EC02MSGBuilder(EQXRawInstance eqxRawIns){ + this.setEqxRawIns(eqxRawIns); + this.eqxRawDatas = new EquinoxRawData(); + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + + public String getInvoke() { + return invoke; + } + + public void setInvoke(String invoke) { + this.invoke = invoke; + } + + public EquinoxRawData getDiameterMessage() { + if (this.invoke != null) + this.map.put(EQXMsg.INVOKE, this.invoke); + this.map.put(EQXMsg.NAME, EQXMsg.DIAMETER); + this.map.put(EQXMsg.TYPE, this.eqxRawIns.getType()); + this.map.put(EQXMsg.CTYPE, this.eqxRawIns.getCtype()); + this.eqxRawDatas.setRawDataAttributes(this.map); + this.eqxRawDatas.setTo(this.eqxRawIns.getTo()); + this.eqxRawDatas.setRawMessage(this.eqxRawIns.getMessage()); + + return this.eqxRawDatas; + } + + public EquinoxRawData getHttpMessage() { + if (this.invoke != null) + this.map.put(EQXMsg.INVOKE, this.invoke); + this.map.put(EQXMsg.NAME, EQXMsg.HTTP); + this.map.put(EQXMsg.TYPE, this.eqxRawIns.getType()); + this.map.put(EQXMsg.CTYPE, this.eqxRawIns.getCtype()); + if(this.eqxRawIns.getCtype().equals(EQXMsg.TEXTPLAIN) || this.eqxRawIns.getCtype().equals(EQXMsg.TEXTHTML)) { + this.map.put(EQXMsg.VAL, this.eqxRawIns.getMessage()); + } + else { + this.eqxRawDatas.setRawMessage(this.eqxRawIns.getMessage()); + } + this.eqxRawDatas.setRawDataAttributes(this.map); + this.eqxRawDatas.setTo(this.eqxRawIns.getTo()); + + return this.eqxRawDatas; + } + + public EquinoxRawData getLdapMessage() { + if (this.invoke != null) + this.map.put(EQXMsg.INVOKE, this.invoke); + this.map.put(EQXMsg.NAME, EQXMsg.LDAP); + this.map.put(EQXMsg.TYPE, this.eqxRawIns.getType()); + this.map.put(EQXMsg.CTYPE, this.eqxRawIns.getCtype()); + this.map.put(EQXMsg.OID, this.eqxRawIns.getOid()); + this.eqxRawDatas.setRawDataAttributes(this.map); + this.eqxRawDatas.setTo(this.eqxRawIns.getTo()); + this.eqxRawDatas.setRawMessage(this.eqxRawIns.getMessage()); + + return this.eqxRawDatas; + } + + public EquinoxRawData getSMPPMessage() { + if (this.invoke != null) + this.map.put(EQXMsg.INVOKE, this.invoke); + this.map.put(EQXMsg.NAME, EQXMsg.SMPP); + this.map.put(EQXMsg.TYPE, this.eqxRawIns.getType()); + this.map.put(EQXMsg.CTYPE, this.eqxRawIns.getCtype()); + this.eqxRawDatas.setRawDataAttributes(this.map); + this.eqxRawDatas.setTo(this.eqxRawIns.getTo()); + this.eqxRawDatas.setRawMessage(this.eqxRawIns.getMessage()); + + return this.eqxRawDatas; + } + + public EquinoxRawData getUpdateIns() { + return this.eqxRawDatas; + } + + public EQXRawInstance getEqxRawIns() { + return eqxRawIns; + } + + public void setEqxRawIns(EQXRawInstance eqxRawIns) { + this.eqxRawIns = eqxRawIns; + } +} diff --git a/AF-Demo/src/af/message/MSGParser.java b/AF-Demo/src/af/message/MSGParser.java new file mode 100644 index 0000000..4506b43 --- /dev/null +++ b/AF-Demo/src/af/message/MSGParser.java @@ -0,0 +1,67 @@ +package af.message; + +import java.util.ArrayList; +import af.instatnce.AFInstance; +import af.instatnce.E01Instance; + +public class MSGParser { + private String msg = ""; + private E01Instance e01Ins = null; + private AFInstance afInstance = null; + + + + public MSGParser(String msg){ + this.msg = msg; + } + + public void extractHTTPMessage(AFInstance afIns){ + this.afInstance = afIns; + + } + + public void extractE01Message(E01Instance e01Ins){ + this.e01Ins = e01Ins; + ArrayList key = null; + String [] e01msg = this.msg.split(":"); + String [] cmd = e01msg[0].split("="); + this.e01Ins.setCmd(cmd[1].trim()); + String [] e01objAndkey = e01msg[1].split(","); + for(int i = 0; i < e01objAndkey.length; i++){ + String [] e01val = e01objAndkey[i].split("="); + if(e01val[0].trim().equalsIgnoreCase("objecttype")){ + this.e01Ins.setObjType(e01val[1].trim()); + } + else if(e01val[0].contains("key")){ + if(key == null){ + key = new ArrayList(); + } + key.add(e01val[1].trim()); + } + else if(e01val[0].trim().equalsIgnoreCase("data")){ + this.e01Ins.setData(e01val[1].trim()); + } + else if(e01val[0].trim().equalsIgnoreCase("id")){ + this.e01Ins.setId(e01val[1].trim()); + } + } + + this.e01Ins.setKey(key); + } + + public E01Instance getE01Ins() { + return e01Ins; + } + + public void setE01Ins(E01Instance e01Ins) { + this.e01Ins = e01Ins; + } + + public AFInstance getAFInstance() { + return afInstance; + } + + public void setMsgIns(AFInstance afInstance) { + this.afInstance = afInstance; + } +} diff --git a/AF-Demo/src/af/state/StateIdle.java b/AF-Demo/src/af/state/StateIdle.java new file mode 100644 index 0000000..cc0ac4e --- /dev/null +++ b/AF-Demo/src/af/state/StateIdle.java @@ -0,0 +1,59 @@ +package af.state; + +import java.util.ArrayList; + +import af.instatnce.E01Instance; +import af.instatnce.EC02Instance; +import af.interfaces.AFEvent; +import af.interfaces.AFState; +import af.interfaces.EQXMsg; +import af.message.EC02Builder; + +import ec02.af.abstracts.AbstractAF; +import ec02.af.data.EquinoxRawData; +import ec02.af.interfaces.IAFState; +import ec02.af.utils.AlarmCategory; +import ec02.af.utils.AlarmSeverity; +import ec02.af.utils.AlarmType; + +public class StateIdle implements IAFState { + private String eqxState = null; + private EC02Builder ec02Builder = new EC02Builder(); + private ArrayList eqxRawDataList = new ArrayList(); + + @Override + public String doAction(AbstractAF abstractAF, Object instance, ArrayList eqxRawDataList) { + EC02Instance ec02Ins = (EC02Instance) instance; + + for(EquinoxRawData eqxRawData : eqxRawDataList){ + this.ec02Builder.setEquinoxRawData(eqxRawData, abstractAF, ec02Ins); + ec02Ins.getAFInstance().setInvoke(eqxRawData.getInvoke()); + ec02Ins.getAFInstance().setOrig(eqxRawData.getRawDataAttribute(EQXMsg.ORIG)); + + if(eqxRawData.getRawEventType().equals(AFEvent.Incoming_HTTP_Request)){ + E01Instance e01Ins = new E01Instance(); + ArrayList keys = new ArrayList(); + keys.add(eqxRawData.getRawDataMessage()); + keys.add("def"); + keys.add("def"); + keys.add("def"); + keys.add("def"); + e01Ins.setCmd("search"); + e01Ins.setObjType("TESTDATA"); + e01Ins.setKey(keys); +// e01Ins.setId("01"); + ec02Ins.setE01Ins(e01Ins); + this.ec02Builder.getE01Request(); + String [] parameter = {""}; + abstractAF.getUtils().writeLog("mylog1", "hello word!!!"); + abstractAF.getUtils().incrementStats("my_stat"); + abstractAF.getUtils().incrementStats("raise_by_stat"); + abstractAF.getUtils().raiseAlarm("my_alarm", parameter, AlarmSeverity.WARNING, AlarmCategory.APPLICATION, AlarmType.Normal); + this.eqxState = AFState.W_E01Res; + } + } + ec02Ins.setEqxRawDataList(this.eqxRawDataList); + return this.eqxState; + } + +} diff --git a/AF-Demo/src/af/state/StateWaitA.java b/AF-Demo/src/af/state/StateWaitA.java new file mode 100644 index 0000000..2a069e8 --- /dev/null +++ b/AF-Demo/src/af/state/StateWaitA.java @@ -0,0 +1,48 @@ +package af.state; + +import java.util.ArrayList; +import java.util.HashMap; + +import th.co.ais.equinox.utils.StringExtract; +import af.instatnce.EC02Instance; +import af.instatnce.EQXRawInstance; +import af.interfaces.AFEvent; +import af.interfaces.AFState; +import af.interfaces.EQXMsg; +import af.message.EC02Builder; +import ec02.af.abstracts.AbstractAF; +import ec02.af.data.EquinoxRawData; +import ec02.af.interfaces.IAFState; + +public class StateWaitA implements IAFState { + private String eqxState = null; + private EC02Builder ec02Builder = new EC02Builder(); + private ArrayList eqxRawDataList = new ArrayList(); + + @Override + public String doAction(AbstractAF abstractAF, Object instance, ArrayList eqxRawDataList) { + EC02Instance ec02Ins = (EC02Instance)instance; + + for(EquinoxRawData eqxRawData : eqxRawDataList) { + this.ec02Builder.setEquinoxRawData(eqxRawData, abstractAF, ec02Ins); + if(eqxRawData.getRawEventType().equals(AFEvent.Incoming_A_Response)){ + StringExtract str = new StringExtract(); + HashMap map = str.getAll(str.setMessage(eqxRawData.getRawDataMessage().trim())); + String message = map.get("MSG[0].value"); + if (message.trim().equals("SUCCESS")) { + EQXRawInstance eqxRaw = new EQXRawInstance(); + eqxRaw.setMessage(message.trim()); + eqxRaw.setTo(ec02Ins.getAFInstance().getOrig()); + eqxRaw.setCtype(EQXMsg.TEXTPLAIN); + this.eqxRawDataList.add(this.ec02Builder.getHTTPResponse(eqxRaw)); + this.eqxState = AFState.IDLE; + } + else { + + } + } + } + ec02Ins.setEqxRawDataList(this.eqxRawDataList); + return this.eqxState; + } +} diff --git a/AF-Demo/src/af/state/StateWaitE01.java b/AF-Demo/src/af/state/StateWaitE01.java new file mode 100644 index 0000000..071adae --- /dev/null +++ b/AF-Demo/src/af/state/StateWaitE01.java @@ -0,0 +1,52 @@ +package af.state; + +import java.util.ArrayList; +import af.instatnce.EC02Instance; +import af.instatnce.EQXRawInstance; +import af.interfaces.AFState; +import af.interfaces.EQXMsg; +import af.message.EC02Builder; +import ec02.af.abstracts.AbstractAF; +import ec02.af.data.EquinoxRawData; +import ec02.af.interfaces.IAFState; + +public class StateWaitE01 implements IAFState { + private String eqxState = null; + private EC02Builder ec02Builder = new EC02Builder(); + private ArrayList eqxRawDataList = new ArrayList(); + + @Override + public String doAction(AbstractAF abstractAF, Object instance, ArrayList eqxRawDataList) { + EC02Instance ec02Ins = (EC02Instance) instance; + + //receive E01 response + if(abstractAF.getUtils().getGlobalData().isRecieve()){ + this.ec02Builder.setEquinoxRawData(abstractAF, ec02Ins); + //E01 return success + ec02Ins.setE01data(abstractAF.getUtils().getGlobalData().getDataResultSet().get(0).getData()); + if(abstractAF.getUtils().getGlobalData().getResultCode().equals("0")){ + ArrayList eqxRawList = new ArrayList(); + if (ec02Ins.getE01data().equals("SUCCESS")) { + EQXRawInstance eqxRaw = new EQXRawInstance(); + eqxRaw.setMessage(""); + eqxRaw.setTo(abstractAF.getUtils().getHmWarmConfig().get("Resource-Name-A").get(0)); + eqxRaw.setCtype(EQXMsg.TEXTXML); + eqxRawList.add(eqxRaw); + ArrayList rawList = this.ec02Builder.getHTTPRequest(eqxRawList); + for (int i = 0; i < rawList.size(); i++) { + this.eqxRawDataList.add(rawList.get(i)); + } + this.eqxState = AFState.W_ARes; + } + } + //E01 does not return success + + } + //E01 does not response + else{ + + } + ec02Ins.setEqxRawDataList(this.eqxRawDataList); + return this.eqxState; + } +} diff --git a/AF-Demo/src/af/utils/Zip.java b/AF-Demo/src/af/utils/Zip.java new file mode 100644 index 0000000..8a9333c --- /dev/null +++ b/AF-Demo/src/af/utils/Zip.java @@ -0,0 +1,72 @@ +package af.utils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.zip.DataFormatException; +import java.util.zip.Deflater; +import java.util.zip.Inflater; + +/** + * Created by IntelliJ IDEA. + * User: Administrator + * Date: 25/8/2555 + * To change this template use File | Settings | File Templates. + */ +public class Zip { + public static byte[] compressBytes(byte[] input) throws UnsupportedEncodingException, IOException { + Deflater df = new Deflater(); //this function mainly generate the byte code + //df.setLevel(Deflater.BEST_COMPRESSION); + df.setInput(input); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length); //we write the generated byte code in this array + df.finish(); + byte[] buff = new byte[1024]; //segment segment pop....segment set 1024 + while (!df.finished()) { + int count = df.deflate(buff); //returns the generated code... index + baos.write(buff, 0, count); //write 4m 0 to count + } + baos.close(); + byte[] output = baos.toByteArray(); + + //System.out.println("Original: " + input.length); + //System.out.println("Compressed: " + output.length); + return output; + } + + public static byte[] extractBytes(byte[] input) throws UnsupportedEncodingException, IOException, DataFormatException { + Inflater ifl = new Inflater(); //mainly generate the extraction + //df.setLevel(Deflater.BEST_COMPRESSION); +// Log.i(input +""); + ifl.setInput(input); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length); + byte[] buff = new byte[1024]; + while (!ifl.finished()) { + int count = ifl.inflate(buff); + baos.write(buff, 0, count); + } + baos.close(); + byte[] output = baos.toByteArray(); + + //System.out.println("Original: " + input.length); + //System.out.println("Extracted: " + output.length); + //System.out.println("Data:"); + //System.out.println(new String(output)); + return output; + } + + public static void compressFile(String src, String dest) throws IOException { + java.util.zip.GZIPOutputStream out = new java.util.zip.GZIPOutputStream(new java.io.FileOutputStream(dest)); + java.io.FileInputStream in = new java.io.FileInputStream(src); + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + // Complete the GZIP file + out.finish(); + out.close(); + } +} -- libgit2 0.21.2