0
votes

I am trying to create a SOAP adapter which uses soapenv:Envelope request. But when I invoke the adapter eclipse produces following error - { "errors": [ "Ecma Error: TypeError: Cannot read property \"Body\" from undefined (C%3A%5Cdevelopment%5Cmywork%5CWorklight%5CWorklightApp lications%5Cadapters%5CSOAPAdapter/SOAPAdapter-impl.js#40)" ], "info": [ ], "isSuccessful": false, "warnings": [ ] }

It seems to be a SAXParser issue therefore I googled it and got a solution from IBM developers forum (http://www.ibm.com/developerworks/forums/thread.jspa?threadID=454988) - After the -vmargs line in eclipse.ini, add this line and then restart Eclipse: -Dorg.xml.sax.driver=com.sun.org.apache.xerces.internal.parsers.SAXParser

I did that but still I am getting the same error. Here is my SOAP 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>";

Updated function -

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;
}

Updated 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

1 Answers

2
votes

Instead of creating the SOAP request as a string you should create it as a XML literal (E4X).

Meaning, instead of var request = "<mytag>" + myJSVar + "</mytag>"; you should do var request = <mytag> {myJSVar} </mytag>;

See slides 5 and 6 in Using HTTP adapters with SOAP Services for examples