Remotely Importing Entities to ThingWorx with Java
Just struggled to remotely upload some pre-made entities files and have them import to the Thingworx server automatically. The objective was to have a client application that could upload a utilitything which had some server side services. We would then call these remote services from the client to do certain operations on Thingworx.
This project was done with the ThingWorx Java SDK so performing this in java was important. Here's the code:
writer.append("Content-Type: application/xml").append(CRLF); // Text file itself must be saved in the specified charset!
output.flush(); // Important before continuing with writer!
writer.append(CRLF).flush(); // CRLF is important! It indicates end
// of boundary.
// End of multipart/form-data.
writer.append("--"+ boundary +"--").append(CRLF);
//System.out.print("This is the output:: " + output + " ::This is the end");
// Request is lazily fired whenever you need to obtain information about
int responseCode = ((HttpURLConnection) connection).getResponseCode();
//System.out.println(responseCode); // Should be 200
We were able to do this in curl but decided against it so that the client could be mulitplatform and not require prerequisite software. Here's a example curl command for anyone interested (Thanks to Bill Reichardt!)...