alexeybondarenko
alexeybondarenko

Reputation: 78

How to pass date object to SOAP request in Worklight Adapter

I use Worklight Adapters with HTTP SOAP request to backend service. So, I had several problems:

  1. How to use loop (ex. for) to create request string in Adapter?.
  2. How to pass the date string to request string. (ex. date argument has value "2014-10-12T00:00:00+03:00");

I has successful tested this request in SoapUI and received right response. When I try to create request dynamically from procedure arguments, invocation result is failed. Instead, when data is written in the request like string, all works well.

    var path = '...';
    function procedureName (sessGUID, id, number, date, status) {
        var request =
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soa="http://...">
                <soapenv:Header/>
                <soapenv:Body>
                    <soa:acceptPayment>
                        <id>{ id }</id>
                        <number>{ number }</number>
                        <date>{ date }</date>
                        <newStatus>{ status }</newStatus>
                        <sessGUID>{ sessGUID }</sessGUID>
                        <loginName></loginName>
                        <localRequestTime></localRequestTime>
                    </soa:acceptPayment>
                </soapenv:Body>
            </soapenv:Envelope>;

        var input = {
            method : 'post',
            returnedContentType : 'xml',
            path : path,
            body: {
                content: request.toString(),
                contentType: 'text/xml; charset=UTF-8'
            }
        };

        return WL.Server.invokeHttp(input);
    }

Upvotes: 0

Views: 341

Answers (1)

Raanan Avidor
Raanan Avidor

Reputation: 3583

  1. First of all it is not a must to use E4X, at the end you are just sending a string. You can build your string in any way you want.
    If you do want to use E4X you can use appendChild() in order to build your SOAP envelope. Create the element you want to loop on and append it to its parent.
  2. Did you try var d = new Date(); var n = d.toUTCString();?

Upvotes: 1

Related Questions