1

I'm using VBScript to call a REST Webservice in a dataflow. When i test the webservice with soapUI it returns xml that i am able to parte with VBScript. But when i use Msxml2.ServerXMLHTTP.6.0 witn in my VBScript it returns data in different format that i cannot parse.

My VBScript

endpoint="http://localhost/oozie/v2/job/"
parameter ="?show=info" 
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP.6.0") 
URL = endpoint & resource & parameter
on error resume next 
    objXmlHttpMain.open "GET",URL, False 

    objXmlHttpMain.setRequestHeader "Content-Type", "application/xml"


    objXmlHttpMain.send

     response = objXmlHttpMain.responsetext 
     WScript.Echo response

When i try to shift

objXmlHttpMain.responsetext to objXmlHttpMain.responseXML

I get no output at all.

First this is the output from SoapUI calling the samme service and this output is really what im am looking for in my vbscript-.

<Response xmlns="localhost/oozie/v2/job/0000140-161115133330924-oozie-oozi-W">
<acl null="true"/>
<actions>
   <e>
      <conf/>
      <consoleUrl>-</consoleUrl>
     <cred null="true"/>
     <data null="true"/>
     <endTime>Wed, 30 Nov 2016 13:56:51 GMT</endTime>
     <errorCode null="true"/>
     <errorMessage null="true"/>
     <externalChildIDs null="true"/>
     <externalId>-</externalId>
     <externalStatus>OK</externalStatus>
      <id>0000140-161115133330924-oozie-oozi-W@:start:</id>
      <name>:start:</name>
      <retries>0</retries>
      <startTime>Wed, 30 Nov 2016 13:56:51 GMT</startTime>
      <stats null="true"/>
      <status>OK</status>
      <toString>Action name[:start:] status[OK]</toString>
      <trackerUri>-</trackerUri>
      <transition>run_hive_script</transition>
     <type>:START:</type>
     <userRetryCount>0</userRetryCount>
     <userRetryInterval>10</userRetryInterval>
     <userRetryMax>0</userRetryMax>
  </e>
  <e>
<conf><![CDATA[<hive xmlns="uri:oozie:hive-action:0.4">
<job-tracker>localhost:80</job-tracker>
<name-node>hdfs://localhost:8020</name-node>
<script>/tmp/scripts/ingest/hivetest2.hql</script>
<configuration />
</hive>]]></conf>
             <consoleUrl>http://localhost:8088/proxy/application_1479975743615_0124/</console   Url >
       <cred null="true"/>
        <data null="true"/>
        <endTime>Wed, 30 Nov 2016 14:12:20 GMT</endTime>
        <errorCode>JA018</errorCode>
         <errorMessage>java.lang.ClassNotFoundException: Class      org.apache.oozie.action.hadoop.HiveMain not found</errorMessage>
      <externalChildIDs null="true"/>
      <externalId>job_1479975743615_0124</externalId>
      <externalStatus>FAILED/KILLED</externalStatus>
      <id>0000140-161115133330924-oozie-oozi-W@run_hive_script</id>
      <name>run_hive_script</name>
      <retries>0</retries>
      <startTime>Wed, 30 Nov 2016 13:56:52 GMT</startTime>
      <stats null="true"/>
      <status>ERROR</status>
      <toString>Action name[run_hive_script] status[ERROR]</toString>
      <trackerUri>localhost:8050</trackerUri>
      <transition>kill_job</transition>
      <type>hive</type>
      <userRetryCount>0</userRetryCount>
      <userRetryInterval>10</userRetryInterval>
      <userRetryMax>0</userRetryMax>
    </e>
    <e>
      <conf>Job failed</conf>
      <consoleUrl>-</consoleUrl>
      <cred null="true"/>
      <data null="true"/>
      <endTime>Wed, 30 Nov 2016 14:12:20 GMT</endTime>
      <errorCode>E0729</errorCode>
      <errorMessage>Job failed</errorMessage>
      <externalChildIDs null="true"/>
      <externalId>-</externalId>
      <externalStatus>OK</externalStatus>
       <id>0000140-161115133330924-oozie-oozi-W@kill_job</id>
       <name>kill_job</name>
       <retries>0</retries>
       <startTime>Wed, 30 Nov 2016 14:12:20 GMT</startTime>
       <stats null="true"/>
       <status>OK</status>
       <toString>Action name[kill_job] status[OK]</toString>
       <trackerUri>-</trackerUri>
       <transition null="true"/>
       <type>:KILL:</type>
       <userRetryCount>0</userRetryCount>
       <userRetryInterval>10</userRetryInterval>
       <userRetryMax>0</userRetryMax>
    </e>
 </actions>
 <appName>simple-Workflow</appName>
 <appPath>hdfs://localhost/tmp/scripts/ingest/oozie-test-wf-  params.xml</appPath>
 <conf><![CDATA[<configuration>
 <property>
 <name>oozie.wf.application.path</name>
 <value>hdfs:localhost/tmp/scripts/ingest/oozie-test-wf-params.xml</value>
 </property>
 <property>
 <name>user.name</name>
 <value>username</value>
 </property>
 <property>
 <name>jobTracker</name>
 <value>localhost:80</value>
 </property>
 <property>
 <name>mapreduce.job.user.name</name>
 <value>username</value>
 </property>
 <property>
 <name>nameNode</name>
 <value>hdfs://sktttst01hdp01.ccta.dk:8020</value>
 </property>
 </configuration>]]></conf>
 <consoleUrl>http://localhost:11000/oozie?job=0000140-161115133330924-oozie-oozi-W</consoleUrl>
 <createdTime>Wed, 30 Nov 2016 13:56:50 GMT</createdTime>
 <endTime>Wed, 30 Nov 2016 14:12:20 GMT</endTime>
 <externalId null="true"/>
 <group null="true"/>
 <id>0000140-161115133330924-oozie-oozi-W</id>
 <lastModTime>Wed, 30 Nov 2016 14:12:20 GMT</lastModTime>
 <parentId null="true"/>
 <run>0</run>
 <startTime>Wed, 30 Nov 2016 13:56:51 GMT</startTime>
 <status>KILLED</status>
 <toString>Workflow id[0000140-161115133330924-oozie-oozi-W] status[KILLED]    </toString>
 <user>username</user>
 </Response>

