Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I am calling rest api(thingworx url) from java eclipse but throwing error in java.Below is my code
String b64 = Base64.getEncoder().encodeToString(bytes);
//Construct jsoninput body//
JSONObject params=new JSONObject();
params.put("path","/Motivation.pdf");
params.put("content", b64);
//Load pdf to Thingworx repository//
String url = "HiddenServerurlforsafetypurpose/Thingworx/Things/komal_FileRepo/Services/SaveBinary";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add request header
con.setRequestMethod("POST");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("appKey", "removedforsafetypurpose");
con.setRequestProperty("Body", params.toJSONString());
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
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);
}
in.close();
//print result
System.out.println(response.toString());
Error in Thingworx :
No Path Was Specified
[SECURITY FAILURE Anonymous:@unknown -> /ExampleApplication/IntrusionDetector] Invalid input: context=HTTP header value: body, type(HTTPHeaderValue)=^[a-zA-Z0-9()\-=\*\.\?;,+\/:&_ %$ ¡-'"]*$, input={"path":"\/Motivation.pdf","content":"JVBERi0xLjQKJeLjz9MKMiAwIG9iago8PC9MZW5ndGggMTIxL0ZpbHRlci9GbGF0ZURlY29kZT4+c3RyZWFtCnicFc3LCsIwEEbh\/TzF76oKXhKF0rVQQXfCvEAwE6uFjk1SxLc32Z3FB2emM9OpRWdasCeDne1qHC4W9ggOtL4G\/HRpokBDkCgeDklchk6loj5GyUjD67OF16nJcGnEdyigqhVuS8p4SvX7Db\/Lw9RDz3SnP8DJJHoKZW5kc3RyZWFtCmVuZG9iago0IDAgb2JqCjw8L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input
Solved! Go to Solution.
Thank you Velkumar for the much needed support.
Hi @KN_9954684
I think there is some bug in the code. You are setting Body as POST Header Property.
Please refer to this one -
POSTing via a REST call in Java - PTC Community
Making a JSON POST Request With HttpURLConnection | Baeldung
/VR
In the first example they are not setting body.
As per second example I set the body and changed the code but still I am getting error as "No path was specified"
Please check below code
String url = "Hiddenforsecuritypurpose/Things/komal_FileRepo/Services/SaveBinary";
String jsonInputString = "{"+"path"+":"+"/Motivation.pdf"+","+"content"+":"+b64+"}";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add request header
con.setRequestMethod("POST");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("appKey", "Hidden");
//con.setRequestProperty("Body", jsonInputString);
// Send post request
con.setDoOutput(true);
// DataOutputStream wr = new DataOutputStream(con.getOutputStream());
//
// wr.flush();
//
// wr.close();
//
// int responseCode = con.getResponseCode();
//
// System.out.println("\nSending 'POST' request to URL : " + url);
//
// 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);
//
// }
//
// in.close();
//
// //print result
//
// System.out.println(response.toString());
try(OutputStream os = con.getOutputStream()) {
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
try(BufferedReader br = new BufferedReader(
new InputStreamReader(con.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
Hi @KN_9954684
Please find below code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class restApiPostRequest {
public static void main(String[] args) throws IOException {
// Create URL Instance
URL url = new URL("http://192.168.86.195:8080/Thingworx/Things/SystemRepository/Services/SaveBinary");
// Open Connection
HttpURLConnection conection = (HttpURLConnection) url.openConnection();
// set HTTP Method
conection.setRequestMethod("POST");
// Set Headers to specify content types
conection.setRequestProperty("Content-Type", "application/json");
conection.setRequestProperty("Accept", "application/json");
conection.setRequestProperty("appKey", "2d3571aa-8d70-40ad-b1be-2a32ebb69a1a");
// to enable write content to request
conection.setDoOutput(true);
// making JSON String
String jsonString = "{ \"content\": \"JVBERi0xLjQKJeLjz9MKMiAwIG9iago8PC9MZW5ndGggMTIxL0ZpbHRlci9GbGF0ZURlY29kZT4+c3RyZWFtCnicFc3LCsIwEEbh\\/TzF76oKXhKF0rVQQXfCvEAwE6uFjk1SxLc32Z3FB2emM9OpRWdasCeDne1qHC4W9ggOtL4G\\/HRpokBDkCgeDklchk6loj5GyUjD67OF16nJcGnEdyigqhVuS8p4SvX7Db\\/Lw9RDz3SnP8DJJHoKZW5kc3RyZWFtCmVuZG9iago0IDAgb2JqCjw8L1R5cGUvUGFnZS9NZWRpYUJveFswIDAgNTk1IDg0Ml0vUmVzb3VyY2VzPDwvRm9udDw8L0YxIDEgMCBSPj4+Pi9Db250ZW50cyAyIDAgUi9QYXJlbnQgMyAwIFI+PgplbmRvYmoKMSAwIG9iago8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9IZWx2ZXRpY2EvRW5jb2RpbmcvV2luQW5zaUVuY29kaW5nPj4KZW5kb2JqCjMgMCBvYmoKPDwvVHlwZS9QYWdlcy9Db3VudCAxL0tpZHNbNCAwIFJdPj4KZW5kb2JqCjUgMCBvYmoKPDwvVHlwZS9DYXRhbG9nL1BhZ2VzIDMgMCBSPj4KZW5kb2JqCjYgMCBvYmoKPDwvUHJvZHVjZXIoaVRleHSuIDUuNS4xMy4yIKkyMDAwLTIwMjAgaVRleHQgR3JvdXAgTlYgXChBR1BMLXZlcnNpb25cKSkvQ3JlYXRpb25EYXRlKEQ6MjAyMzEwMDQxNjE2MzkrMDUnMzAnKS9Nb2REYXRlKEQ6MjAyMzEwMDQxNjE2MzkrMDUnMzAnKT4+CmVuZG9iagp4cmVmCjAgNwowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAzMTUgMDAwMDAgbiAKMDAwMDAwMDAxNSAwMDAwMCBuIAowMDAwMDAwNDAzIDAwMDAwIG4gCjAwMDAwMDAyMDMgMDAwMDAgbiAKMDAwMDAwMDQ1NCAwMDAwMCBuIAowMDAwMDAwNDk5IDAwMDAwIG4gCnRyYWlsZXIKPDwvU2l6ZSA3L1Jvb3QgNSAwIFIvSW5mbyA2IDAgUi9JRCBbPGNkYjRlMmVkODI3YzhjNmEyZjA3OGIxMTkwMjBjMGVkPjxjZGI0ZTJlZDgyN2M4YzZhMmYwNzhiMTE5MDIwYzBlZD5dPj4KJWlUZXh0LTUuNS4xMy4yCnN0YXJ0eHJlZgo2NTkKJSVFT0YK\", \"path\": \"/motivation.pdf\" }";
try (OutputStream os = conection.getOutputStream()) {
byte[] input = jsonString.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// Print Stataus code
System.out.println("Status Code: "+conection.getResponseCode());
// Get content from response and print in console. Use try with resource to close streams automatically
try (BufferedReader br = new BufferedReader(new InputStreamReader(conection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder resp = new StringBuilder();
String respLine = null;
while ((respLine = br.readLine()) != null) {
resp.append(respLine.trim());
}
System.out.println(resp.toString());
}
}
}
/VR
Thanks for the reply.
I see that you have given the content and path directly in json string.
I am fetching content value from a variable , So I have written code like below which is not throwing any errors nor creating the file.
JSONObject params=new JSONObject();
params.put("path","komal_FileRepo/Motivation.pdf");
params.put("content", b64);
String jsonString = params.toString();
And rest of the code is similiar to yours.
When I print the jsonString variable in eclipse,It is like below unlike yours
jsonString{"path":"komal_FileRepo/Motivation.pdf","content":"JVBERi0xLjQKJeLjz9MKMiAwIG9iago8PC9MZW5ndGggNjE1L0ZpbHRlci9Gb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w8L1NpemUgMTEvUm9vdCA5IDAgUi9JbmZvIDEwIDAgUi9JRCBbPDUyNGY0MjMxYjE3NTU3OTdjODQwMjI0MTM3ZGRmYjY0Pjw1MjRmNDIzMWIxNzU1Nzk3Yzg0MDIyNDEzN2RkZmI2ND5dPj4KJWlUZXh0LTUuNS4xMy4yCnN0YXJ0eHJlZgoyMjA1CiUlRU9GCg=="}Status Code: 200
{}
Can you please let me know how to construct the json input when using variable.Thanks in advance.
Thank you ,It works
I have used variable for content part like below
String jsonString = "{\"content\" : \""+b64+"\" ,\"path\": \"/Motivation.pdf\"}";
Hi @KN_9954684
I can status code: 200 which means the file got created in Thingowrx. Please check the Repository for the file.
It should be available in repository under folder komal_repo
/VR
Yes it is, when tried with java code.But when I executed same with Thingworx code.getting error as below
Active Directory error occurred. [explanation: javax.naming.CommunicationException: localhost:389 [Root exception is java.net.ConnectException: Connection refused: connect]]
And file is also not getting created in repository.Any idea upon this?
Please post some screenshot
After exectuing savebinary service,I got the error
Hi @KN_9954684
There is some connectivity issue between AD and other systems. This is not related to a script error.
/VR
Thank you for the clarification.
Could you let me know if there is any way to resolve this?
@KN_9954684 Check this article - Troubleshooting Active Directory Issues (ptc.com)
Debbuging the issue.I will accept it as solution once resolved.Thanks
The Active directory error is not related to this.Can you run the same code from Thingworx as extension and let me know if pdf is getting created
ThingWorx 9.2.1-b112
Thank you.
//Above is my Thingworx extension code.It is not saving file to sysrepo when executed.And no error is generated.Can you import and check the same.Thanks in advance
I have imported in 9.2.5 Thingworx with http url which worked.But we want this on https and 9.2.1.Please verify the same.Thanks
Hi @KN_9954684
Article - CS219756 - Using the Eclipse IDE to debug an Extension running in ThingWorx (ptc.com) You can use eclipse to debug an extension in Thingworx.
Also please upload your script as file or use code formatting it is difficult to copy and test it
/VR
Hi @KN_9954684
Please provide a proper PDF file path. The code working properly on my end
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Base64;
public class restApiPostRequest {
public static void main(String[] args) throws IOException {
// Convert PDF to binary
File file = new File("C:\\test.pdf");
byte[] bytes = Files.readAllBytes(file.toPath());
String b64 = Base64.getEncoder().encodeToString(bytes);
// Create URL Instance
URL url = new URL("http://192.168.86.136:8080/Thingworx/Things/SystemRepository/Services/SaveBinary");
// Open Connection
HttpURLConnection conection = (HttpURLConnection) url.openConnection();
// set HTTP Method
conection.setRequestMethod("POST");
// Set Headers to specify content types
conection.setRequestProperty("Content-Type", "application/json");
conection.setRequestProperty("Accept", "application/json");
conection.setRequestProperty("appKey", "20e2fe8a-3a0b-4e9c-bcb7-a632f2c4a7a7");
// to enable write content to request
conection.setDoOutput(true);
/*
// making JSON String
JSONObject params = new JSONObject();
params.put("path","/komal_FileRepo/Motivation.pdf");
params.put("content", "JVBERi0xLjQKJeLjz9MKMiAwIG9iago8PC9MZW5ndGggMTIxL0ZpbHRlci9GbGF0ZURlY29kZT4+c3RyZWFtCnicFc3LCsIwEEbh\\\\/TzF76oKXhKF0rVQQXfCvEAwE6uFjk1SxLc32Z3FB2emM9OpRWdasCeDne1qHC4W9ggOtL4G\\\\/HRpokBDkCgeDklchk6loj5GyUjD67OF16nJcGnEdyigqhVuS8p4SvX7Db\\\\/Lw9RDz3SnP8DJJHoKZW5kc3RyZWFtCmVuZG9iago0IDAgb2JqCjw8L1R5cGUvUGFnZS9NZWRpYUJveFswIDAgNTk1IDg0Ml0vUmVzb3VyY2VzPDwvRm9udDw8L0YxIDEgMCBSPj4+Pi9Db250ZW50cyAyIDAgUi9QYXJlbnQgMyAwIFI+PgplbmRvYmoKMSAwIG9iago8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9IZWx2ZXRpY2EvRW5jb2RpbmcvV2luQW5zaUVuY29kaW5nPj4KZW5kb2JqCjMgMCBvYmoKPDwvVHlwZS9QYWdlcy9Db3VudCAxL0tpZHNbNCAwIFJdPj4KZW5kb2JqCjUgMCBvYmoKPDwvVHlwZS9DYXRhbG9nL1BhZ2VzIDMgMCBSPj4KZW5kb2JqCjYgMCBvYmoKPDwvUHJvZHVjZXIoaVRleHSuIDUuNS4xMy4yIKkyMDAwLTIwMjAgaVRleHQgR3JvdXAgTlYgXChBR1BMLXZlcnNpb25cKSkvQ3JlYXRpb25EYXRlKEQ6MjAyMzEwMDQxNjE2MzkrMDUnMzAnKS9Nb2REYXRlKEQ6MjAyMzEwMDQxNjE2MzkrMDUnMzAnKT4+CmVuZG9iagp4cmVmCjAgNwowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAzMTUgMDAwMDAgbiAKMDAwMDAwMDAxNSAwMDAwMCBuIAowMDAwMDAwNDAzIDAwMDAwIG4gCjAwMDAwMDAyMDMgMDAwMDAgbiAKMDAwMDAwMDQ1NCAwMDAwMCBuIAowMDAwMDAwNDk5IDAwMDAwIG4gCnRyYWlsZXIKPDwvU2l6ZSA3L1Jvb3QgNSAwIFIvSW5mbyA2IDAgUi9JRCBbPGNkYjRlMmVkODI3YzhjNmEyZjA3OGIxMTkwMjBjMGVkPjxjZGI0ZTJlZDgyN2M4YzZhMmYwNzhiMTE5MDIwYzBlZD5dPj4KJWlUZXh0LTUuNS4xMy4yCnN0YXJ0eHJlZgo2NTkKJSVFT0YK");
*/
String jsonString = "{ \"content\": \"" + b64 + "\", \"path\": \"komal_repo/Motivation.pdf\" }";
try (OutputStream os = conection.getOutputStream()) {
byte[] input = jsonString.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// Print Stataus code
System.out.println("Status Code: "+conection.getResponseCode());
// Get content from response and print in console. Use try with resource to close streams automatically
try (BufferedReader br = new BufferedReader(new InputStreamReader(conection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder resp = new StringBuilder();
String respLine = null;
while ((respLine = br.readLine()) != null) {
resp.append(respLine.trim());
}
System.out.println(resp.toString());
}
}
}
Result
PS : Tested in Thingworx 9.2.0
/VR
Thank you.Can you confirm if you have tried on https?
Thank you Velkumar for the much needed support.