Skip to main content
17-Peridot
October 15, 2020
Solved

PostJSON in ThingWorx 9.0 Extension SDK

  • October 15, 2020
  • 1 reply
  • 2888 views

Has anybody been successful using the ContentLoader functions in TWx 9.0 Extension SDK?  I've been following this example and this javadoc but I keep getting a null pointer exception.  Just to test my sanity, I used the same url, header, and content information inside a Composer service and I was successful.  I've attached the stack trace and the code I'm using is:


 

public Boolean myService() throws Exception {
	Boolean verify = false;	
		
	ContentLoader verifyCheck = new ContentLoader(); 
		
		
	String url = "https://postman-echo.com/post";
		
 JSONObject content = new JSONObject("{\"meta\":{\"key\": \"" + "abc" + "\"}}");
 String username = null;
 String password = null;
 JSONObject headers = null;
 Boolean ignoreSSLErrors = null;
 Boolean withCookies = null;
 Double timeout = null;
 Boolean useNTLM = null;
 String workstation = null;
 String domain = null;
 Boolean useProxy = null;
 String proxyHost = null;
 Integer proxyPort = null;
 String proxyScheme = null;
 
 try { 	
 _logger.warn("URL in myService(): " + url.toString()); 
 _logger.warn("Content in myService(): " + content.toString()); 
 	 
 verifyCheck.PostJSON(url, content, username, password, headers, 
 ignoreSSLErrors, withCookies, timeout, useNTLM, workstation, domain, useProxy, 
 proxyHost, proxyPort, proxyScheme); 	
 }
 catch(Exception e)
 {
 	StringWriter sw = new StringWriter();
 	PrintWriter pw = new PrintWriter(sw);
 	e.printStackTrace(pw);
 	
 	_logger.error("Exception in myService(): " + sw.toString()); 
 }
		return verify;
	}

 

 

Best answer by nmilleson

@slangley ,

 

Thanks for the reply.  I believe I found the issue.  In the example that I linked, all of the Boolean values are set to null.  I changed them all to false instead and that seems to have fixed the issue.  The PTC example may need to be updated.

1 reply

Support
October 27, 2020

Hi @nmilleson.

 

We're working internally to answer your question and will respond back as soon as we have more information.

 

Regards.

 

--Sharon

nmilleson17-PeridotAuthorAnswer
17-Peridot
October 27, 2020

@slangley ,

 

Thanks for the reply.  I believe I found the issue.  In the example that I linked, all of the Boolean values are set to null.  I changed them all to false instead and that seems to have fixed the issue.  The PTC example may need to be updated.

Support
October 27, 2020

Hi @nmilleson.

 

Thank you for the follow-up!

 

I will pursue getting the instructions reviewed for update.

 

Regards.

 

--Sharon