How to access the JSON data passing from external Java Code Via REST Call To TWX Service
I have written this code Snippet in Java:
public static void callTW(JSONObject obj) throws Exception {
String statusMsg = "";
try
{
String uri = "http://localhost:8080/Thingworx/Things/test2/Services/JSON_Split?userid=Administrator&password=admin";
HttpURLConnection conn = (HttpURLConnection) new URL(uri).openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
OutputStream os = conn.getOutputStream();
JSONObject obj2=new JSONObject();
obj2.put("IDA2A2", "6278");
obj2.put("Number_P", "W10320887");
obj2.put("Name", "test");
JSONObject obj3=new JSONObject();
obj3.put("IDA2A2", "6278");
obj3.put("Number_P", "W10320887");
obj3.put("View_P", "Engineering");
obj.put("partmaster", obj2);
obj.put("part", obj3);
System.out.println(obj);
os.flush();
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK)
{
statusMsg = conn.getResponseCode() + " " + conn.getResponseMessage();
throw new RuntimeException("Failed : HTTP error code : " + statusMsg);
}
os.close();
conn.disconnect();
}
catch (Exception e)
{
throw new Exception(statusMsg + "." + e);
}
}
This Code actually contains three JSON Object and here I am actually merging two JSON Object into one Object i.e. "obj".
And Now I want to catch this whole JSON at ThingWorx Side by creating a Service.
I actually want to split this JSON Object "obj" into its Child object and then store the values in these child objects at TWX Side.
I hope you guys are getting me.
What script I should write at TWX Side to catch all this data.
