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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Pull in .XML website information into an infotable

ptc-6292144
3-Newcomer

Pull in .XML website information into an infotable

Hello,

I am looking to learn how to get information from a .XML website and then parsing through the data and whenever it reaches a <name> or <product_description> to take that information and write it into the infotable. I have absolutely no clue how to do this so I need a lot of help.

Thank you,

Mike

20 REPLIES 20
paic
12-Amethyst
(To:ptc-6292144)

Hi Michael, what is the use case for this btw? Is this temporary information going out to the mashup or information that you wish to store for a period or permanent?
As to how to do this, please look in the Training section and look for a Video on Services/Consuming an external web page.
That should get you up and going.



It won't need to be permanent as the script will have to redownload the XML file every five minutes to check for updates so it will be purely for display in a mashup. I will watch the video and let you know if I have any questions.

Thanks Pai!



Pai,

Getting an error when running the first part of the video for my xml website (the loadxml snippet)

Wrapped java.lang.IllegalArgumentException: Illegal character in path at
index 0: \mespabeloitsharedProductionMonitorProdMonProduct2.xml Cause:
Illegal character in path at index 0:
\mespabeloitsharedProductionMonitorProdMonProduct2.xml

the website uses \ instead of / and I am assuming that is messing up the code.

Let me know if I am wrong.

Thank you,

Mike Francek



it seems the website is not so much a website but an XML document on our internal network. Would there be a different way I go about getting this XML information into Thingworx?



paic
12-Amethyst
(To:ptc-6292144)

Thingworx can load it, if it is a proper URL or if it is in the File Repository.

Although it should be possible to refer to the document by using something like:
file://server01\fshare\dir1\dir2\dir3\NameofFile

I am not getting the following error.

Wrapped org.apache.http.client.ClientProtocolException Cause: null

I switched the URL to read as the following

file://mespabeloit/shared/ProductionMonitor/ProdMonProduct2.xml



paic
12-Amethyst
(To:ptc-6292144)

A standard way I approach this is to first set the return type of the service as String and use GetText vs. GetXML and test that first.

ptc-6292144
3-Newcomer
(To:paic)

still getting the error. My output is set to String. Below is the code I used.


var params = {

    headers: undefined /* JSON /,<br>    useProxy: undefined / BOOLEAN /,<br>    proxyHost: undefined / STRING /,<br>    useNTLM: undefined / BOOLEAN /,<br>    ignoreSSLErrors: undefined / BOOLEAN /,<br>    proxyPort: undefined / INTEGER /,<br>    withCookies: undefined / BOOLEAN /,<br>    password: undefined / STRING /,<br>    url: 'file://mespabeloit\shared\ProductionMonitor\ProdMonProduct2.xml' / STRING /,<br>    workstation: undefined / STRING /,<br>    username: undefined / STRING /,<br>    proxyScheme: undefined / STRING /,<br>    domain: undefined / STRING /,<br>    timeout: undefined / NUMBER */
};

// result: STRING
var result = Resources["ContentLoaderFunctions"].GetText(params);



paic
12-Amethyst
(To:ptc-6292144)

What messages do you see in the application log?

ptc-6292144
3-Newcomer
(To:paic)

[context: com.thingworx.webservices.context.HttpExecutionContext@5051fe6c][message: Execution error in service script [BeloitPCPackaging Test_Get_ICS_Information] : Wrapped org.apache.http.client.ClientProtocolException Cause: null]

paic
12-Amethyst
(To:ptc-6292144)

Temporarily let's eliminate the file location.

Move the file to your Tomcat/webapps/Thingworx folder then you can refer to it by <localhost>/Thingworx/Nameofthefile

ptc-6292144
3-Newcomer
(To:paic)

Pai,

Getting the following error. Wrapped java.lang.IllegalStateException: Target host is null Cause: Target host is null

code is below


