IBM Worklight HTTP Adapter SOAP响应:XSL转换失败

时间:2013-09-12 13:43:17

标签: http xslt soap adapter ibm-mobilefirst

我已经构建了一个调用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 webservice返回的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>

1 个答案:

答案 0 :(得分:2)

适配器完全按照您的要求执行操作。在XSL转换中,您将从服务器中删除响应(不返回任何内容),然后您希望在转换后出现结果Envelope.Body

return result.Envelope.Body;

在XSL的输出中未定义Envelope,因此出现错误消息:

"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语句中再次执行它。