1
votes

Using Worklight 6.2.0.0.

I'm trying to consume one of our corporate web services via Worklight's HTTP Adapter. I have the WSDL for the web service, and I used the "Discover Backend Services" tool to generate the adapter JavaScript and XML.

The web service has 2 input parameters and 3 output parameters, all strings.

When I come to invoke the procedure on the client, I'm doing this:

    var invocationData = {
        adapter : 'messageHandlerAdapter',
        procedure : 'messageHandlerService_messageHandler',
        parameters : ['a','b']
};

var invocationOptions = {
        onSuccess : messageHandlerSuccess,
        onFailure : messageHandlerFailure   
};  

WL.Client.invokeProcedure(invocationData,invocationOptions);

You can see the dummy parameters in the invocationData array. Running this results in the following error:

java.lang.String cannot be cast to org.mozilla.javascript.Scriptable

If I remove the parameters, I don't get an error and the web service call appears to be successful, but I don't get any response (obviously).

A search on the forums led me to this:

http://stackoverflow.com/questions/23192346/class-cast-java-lang-string-cannot-be-cast-to-org-mozilla-javascript-scriptable Which is along the same lines, and the response was that there might be an invalid JSON object somewhere. However, all I've done is used the auto-generated adapter code and called it.

I'm very new to Worklight, so any advice is gratefully received!

WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="messageHandler" targetNamespace="urn:messageHandler" xmlns:tns="urn:messageHandler" xmlns:S2="urn:messageHandler:messageHandler" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:S1="urn:soap-fault:details" xmlns="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation>EncodingType=DOC_LITERAL, WSA_Product=10.1A - N/A</wsdl:documentation>
  <wsdl:types>
<schema elementFormDefault="unqualified" targetNamespace="urn:soap-fault:details" xmlns="http://www.w3.org/2001/XMLSchema"><element name="FaultDetail"><complexType><sequence><element name="errorMessage" type="xsd:string"/><element name="requestID" type="xsd:string"/></sequence></complexType></element></schema>
<schema elementFormDefault="qualified" targetNamespace="urn:messageHandler:messageHandler" xmlns="http://www.w3.org/2001/XMLSchema"><element name="messageHandler"><complexType><sequence><element name="ipMessageParams" nillable="true" type="xsd:string"/><element name="ipMessageData" nillable="true" type="xsd:string"/></sequence></complexType></element><element name="messageHandlerResponse"><complexType><sequence><element name="result" nillable="true" type="xsd:string"/><element name="opMessageResponse" nillable="true" type="xsd:string"/><element name="opMessageData" nillable="true" type="xsd:string"/></sequence></complexType></element></schema>
  </wsdl:types>
  <wsdl:message name="messageHandler_messageHandlerResponse">
    <wsdl:part name="parameters" element="S2:messageHandlerResponse"/>
  </wsdl:message>
  <wsdl:message name="FaultDetailMessage">
    <wsdl:part name="FaultDetail" element="S1:FaultDetail"/>
  </wsdl:message>
  <wsdl:message name="messageHandler_messageHandler">
    <wsdl:part name="parameters" element="S2:messageHandler"/>
  </wsdl:message>
  <wsdl:portType name="messageHandlerObj">
    <wsdl:operation name="messageHandler">
      <wsdl:input message="tns:messageHandler_messageHandler"/>
      <wsdl:output message="tns:messageHandler_messageHandlerResponse"/>
      <wsdl:fault name="messageHandlerFault" message="tns:FaultDetailMessage"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="messageHandlerObj" type="tns:messageHandlerObj">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="messageHandler">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input>
    <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
    <soap:body use="literal"/>
      </wsdl:output>
      <wsdl:fault name="messageHandlerFault">
    <soap:fault name="messageHandlerFault" use="literal"/>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="messageHandlerService">
    <wsdl:port name="messageHandlerObj" binding="tns:messageHandlerObj">
<documentation></documentation>
      <soap:address location="redacted"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Here is a link to a pic of the Service description in Project Explorer.

enter image description here

2
Can you provide the WSDL?Idan Adar
It's a corporate web service, so it's a bit on the sensitive side. I will post but will obscure the location.Andy Smith
Did you try using adaptors?rooftop
I've expanded the Service definition out. It's just 2 string input parameters. The HTTP adapter seems to want parameters to be JSON'd in the invocationData object, so I presume I've done that correctly?Andy Smith
Is there an easy way to see the outbound SOAP message before it gets transmitted?Andy Smith

2 Answers

2
votes

Generally we pass XML to SOAP based web services. With the case to worklight we have to convert XML to JSON and pass it to adapter. Considering your input SOAP is like

<a>
   <b>value1</b>
   <c>value2</c>
</a> 

Your JSON for above XML would be

 params= {
      a:{
          b:value1,
          c:value2
        }
     }

So u will have to pass above JSON as parameter

headers={
        "SOAPAction": "YOUR ACTION NAME"
    }

And so your adapter call will look like this,

var invocationData = {
        adapter : 'messageHandlerAdapter',
        procedure : 'messageHandlerService_messageHandler',
        parameters : [params,headers]
};

var invocationOptions = {
        onSuccess : messageHandlerSuccess,
        onFailure : messageHandlerFailure   
};  

WL.Client.invokeProcedure(invocationData,invocationOptions);
0
votes

You currently have a service under your 'services' folder in your project.
In Project Explorer view right-click on your service and it should show you a sample parameter to be passed to the messageHandlerService_messageHandler procedure:

enter image description here

You can copy this sample JSON and invoke the adapter procedure by pasting and setting the sample values to your desired values:

enter image description here

If you also need to pass custom HTTP headers you should add a comma after the parameter JSON and add another JSON string with the custom headers.