var params = {

    headers: undefined /* JSON /,<br>    useProxy: undefined / BOOLEAN /,<br>    proxyHost: undefined / STRING /,<br>    useNTLM: undefined / BOOLEAN /,<br>    ignoreSSLErrors: undefined / BOOLEAN /,<br>    proxyPort: undefined / INTEGER /,<br>    withCookies: undefined / BOOLEAN /,<br>    password: undefined / STRING /,<br>    url: '7.135.69.57/Thingworx/ProdMonProduct2.xml' / STRING /,<br>    workstation: undefined / STRING /,<br>    username: undefined / STRING /,<br>    proxyScheme: undefined / STRING /,<br>    domain: undefined / STRING /,<br>    timeout: undefined / NUMBER */
};

// result: STRING
var result = Resources["ContentLoaderFunctions"].GetText(params);



paic
12-Amethyst
(To:ptc-6292144)

Try that with http:// or https:// in front of it.

ptc-6292144
3-Newcomer
(To:paic)

it pulled the file when I used http:// but not when i used https://



paic
12-Amethyst
(To:ptc-6292144)

Ok great. At least for now you can go ahead and work on the parsing and consumption.

We'll have to take another look at the direct load from file, looks like it is not able to find it or load it, perhaps by adding an alias locally or using the IP vs. the machine name you can use the file reference to retrieve it.

ptc-6292144
3-Newcomer
(To:paic)

Pai,

Do you know how I could find out the IP address of the machine/server?

Thank you for all the help!



paic
12-Amethyst
(To:ptc-6292144)

not really my area of expertise, but you can try pinging it from your command prompt.

ptc-6292144
3-Newcomer
(To:paic)

Pai,

Was finally able to get the web url issue figured out, however now I am receiving the following text instead of the file

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd"&gt;

&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;You are not authorized to view this

page&lt;/TITLE&gt;

&lt;META HTTP-EQUIV="Content-Type" Content="text/html;

charset=Windows-1252"&gt;

&lt;STYLE type="text/css"&gt;

BODY

H1

H2

A:link

A:visited

&lt;/STYLE&gt;

&lt;/HEAD&gt;&lt;BODY&gt;&lt;TABLE width=500 border=0

cellspacing=10&gt;&lt;TR&gt;&lt;TD&gt;

&lt;h1&gt;You are not authorized to view this page&lt;/h1&gt;

You do not have permission to view this directory or page using the

credentials that you supplied because your Web browser is sending a

WWW-Authenticate header field that the Web server is not configured to

accept.

&lt;hr&gt;

&lt;p&gt;Please try the following:&lt;/p&gt;

&lt;ul&gt;

&lt;li&gt;Contact the Web site administrator if you believe you should

be able to view this directory or page.&lt;/li&gt;

&lt;li&gt;Click the &lt;a

href="javascript:location.reload()"&gt;Refresh&lt;/a&gt; button to try

again with different credentials.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;HTTP Error 401.2 - Unauthorized: Access is denied due to

server configuration.&lt;br&gt;Internet Information Services

(IIS)&lt;/h2&gt;

&lt;hr&gt;

&lt;p&gt;Technical Information (for support personnel)&lt;/p&gt;

&lt;ul&gt;

&lt;li&gt;Go to &lt;a

href="http://go.microsoft.com/fwlink/?linkid=8180"&gt;Microsoft Product

Support Services&lt;/a&gt; and perform a title search for the words

&lt;b&gt;HTTP&lt;/b&gt; and &lt;b&gt;401&lt;/b&gt;.&lt;/li&gt;

&lt;li&gt;Open &lt;b&gt;IIS Help&lt;/b&gt;, which is accessible in IIS

Manager (inetmgr),

and search for topics titled &lt;b&gt;About Security&lt;/b&gt;,

&lt;b&gt;Authentication&lt;/b&gt;, and &lt;b&gt;About Custom Error

Messages&lt;/b&gt;.&lt;/li&gt;

&lt;/ul&gt;

&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;



I can access the web url on the server in a web browser, but for some reason it seems I can't access it through Thingworx. Any suggestions?

Thank you,

Mike



Is there some type of way I can map it as a network drive on the server and access it that way?



paic
12-Amethyst
(To:ptc-6292144)

Looks like the account that Thingworx is running under does not have permission to that drive or file. So mapping the drive wont make much of a difference I believe. Best to fix the permissions on the target box so Thingworx can get full access to them.

Announcements


Top Tags