VBScript rest webservice调用返回的格式与SoapUI不同

时间:2016-12-01 12:36:39

标签: json ajax vbscript asp-classic

我正在使用VBScript在数据流中调用REST Web服务。 当我使用soapUI测试web服务时,它返回xml,我可以参与VBScript。 但是当我在我的VBScript中使用Msxml2.ServerXMLHTTP.6.0时,它会返回我无法解析的不同格式的数据。

我的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

当我试图转移时

objXmlHttpMain.responsetext to objXmlHttpMain.responseXML

我根本没有输出。

首先,这是SoapUI调用samme服务的输出,这个输出实际上是我在我的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>

这是脚本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}

1 个答案:

答案 0 :(得分:2)

由于API支持多种响应格式,因此您必须告诉它使用哪种响应格式,这是使用HTTP标头Accept完成的。

  

来自14 Header Field Definitions
   Accept request-header字段可用于指定响应可接受的某些媒体类型。

不同之处在于SoapUI会自动设置Accept标头,因为它始终处理SOAP XML。

所以只需将setRequestHeader更改为

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

完成此操作后,您应该可以毫无问题地使用objXmlHttpMain.responseXML。目前它是空的,因为你正在返回JSON而不是XML。