VBScript rest webservice 调用 returns 与 SoapUI 不同的格式
VBScript rest webservice call returns different format than SoapUI
我正在使用 VBScript 在数据流中调用 REST Web 服务。
当我使用 soapUI 测试 Web 服务时 returns xml 我可以使用 VBScript。
但是当我在我的 VBScript 中使用 Msxml2.ServerXMLHTTP.6.0 witn 时,它的 returns 数据格式不同,我无法解析。
我的 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
我完全没有输出。
首先,这是调用 samme 服务的 SoapUI 的输出,这个输出正是我在我的 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}
因为 API 支持多种响应格式,所以您必须告诉它使用哪种响应格式,这是使用 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.
区别在于 SoapUI 会自动设置 Accept
header 因为它总是处理 SOAP XML.
所以只需将 setRequestHeader
更改为;
objXmlHttpMain.setRequestHeader "Accept", "application/xml"
完成此操作后,您应该可以毫无问题地使用 objXmlHttpMain.responseXML
。目前它是空的,因为您要返回 JSON 而不是 XML.
我正在使用 VBScript 在数据流中调用 REST Web 服务。 当我使用 soapUI 测试 Web 服务时 returns xml 我可以使用 VBScript。 但是当我在我的 VBScript 中使用 Msxml2.ServerXMLHTTP.6.0 witn 时,它的 returns 数据格式不同,我无法解析。
我的 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
我完全没有输出。
首先,这是调用 samme 服务的 SoapUI 的输出,这个输出正是我在我的 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}
因为 API 支持多种响应格式,所以您必须告诉它使用哪种响应格式,这是使用 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.
区别在于 SoapUI 会自动设置 Accept
header 因为它总是处理 SOAP XML.
所以只需将 setRequestHeader
更改为;
objXmlHttpMain.setRequestHeader "Accept", "application/xml"
完成此操作后,您应该可以毫无问题地使用 objXmlHttpMain.responseXML
。目前它是空的,因为您要返回 JSON 而不是 XML.