diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..f619a53
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..e902d15
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ MockUp
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..f9fe345
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/test/java=UTF-8
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..6249222
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+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.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..bbd1ff1
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,67 @@
+
+ 4.0.0
+
+ sourcecode
+ MockUp
+ 0.0.1-SNAPSHOT
+ jar
+
+ MockUp
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+
+ com.sun.net.httpserver
+ http
+ 20070405
+ test
+
+
+ com.google.code.gson
+ gson
+ 2.8.0
+
+
+
+ commons-io
+ commons-io
+ 2.6
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.4
+
+
+ org.json
+ json
+ 20180130
+
+
+ org.mongodb
+ mongodb-driver
+ 3.6.3
+
+
+ org.mongodb
+ mongo-java-driver
+ 3.6.3
+
+
+
+
+
diff --git a/src/main/java/sourcecode/MockUp/MockUp.java b/src/main/java/sourcecode/MockUp/MockUp.java
new file mode 100644
index 0000000..7295a7a
--- /dev/null
+++ b/src/main/java/sourcecode/MockUp/MockUp.java
@@ -0,0 +1,285 @@
+package sourcecode.MockUp;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.http.Consts;
+import org.bson.Document;
+import org.json.JSONObject;
+
+import com.google.gson.Gson;
+import com.mongodb.BasicDBObject;
+import com.mongodb.MongoClient;
+import com.mongodb.MongoClientOptions;
+import com.mongodb.MongoClientURI;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.MongoDatabase;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+
+
+
+
+
+public class MockUp
+{
+ private static Gson gson = new Gson();
+ private static MongoDatabase database;
+ private final static String GET = "GET";
+ private final static String POST = "POST";
+ private final static String PUT = "PUT";
+ private final static String DELETE = "DELETE";
+
+
+
+ public static void main(String[] args) throws Exception {
+
+ int port = 8000;
+
+
+ try{
+
+
+ if(args.length>0)
+ port = Integer.parseInt(args[0]);
+
+ //connect mongo
+ MongoConnector("spw");
+
+ HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
+ server.createContext("/", new MyHandler());
+ server.setExecutor(null); // creates a default executor
+ server.start();
+ System.out.println("Run in port : "+port);
+
+ }catch(Exception e)
+ {
+ e.printStackTrace();
+ System.out.println("Fail to run in port : "+port);
+ }
+ }
+
+ static class MyHandler implements HttpHandler {
+ public void handle(HttpExchange t) throws IOException {
+
+ String method = t.getRequestMethod();
+ String url = t.getRequestURI().toString();
+ String response = "";
+ String keyBody ="";
+
+// System.out.println(t.getRequestMethod());
+ if(!method.equals(GET))
+ {
+ String bodyData = IOUtils.toString(t.getRequestBody(),Consts.UTF_8);
+ JSONObject body = new JSONObject(bodyData);
+ String[] a = bodyData.split(",");
+ // System.out.println(a[0]);
+ String[] b = a[0].split(":");
+ // System.out.println(b[0]);
+ String c = b[0].replace("{", "").trim().replace("\"", "");
+ // System.out.println(c);
+ keyBody = (String) body.get(c);
+ }
+// System.out.println(body.get(c));
+
+// for(Entry> row:t.getRequestHeaders().entrySet())
+// {
+// System.out.println(row.getKey());
+// System.out.println(row.getValue());
+// }
+// System.out.println(t.getRequestHeaders());
+// System.out.println(t.getRequestURI());
+
+
+ String collectionName = "spwCustomerAccounts";
+
+
+ BasicDBObject basicDBObject = new BasicDBObject();
+
+ switch (method) {
+ case GET:
+ basicDBObject.put("url", url);
+ break;
+ case POST:
+ case PUT:
+ basicDBObject.put("key", keyBody);
+ break;
+ case DELETE:
+ basicDBObject.put("key", url);
+ break;
+
+ default:
+ break;
+ }
+
+ ArrayList responseList = getDBData(basicDBObject,collectionName,method);
+
+ if(responseList.size() == 0)
+ {
+ System.out.println("===> Go to Main flow");
+
+ BasicDBObject basicDBObjectMain = new BasicDBObject();
+ if(method.equals(GET))
+ basicDBObjectMain.put("url", "");
+ else
+ basicDBObjectMain.put("key", "");
+ responseList = getDBData(basicDBObjectMain,collectionName,method);
+
+
+ }
+
+ JSONObject responsJSON = new JSONObject();
+ ArrayList resultData = new ArrayList();
+ for(int i=0;i 1)
+ {
+ if(rowJSON.get("resultData")!=null)
+ resultData.add((JSONObject) rowJSON.get("resultData"));
+ else if(rowJSON.get("value")!=null)
+ resultData.add((JSONObject) rowJSON.get("value"));
+ }else
+ resultData.add(rowJSON);
+// System.out.println(rowJSON);
+// resultData.add((JSONObject) rowJSON.get("resultData"));
+ }
+
+
+ responsJSON.put("resultCode", "20000");
+ responsJSON.put("resultDescription", "Success");
+ if(method.equals(GET))
+ {
+ responsJSON.put("resultData",resultData);
+ responsJSON.put("rowCount", resultData.size());
+ }
+
+// System.out.println(responsJSON.toString());
+ response = responsJSON.toString();
+
+
+ t.getResponseHeaders().set("Content-Type", "application/json");
+ t.sendResponseHeaders(200, response.length());
+ OutputStream os = t.getResponseBody();
+ os.write(response.getBytes());
+ os.close();
+
+ System.out.println("");
+ System.out.println("URL : " + url);
+ System.out.println("Method : " + method);
+ System.out.println("Response : " + response);
+ System.out.println("");
+ }
+ }
+
+
+ private static void MongoConnector(String db) {
+
+ String username = "";
+ String password = "";
+ String address = "10.1.2.155:27017";
+ String dbname = db;
+ String authSource = db;
+ int timeoutMongoDB = 10000;
+
+ MongoClientOptions.Builder optionsBuilder = MongoClientOptions.builder();
+ optionsBuilder.connectTimeout(timeoutMongoDB);
+ optionsBuilder.socketTimeout(timeoutMongoDB);
+ optionsBuilder.serverSelectionTimeout(timeoutMongoDB);
+
+// optionsBuilder.connectionsPerHost(maxPoolSize);
+// optionsBuilder.minConnectionsPerHost(minPoolSize);
+
+ MongoClientURI uri = new MongoClientURI("mongodb://"+username+":"+password+"@"+address+"/?authSource="+authSource, optionsBuilder);
+ if(username.equals(""))
+ uri = new MongoClientURI("mongodb://"+address+"/?authSource="+authSource, optionsBuilder);
+ System.out.println("MongoDB Connecting to "+uri.toString()+"...");
+ MongoClient mongoClient = new MongoClient(uri);
+ database = mongoClient.getDatabase(dbname);
+ //test connect and list collections
+ MongoCursor collectionNames = database.listCollectionNames().iterator();
+ System.out.println("MongoDB Connect to "+uri.toString()+" Success");
+ System.out.println("MongoDB Collections in datebase");
+ while (collectionNames.hasNext()) {
+ String collectionName = collectionNames.next();
+ System.out.println(" |_ "+collectionName);
+
+ }
+ }
+
+ private static ArrayList getDBData(BasicDBObject basicDBObject,String collectionName,String method)
+ {
+ collectionName = method.toLowerCase()+"_"+collectionName;
+ System.out.println("CollectionName : " + collectionName);
+ System.out.println("Find : "+basicDBObject.toJson());
+ ArrayList returnData = new ArrayList();
+ String found = "";
+
+ MongoCollection collection = database.getCollection(collectionName);
+ FindIterable findData = collection.find(basicDBObject);
+ MongoCursor cursor = findData.iterator();
+
+
+ switch (method) {
+ case GET:
+ while(cursor.hasNext()){
+ Document rawRow = cursor.next();
+ System.out.println("found _id : "+rawRow.get("_id"));
+ rawRow.remove("_id");
+ rawRow.remove("url");
+ if(rawRow.get("value") != null)
+ {
+
+ rawRow.append("resultData", rawRow.get("value"));
+ rawRow.append("rowCount", "1");
+ rawRow.remove("value");
+ }
+ found = rawRow.toJson();
+ returnData.add(found);
+ }
+ break;
+ case POST:
+ case PUT:
+ case DELETE:
+ while(cursor.hasNext()){
+ Document rawRow = cursor.next();
+ System.out.println("found _id : "+rawRow.get("_id"));
+ rawRow.remove("_id");
+ rawRow.remove("key");
+ if(rawRow.get("value") != null)
+ {
+
+ JSONObject rowJSON = new JSONObject(rawRow.toJson());
+// System.out.println(rowJSON.get("value"));
+ found = rowJSON.get("value").toString();
+ returnData.add(found);
+ System.out.println("found : "+found);
+ }else
+ {
+ found = rawRow.toJson();
+ returnData.add(found);
+ }
+
+ }
+ break;
+
+ default:
+ break;
+ }
+
+
+ return returnData;
+ }
+}
diff --git a/src/test/java/sourcecode/MockUp/AppTest.java b/src/test/java/sourcecode/MockUp/AppTest.java
new file mode 100644
index 0000000..8be594d
--- /dev/null
+++ b/src/test/java/sourcecode/MockUp/AppTest.java
@@ -0,0 +1,38 @@
+package sourcecode.MockUp;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..9a31738
--- /dev/null
+++ b/target/classes/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Built-By: SourceCode
+Build-Jdk: 1.8.0_161
+Created-By: Maven Integration for Eclipse
+
diff --git a/target/classes/META-INF/maven/sourcecode/MockUp/pom.properties b/target/classes/META-INF/maven/sourcecode/MockUp/pom.properties
new file mode 100644
index 0000000..2c56ac2
--- /dev/null
+++ b/target/classes/META-INF/maven/sourcecode/MockUp/pom.properties
@@ -0,0 +1,7 @@
+#Generated by Maven Integration for Eclipse
+#Wed Aug 29 16:58:24 ICT 2018
+version=0.0.1-SNAPSHOT
+groupId=sourcecode
+m2e.projectName=MockUp
+m2e.projectLocation=C\:\\myWork\\eclipseCode\\MockUp
+artifactId=MockUp
diff --git a/target/classes/META-INF/maven/sourcecode/MockUp/pom.xml b/target/classes/META-INF/maven/sourcecode/MockUp/pom.xml
new file mode 100644
index 0000000..bbd1ff1
--- /dev/null
+++ b/target/classes/META-INF/maven/sourcecode/MockUp/pom.xml
@@ -0,0 +1,67 @@
+
+ 4.0.0
+
+ sourcecode
+ MockUp
+ 0.0.1-SNAPSHOT
+ jar
+
+ MockUp
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+
+ com.sun.net.httpserver
+ http
+ 20070405
+ test
+
+
+ com.google.code.gson
+ gson
+ 2.8.0
+
+
+
+ commons-io
+ commons-io
+ 2.6
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.4
+
+
+ org.json
+ json
+ 20180130
+
+
+ org.mongodb
+ mongodb-driver
+ 3.6.3
+
+
+ org.mongodb
+ mongo-java-driver
+ 3.6.3
+
+
+
+
+
diff --git a/target/classes/sourcecode/MockUp/MockUp$MyHandler.class b/target/classes/sourcecode/MockUp/MockUp$MyHandler.class
new file mode 100644
index 0000000..7533366
Binary files /dev/null and b/target/classes/sourcecode/MockUp/MockUp$MyHandler.class differ
diff --git a/target/classes/sourcecode/MockUp/MockUp.class b/target/classes/sourcecode/MockUp/MockUp.class
new file mode 100644
index 0000000..141efa8
Binary files /dev/null and b/target/classes/sourcecode/MockUp/MockUp.class differ
diff --git a/target/test-classes/sourcecode/MockUp/AppTest.class b/target/test-classes/sourcecode/MockUp/AppTest.class
new file mode 100644
index 0000000..5b65813
Binary files /dev/null and b/target/test-classes/sourcecode/MockUp/AppTest.class differ
--
libgit2 0.21.2