Work Light - SOAP适配器无法解析<soapenv:envelope> request </soapenv:envelope>

时间:2013-03-04 11:00:58

标签: ibm-mobilefirst

我正在尝试创建一个使用 soapenv:Envelope 请求的 SOAP适配器。但是当我调用eclipse时,eclipse会产生以下错误 -       {       “错误”:[       “Ecma错误: TypeError:无法从undefined中读取属性\”Body \“      (C%3A%5Cdevelopment%5Cmywork%5CWorklight%5CWorklightApp       lications%5Cadapters%5CSOAPAdapter / SOAPAdapter-impl.js#40)”      ]     “信息”:[     ]     “isSuccessful”:false,     “警告”:[     ]      }

这似乎是一个SAXParser问题,因此我搜索了它并从IBM开发人员论坛获得了解决方案http://www.ibm.com/developerworks/forums/thread.jspa?threadID=454988 - 在eclipse.ini中的-vmargs行之后,添加它 行然后重启Eclipse: 的 -Dorg.xml.sax.driver = com.sun.org.apache.xerces.internal.parsers.SAXParser

我做到了,但我仍然遇到同样的错误。这是我的SOAP请求 -

 "<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:soap="http://soap.amazon.com">"+
  "<soapenv:Header/>"+
  "<soapenv:Body>"+
   "<soap:ActorSearchRequest soapenv:encodingStyle="http://schemas.xmlsoap.org"+
      "/soap/encoding/">"+
      "<ActorSearchRequest xsi:type="soap:ActorRequest" xs:type="type:ActorRequest"+ 
         "xmlns:xs="http://www.w3.org/2000/XMLSchema-instance">"+
         "<actor xsi:type="xsd:string" xs:type="type:string">abc</actor>"+
         "<page xsi:type="xsd:string" xs:type="type:string">1</page>"+
         "<mode xsi:type="xsd:string" xs:type="type:string">a</mode>"+
         "<tag xsi:type="xsd:string" xs:type="type:string">a</tag>"+
         "<type xsi:type="xsd:string" xs:type="type:string">a</type>"+
         "<devtag xsi:type="xsd:string" xs:type="type:string">a</devtag>"+            
      "</ActorSearchRequest>"+
      "</soap:ActorSearchRequest>"+
     "</soapenv:Body>"+
    "</soapenv:Envelope>";

提前感谢您的帮助。 --Yash

更新功能 -

function temperatureConvertor(celsiusTemp) {
            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:soap="http://soap.amazon.com">'+
                   '<soapenv:Header/>'+
                   '<soapenv:Body>'+
                      '<soap:ActorSearchRequest soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'+
                         '<ActorSearchRequest xsi:type="soap:ActorRequest" xs:type="type:ActorRequest" xmlns:xs="http://www.w3.org/2000/XMLSchema-instance">'+
                            '<actor xsi:type="xsd:string" xs:type="type:string">abc</actor>'+
                            '<page xsi:type="xsd:string" xs:type="type:string">1</page>'+
                            '<mode xsi:type="xsd:string" xs:type="type:string">a</mode>'+
                            '<tag xsi:type="xsd:string" xs:type="type:string">a</tag>'+
                            '<type xsi:type="xsd:string" xs:type="type:string">a</type>'+
                            '<devtag xsi:type="xsd:string" xs:type="type:string">a</devtag>'+            
                         '</ActorSearchRequest>'+
                      '</soap:ActorSearchRequest>'+
                   '</soapenv:Body>'+
                '</soapenv:Envelope>';              
            var input = {
                method : 'post',
                returnedContentType : 'plain',
                path : '/schemas2/AmazonWebServices.wsdl',
                body: {
                    content: request.toString(),
                    contentType: 'text/xml; charset=utf-8'
                }
            };              
            var result = WL.Server.invokeHttp(input);               
            return result.Envelope.Body;

}

更新了adapter.xml

            <?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <wl:adapter xmlns:wl="http://www.worklight.com/integration" xmlns:http="http://www.worklight.com/integration/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="SOAPAdapter">

            <displayName>SOAPAdapter</displayName>
            <description>SOAPAdapter</description>
            <connectivity>
                <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
                    <protocol>http</protocol>
                    <domain>soap.amazon.com</domain>
                    <port></port>           
                </connectionPolicy>
                <loadConstraints maxConcurrentConnectionsPerNode="2"/>
            </connectivity>

            <procedure name="temperatureConvertor"/>

        </wl:adapter>

1 个答案:

答案 0 :(得分:2)

不是将SOAP请求创建为字符串,而应将其创建为XML文本(E4X)。

意思是,您应该var request = "<mytag>" + myJSVar + "</mytag>";;而不是var request = <mytag> {myJSVar} </mytag>;

请参阅Using HTTP adapters with SOAP Services中的幻灯片5和6了解示例