1

我已经构建了一个调用soap web 服务的http 适配器==> 它工作正常。但是当我添加一个 xsl 转换文件并运行适配器过程时

        transformation : {
            type : 'xslFile',
            xslFile : 'filtered.xsl'
        }

和一个空的 xsl 文件

<xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:h="http://www.w3.org/1999/xhtml">
<xsl:output method="text"/>

<xsl:template match="/">
</xsl:template>

我有以下错误:

"Ecma Error: TypeError: Cannot read property \"Body\" from undefined

Web 服务返回的 xml 是正常的(使用 WireShark 检查)。

这是适配器代码:

function getLiveSessionsCountFiltered() {
var request = 
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:met="http://metricsdata.webservicesimpl.server.introscope.wily.com">
   <soapenv:Header/>
   <soapenv:Body>
      <met:getLiveMetricData soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <agentRegex xsi:type="xsd:string">myHost\|websphere\|myAgent</agentRegex>
         <metricPrefix xsi:type="xsd:string">WebSpherePMI\|servletSessionsModule:LiveCount</metricPrefix>
      </met:getLiveMetricData>
   </soapenv:Body>
</soapenv:Envelope>;

var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/introscope-web-services/services/MetricsDataService',
        headers: {'SOAPAction':""},
        body : {
            content: request.toString(),
            contentType: 'text/xml; charset=utf-8'
        },
        transformation : {
            type : 'xslFile',
            xslFile : 'filtered.xsl'
        }
    };

    var result = WL.Server.invokeHttp(input);
    return result.Envelope.Body;
}

