cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

PostJSON in ThingWorx 9.0 Extension SDK

nmilleson
17-Peridot

PostJSON in ThingWorx 9.0 Extension SDK

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;
	}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@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.

View solution in original post

5 REPLIES 5
slangley
23-Emerald II
(To:nmilleson)

Hi @nmilleson.

 

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

 

Regards.

 

--Sharon

@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.

slangley
23-Emerald II
(To:nmilleson)

Hi @nmilleson.

 

Thank you for the follow-up!

 

I will pursue getting the instructions reviewed for update.

 

Regards.

 

--Sharon

slangley
23-Emerald II
(To:slangley)

Hi @nmilleson.

 

The article you referenced has been updated.  Please mark the appropriate response as the Accepted Solution (even if it's yours) for the benefit of others in the community.

 

Regards.

 

--Sharon

Thank you!  Much appreciated

Top Tags