This is my output from the script response.text

{"appName":"simple-Workflow","externalId":null,"conf":"<configuration>\r\n  <property>\r\n    <name>oozie.wf.application.path<\/name>\r\n    <value>hd
fs:\/\/localhost\/tmp\/scripts\/ingest\/oozie-test-wf-params.xml<\/value>\r\n  <\/property>\r\n  <property>\r\n    <name>user.name<\/name
>\r\n    <value>username<\/value>\r\n  <\/property>\r\n  <property>\r\n    <name>jobTracker<\/name>\r\n    <value>localhost:80<\/value
>\r\n  <\/property>\r\n  <property>\r\n    <name>mapreduce.job.user.name<\/name>\r\n    <value>username<\/value>\r\n  <\/property>\r\n  <property>\r\
n    <name>nameNode<\/name>\r\n    <value>hdfs:\/\/localhost:8020<\/value>\r\n  <\/property>\r\n<\/configuration>","run":0,"acl":null,"ap
pPath":"hdfs:\/\/localhost\/tmp\/scripts\/ingest\/oozie-test-wf-params.xml","parentId":null,"lastModTime":"Wed, 30 Nov 2016 14:12:20 GMT"
,"consoleUrl":"http:\/\/localhost:11000\/oozie?job=0000140-161115133330924-oozie-oozi-W","createdTime":"Wed, 30 Nov 2016 13:56:50 GMT","s
tartTime":"Wed, 30 Nov 2016 13:56:51 GMT","toString":"Workflow id[0000140-161115133330924-oozie-oozi-W] status[KILLED]","id":"0000140-161115133330924-
oozie-oozi-W","endTime":"Wed, 30 Nov 2016 14:12:20 GMT","user":"username","actions":[{"cred":null,"userRetryMax":0,"trackerUri":"-","data":null,"erro
rMessage":null,"userRetryCount":0,"externalChildIDs":null,"externalId":"-","errorCode":null,"conf":"","type":":START:","transition":"run_hive_script",
"retries":0,"consoleUrl":"-","stats":null,"userRetryInterval":10,"name":":start:","startTime":"Wed, 30 Nov 2016 13:56:51 GMT","toString":"Action name[
:start:] status[OK]","id":"0000140-161115133330924-oozie-oozi-W@:start:","endTime":"Wed, 30 Nov 2016 13:56:51 GMT","externalStatus":"OK","status":"OK"
},{"cred":null,"userRetryMax":0,"trackerUri":"localhost:80","data":null,"errorMessage":"java.lang.ClassNotFoundException: Class org.apa
che.oozie.action.hadoop.HiveMain not found","userRetryCount":0,"externalChildIDs":null,"externalId":"job_1479975743615_0124","errorCode":"JA018","conf
":"<hive xmlns=\"uri:oozie:hive-action:0.4\">\r\n  <job-tracker>localhost:80<\/job-tracker>\r\n  <name-node>hdfs:\/\/sktttst01hdp01.cct
a.dk:8020<\/name-node>\r\n  <script>\/tmp\/scripts\/ingest\/hivetest2.hql<\/script>\r\n  <configuration \/>\r\n<\/hive>","type":"hive","transition":"k
ill_job","retries":0,"consoleUrl":"http:\/\/localhost:80\/proxy\/application_1479975743615_0124\/","stats":null,"userRetryInterval":10,
"name":"run_hive_script","startTime":"Wed, 30 Nov 2016 13:56:52 GMT","toString":"Action name[run_hive_script] status[ERROR]","id":"0000140-16111513333
0924-oozie-oozi-W@run_hive_script","endTime":"Wed, 30 Nov 2016 14:12:20 GMT","externalStatus":"FAILED\/KILLED","status":"ERROR"},{"cred":null,"userRet
ryMax":0,"trackerUri":"-","data":null,"errorMessage":"Job failed","userRetryCount":0,"externalChildIDs":null,"externalId":"-","errorCode":"E0729","con
f":"Job failed","type":":KILL:","transition":null,"retries":0,"consoleUrl":"-","stats":null,"userRetryInterval":10,"name":"kill_job","startTime":"Wed,
 30 Nov 2016 14:12:20 GMT","toString":"Action name[kill_job] status[OK]","id":"0000140-161115133330924-oozie-oozi-W@kill_job","endTime":"Wed, 30 Nov 2
016 14:12:20 GMT","externalStatus":"OK","status":"OK"}],"status":"KILLED","group":null}
Tomalak
  • 332,285
  • 67
  • 532
  • 628
havmaage
  • 573
  • 7
  • 25
  • That's strange... Why are you using VBScript when you have VB.NET available? – Tomalak Dec 01 '16 at 12:45
  • I execute the script from another platform that do not have .net . And the standard within our setup today is vbscript as scripting laungage. – havmaage Dec 01 '16 at 13:00
  • Then you should remove the irrelevant tags. Since your setup seems to be Classic ASP, I suggest you switch to JScript for this part of the task. This should not be a problem, Classic ASP supports both side-by-side. The response text is JSON. Parsing and handling is difficult in VBScript but much easier in JScript. – Tomalak Dec 01 '16 at 13:05
  • unfortunately i dont have access to the jsc compiler, We dont use .NET, so if it cannot be solved as XML parsing in vbscript i would be forced to attempt on REGEX and other string handling- – havmaage Dec 01 '16 at 13:44
  • JSC compiler? What for? That's .NET again, and you are not using .NET. I'm talking about JScript, which is Microsoft's JavaScript implementation and that runs just fine in ASP Classic websites without any modifications. – Tomalak Dec 01 '16 at 16:41
  • See this question. You need to do the same thing. http://stackoverflow.com/questions/1019223/any-good-libraries-for-parsing-json-in-classic-asp – Tomalak Dec 01 '16 at 16:42
  • 2
    @Tomalak the fact it returns JSON is irrelevant they want the XML response type. To tell the API to return XML just pass the `accept` header in your request not the `content-type`. Change the content type line to `objXmlHttpMain.setRequestHeader "Accept", "application/xml"`. – user692942 Dec 01 '16 at 18:09
  • @Lankymart Ahh, okay I misread this one completely. OP - sorry I was on the wrong track. – Tomalak Dec 01 '16 at 19:34
  • @Tomalak It's easily done, do myself all the time. – user692942 Dec 01 '16 at 19:49

1 Answers1

2

Because the API supports multiple response formats you have to tell it what response format to use, this is done using the HTTP Header Accept.

From 14 Header Field Definitions
The Accept request-header field can be used to specify certain media types which are acceptable for the response.

The difference will be SoapUI will set the Accept header automatically because it's always dealing with SOAP XML.

So just change the setRequestHeader to;

objXmlHttpMain.setRequestHeader "Accept", "application/xml"

Once this is done you should be able to use objXmlHttpMain.responseXML without issue. It's empty at the moment because you are returning JSON not XML.

user692942
  • 16,398
  • 7
  • 76
  • 175
  • Thank you very much for all the good reply's I realized a litle late that infact the return text is in jason format. I found a jason parser class and solved my problem. But i will try the setRequestHeader property to further testing. – havmaage Dec 06 '16 at 09:36
  • 1
    @havmaage If you're happy to use JSON *(JavaScript Object Notation, jason just sounds weird but it's how some pronounce it, not how it's written)* that's another approach, but if you're comfortable with XML just pass the `Accept` header and as long as the Web service supports XML as a response format you are good to go. – user692942 Dec 06 '16 at 09:44