20 Replies Latest reply on Jun 18, 2014 3:35 PM by paic RSS
    michaelfr Creator

    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

      • Pull in .XML website information into an infotable
        paic Collaborator

        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.

         



        • Pull in .XML website information into an infotable
          michaelfr Creator

          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!

           



          • Pull in .XML website information into an infotable
            michaelfr Creator

            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

             



            • Pull in .XML website information into an infotable
              michaelfr Creator

              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?

               



              • Pull in .XML website information into an infotable
                michaelfr Creator

                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

                 



                  • Pull in .XML website information into an infotable
                    paic Collaborator

                    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.

                     

                      • Pull in .XML website information into an infotable
                        michaelfr Creator

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

                         



                          • Pull in .XML website information into an infotable
                            paic Collaborator

                            What messages do you see in the application log?

                             

                              • Pull in .XML website information into an infotable
                                michaelfr Creator

                                [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]

                                 

                                  • Pull in .XML website information into an infotable
                                    paic Collaborator

                                    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

                                      • Pull in .XML website information into an infotable
                                        michaelfr Creator

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

                                         



                                          • Pull in .XML website information into an infotable
                                            paic Collaborator

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

                                             

                                              • Pull in .XML website information into an infotable
                                                michaelfr Creator

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

                                                 



                                                  • Pull in .XML website information into an infotable
                                                    paic Collaborator

                                                    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.

                                                      • Pull in .XML website information into an infotable
                                                        michaelfr Creator

                                                        Pai,

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

                                                        Thank you for all the help!

                                                         



                                                          • Pull in .XML website information into an infotable
                                                            paic Collaborator

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

                                                             

                                                              • Pull in .XML website information into an infotable
                                                                michaelfr Creator

                                                                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