Connect to ThingWorx to get data
Hi All,
I am attempting to connect to thingworx using Java to get specific data using a key.
Data Table Name: DataTable
Service I want to use to extract the data for a row : GetDataTableEntry
This is a generic service and I need to pass key to get the data which is working fine when I use SOAPUI to connect.
In below java code, the row gets returned as null.
ClientConfigurator config = new ClientConfigurator();
config.setUri("wss://URL:443/Thingworx/WS");
config.setAppKey("key");
config.ignoreSSLErrors(true); // All self signed certs
ConnectedThingClient client = new ConnectedThingClient(config);
client.connect();
client.start();
ValueCollection params = new ValueCollection();
params.put("key", new StringPrimitive("Test20124"));
InfoTable table = client.invokeService(ThingworxEntityTypes.Things, "DataTable", "GetDataTableEntry", null, 5000);
System.out.println(table.getJSON());
This Returns null.
Similarly even if I directly attempt to call rest service, the data returned is null
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("key", "Test20124");
con.setRequestProperty("Accept", "application/json");
con.setInstanceFollowRedirects( false );
con.setUseCaches( false );
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("appKey", "key");
con.setDoOutput(true);
try( DataOutputStream wr = new DataOutputStream( con.getOutputStream())) {
wr.flush();
wr.close();
}
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + sURL);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while((inputLine = in.readLine()) != null) {
response.append(inputLine);
}