我的 SOAP 网络服务返回的 XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns1:getLiveMetricDataResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://metricsdata.webservicesimpl.server.introscope.wily.com">
         <getLiveMetricDataReturn soapenc:arrayType="ns2:TimeslicedResultSetMetricData[8]" xsi:type="soapenc:Array" xmlns:ns2="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
            <getLiveMetricDataReturn href="#id0"/>
            <getLiveMetricDataReturn href="#id1"/>
            <getLiveMetricDataReturn href="#id2"/>
            <getLiveMetricDataReturn href="#id3"/>
            <getLiveMetricDataReturn href="#id4"/>
            <getLiveMetricDataReturn href="#id5"/>
            <getLiveMetricDataReturn href="#id6"/>
            <getLiveMetricDataReturn href="#id7"/>
         </getLiveMetricDataReturn>
      </ns1:getLiveMetricDataResponse>
      <multiRef id="id6" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:TimeslicedResultSetMetricData" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns3="urn:ca.wily.introscope.webservices">
         <metricData soapenc:arrayType="ns3:MetricData[1]" xsi:type="soapenc:Array">
            <metricData href="#id8"/>
         </metricData>
         <timesliceEndTime xsi:type="xsd:dateTime">2013-10-11T08:25:45.000Z</timesliceEndTime>
         <timesliceStartTime xsi:type="xsd:dateTime">2013-10-11T08:25:30.000Z</timesliceStartTime>
      </multiRef>
      <multiRef id="id7" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:TimeslicedResultSetMetricData" xmlns:ns4="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
         <metricData soapenc:arrayType="ns4:MetricData[1]" xsi:type="soapenc:Array">
            <metricData href="#id9"/>
         </metricData>
         <timesliceEndTime xsi:type="xsd:dateTime">2013-10-11T08:26:00.000Z</timesliceEndTime>
         <timesliceStartTime xsi:type="xsd:dateTime">2013-10-11T08:25:45.000Z</timesliceStartTime>
      </multiRef>
      <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:TimeslicedResultSetMetricData" xmlns:ns5="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
         <metricData soapenc:arrayType="ns5:MetricData[1]" xsi:type="soapenc:Array">
            <metricData href="#id10"/>
         </metricData>
         <timesliceEndTime xsi:type="xsd:dateTime">2013-10-11T08:24:15.000Z</timesliceEndTime>
         <timesliceStartTime xsi:type="xsd:dateTime">2013-10-11T08:24:00.000Z</timesliceStartTime>
      </multiRef>
      <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns6:TimeslicedResultSetMetricData" xmlns:ns6="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
         <metricData soapenc:arrayType="ns6:MetricData[1]" xsi:type="soapenc:Array">
            <metricData href="#id11"/>
         </metricData>
         <timesliceEndTime xsi:type="xsd:dateTime">2013-10-11T08:24:30.000Z</timesliceEndTime>
         <timesliceStartTime xsi:type="xsd:dateTime">2013-10-11T08:24:15.000Z</timesliceStartTime>
      </multiRef>
      <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns7:TimeslicedResultSetMetricData" xmlns:ns7="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
         <metricData soapenc:arrayType="ns7:MetricData[1]" xsi:type="soapenc:Array">
            <metricData href="#id12"/>
         </metricData>
         <timesliceEndTime xsi:type="xsd:dateTime">2013-10-11T08:24:45.000Z</timesliceEndTime>
         <timesliceStartTime xsi:type="xsd:dateTime">2013-10-11T08:24:30.000Z</timesliceStartTime>
      </multiRef>
      <multiRef id="id4" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns8:TimeslicedResultSetMetricData" xmlns:ns8="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
         <metricData soapenc:arrayType="ns8:MetricData[1]" xsi:type="soapenc:Array">
            <metricData href="#id13"/>
         </metricData>
     <timesliceEndTime xsi:type="xsd:dateTime">2013-10-11T08:25:15.000Z</timesliceEndTime>
     <timesliceStartTime xsi:type="xsd:dateTime">2013-10-11T08:25:00.000Z</timesliceStartTime>
  </multiRef>
  <multiRef id="id5" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns9:TimeslicedResultSetMetricData" xmlns:ns9="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <metricData soapenc:arrayType="ns9:MetricData[1]" xsi:type="soapenc:Array">
        <metricData href="#id14"/>
     </metricData>
     <timesliceEndTime xsi:type="xsd:dateTime">2013-10-11T08:25:30.000Z</timesliceEndTime>
     <timesliceStartTime xsi:type="xsd:dateTime">2013-10-11T08:25:15.000Z</timesliceStartTime>
  </multiRef>
  <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns10:TimeslicedResultSetMetricData" xmlns:ns10="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <metricData soapenc:arrayType="ns10:MetricData[1]" xsi:type="soapenc:Array">
        <metricData href="#id15"/>
     </metricData>
     <timesliceEndTime xsi:type="xsd:dateTime">2013-10-11T08:25:00.000Z</timesliceEndTime>
     <timesliceStartTime xsi:type="xsd:dateTime">2013-10-11T08:24:45.000Z</timesliceStartTime>
  </multiRef>
  <multiRef id="id11" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns11:MetricData" xmlns:ns11="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <agentName xsi:type="xsd:string">myHost|websphere|myAgent</agentName>
     <metricName xsi:type="xsd:string">WebSpherePMI|servletSessionsModule:LiveCount</metricName>
     <metricType xsi:type="xsd:int">258</metricType>
     <metricValue xsi:type="xsd:string">0</metricValue>
  </multiRef>
  <multiRef id="id12" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns12:MetricData" xmlns:ns12="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <agentName xsi:type="xsd:string">myHost|websphere|myAgent</agentName>
     <metricName xsi:type="xsd:string">WebSpherePMI|servletSessionsModule:LiveCount</metricName>
     <metricType xsi:type="xsd:int">258</metricType>
     <metricValue xsi:type="xsd:string">0</metricValue>
  </multiRef>
  <multiRef id="id14" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns13:MetricData" xmlns:ns13="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <agentName xsi:type="xsd:string">myHost|websphere|myAgent</agentName>
     <metricName xsi:type="xsd:string">WebSpherePMI|servletSessionsModule:LiveCount</metricName>
     <metricType xsi:type="xsd:int">258</metricType>
     <metricValue xsi:type="xsd:string">0</metricValue>
  </multiRef>
  <multiRef id="id13" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns14:MetricData" xmlns:ns14="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <agentName xsi:type="xsd:string">myHost|websphere|myAgent</agentName>
     <metricName xsi:type="xsd:string">WebSpherePMI|servletSessionsModule:LiveCount</metricName>
     <metricType xsi:type="xsd:int">258</metricType>
     <metricValue xsi:type="xsd:string">0</metricValue>
  </multiRef>
  <multiRef id="id10" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns15:MetricData" xmlns:ns15="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <agentName xsi:type="xsd:string">myHost|websphere|myAgent</agentName>
     <metricName xsi:type="xsd:string">WebSpherePMI|servletSessionsModule:LiveCount</metricName>
     <metricType xsi:type="xsd:int">258</metricType>
     <metricValue xsi:type="xsd:string">0</metricValue>
  </multiRef>
  <multiRef id="id15" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns16:MetricData" xmlns:ns16="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <agentName xsi:type="xsd:string">myHost|websphere|myAgent</agentName>
     <metricName xsi:type="xsd:string">WebSpherePMI|servletSessionsModule:LiveCount</metricName>
     <metricType xsi:type="xsd:int">258</metricType>
     <metricValue xsi:type="xsd:string">0</metricValue>
  </multiRef>
  <multiRef id="id8" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns17:MetricData" xmlns:ns17="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <agentName xsi:type="xsd:string">myHost|websphere|myAgent</agentName>
     <metricName xsi:type="xsd:string">WebSpherePMI|servletSessionsModule:LiveCount</metricName>
     <metricType xsi:type="xsd:int">258</metricType>
     <metricValue xsi:type="xsd:string">0</metricValue>
  </multiRef>
  <multiRef id="id9" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns18:MetricData" xmlns:ns18="urn:ca.wily.introscope.webservices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
     <agentName xsi:type="xsd:string">myHost|websphere|myAgent</agentName>
     <metricName xsi:type="xsd:string">WebSpherePMI|servletSessionsModule:LiveCount</metricName>
     <metricType xsi:type="xsd:int">258</metricType>
     <metricValue xsi:type="xsd:string">0</metricValue>
  </multiRef>

4

1 回答 1

2

适配器正在执行您告诉它执行的操作。在 XSL 转换中,您正在删除来自服务器的响应(不返回任何内容),然后您期望结果 Envelope.Body 在转换后出现

return result.Envelope.Body;

XSL 的输出中未定义信封,因此错误消息:

"Ecma Error: TypeError: Cannot read property \"Body\" from undefined

很有意义。你需要在变换上添加一些东西来创建一个 Envelope 和一个 Body:

<xsl:template match="/">
    {"Envelope": {"Body": {"content": "This is the content"}}}
</xsl:template>

或者,您可以将 Envelope/Body 留在 XSL 之外,只返回内容的 JSON。

但是,如果您在 XSL 中展开主体,则不能在函数的 return 语句中再次执行此操作。

于 2013-10-11T14:13:43.633 回答