2 Replies Latest reply on Nov 2, 2016 4:06 AM by spanda-2 RSS
    spanda-2 Newbie

    SAXParseException while making a POST call in thingworx

    Hi,

    I am new to Thingworx. I am trying to make a post rest call from thingworx. Here is the script that I have written in the service of a thing.

     

    var result = null;

    var params = {
    //proxyScheme: undefined /* STRING */,
    //headers: undefined /* JSON */,
    //ignoreSSLErrors: undefined /* BOOLEAN */,
    //useNTLM: undefined /* BOOLEAN */,
    //workstation: undefined /* STRING */,
    //useProxy: undefined /* BOOLEAN */,
    //withCookies: undefined /* BOOLEAN */,
    //proxyHost: undefined /* STRING */,
    url: Things["Windchilldemo1"].getRestUrl() + "/bac/import" /* STRING */,
    content: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><BACSpec xmlns=\"http://www.ptc.com/bac\"><Profile><name>newProfile</name></Profile></BACSpec>",
    //timeout: 60 /* NUMBER */,
    //proxyPort: undefined /* INTEGER */,
    //password: undefined /* STRING */,
    //domain: undefined /* STRING */,
    //username: undefined /* STRING */
    };


    result = Resources["ContentLoaderFunctions"].PostXML(params);

     

    At server side I have jaxb implementation for the XML structure. But it does not hit the url.

     

    I am getting the following error.

    Wrapped org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 10; DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true. Cause: DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true.

     

    Is the value for "content" converted to JAVA object on server side?

     

    Please guide me to resolve this issue.

    Thanks in advance.

      • Re: SAXParseException while making a POST call in thingworx
        pchung Collaborator

        You are able to make this call using something like Postman correct?

        You may want to try as PostText first.

          • Re: SAXParseException while making a POST call in thingworx
            spanda-2 Newbie

            Thanks Pai for the reply.

            There were minor issues on server side. I fixed those issues.

             

            For the sake of simplicity I have taken a more simplified object structure.
            message body in postman is
            {
               "spec": "my<></>Spec",
               "deliveryUrl": "http://vagrant.ptcnet.ptc.com:2280/Windchill/servlet/rest/bac/import"
            }

            The result is as follows:
            {
              "importReportContent": "my<></>Spec : http://vagrant.ptcnet.ptc.com:2280/Windchill/servlet/rest/bac/import"
            }


            In thingworx, The snippet in the service is like this.

            var result = null;
            var params = {
            proxyScheme: undefined /* STRING */,
            headers: undefined /* JSON */,
            ignoreSSLErrors: undefined /* BOOLEAN */,
            useNTLM: undefined /* BOOLEAN */,
            workstation: undefined /* STRING */,
            useProxy: undefined /* BOOLEAN */,
            withCookies: undefined /* BOOLEAN */,
            proxyHost: undefined /* STRING */,
            url: "http://vagrant.ptcnet.ptc.com:2280/Windchill/servlet/rest/bac/import" /* STRING */,
                content: { "spec": "mySpec",  "deliveryUrl": "myURL" } /* JSON */,
            timeout: 60 /* NUMBER */,
            proxyPort: undefined /* INTEGER */,
            password: undefined /* STRING */,
            domain: undefined /* STRING */,
            contentType: undefined /* STRING */,
            username: undefined /* STRING */
            };

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

            result = jsonResult["importReportContent"];


            This returns empty result without any error. I tried with providing a wrong url. then also I got empty result without any error. So it seems that the url is not being used. Please let me know if I am doing anything wrong or missed anything.

             

            Behaviour is the same with PostText as well.

             

            Thanks