SOAP JS API - Proposed change


(Martin) #1

Hi,


In the file: packages/web_services/api/soap_api/web_services_caller.js the send() function invokes the callback function using:


    
    eval(callback_fnc+'(response)');


Is there any reason this line is not just:
    
    callback_fnc(response);


And the function passed as the callback_func variable, instead of a string?

I realise this will break existing code, but you could check the type of the variable for backward compatibility.

The reason for this is that is is not possible to pass other useful variables to the callback. To be consistent with jQuery style callbacks it would be good to be able to do something like:

    
    var location = 'http://www.mydomain.com/_web_services/soap-server';
    wsdl = 'http://www.mydomain.com/_web_services/soap-server?WSDL';
var soapBody = CloneAsset(123, 345, 1, 2, 1);

var soapRequest = constructSOAPRequest(soapBody, location);

send(wsdl, soapRequest, cloneAssetCallback);

var cloneAssetCallback = function(extra_variable) {
return function(response) {
    alert(extra_variable +' '+response);
}
}




Regards,

Martin

(Nic Hubbard) #2

Martin, why not just use the JS API for this?


(Jaco Roeloffs) #3

[quote]
Martin, why not just use the JS API for this?

[/quote]



can't clone assets with the js api.


(Martin) #4

[quote]
can't clone assets with the js api.

[/quote]



Precisely. I am having to use some elements of the SOAP API for the functionality not yet implemented in the JS API.



I would be happy to write the code and submit a patch, as long as there is not a reason it is being done this way.


(Martin) #5

[quote]
I would be happy to write the code and submit a patch, as long as there is not a reason it is being done this way.

[/quote]



Tried, tested and backward compatible.


    
    *** web_services_caller.js      2011-02-18 10:25:00.000000000 +0000
    --- web_services_caller.js.new  2011-02-25 12:17:27.000000000 +0000
    ***************
    *** 86,92 ****
        {
                if (xmlHttpObj.readyState == 4) {
                        var response    = xmlHttpObj.responseXML;
    !                       eval(callback_fnc+'(response)');
                }
        }
      
    --- 86,97 ----
        {
                if (xmlHttpObj.readyState == 4) {
                        var response    = xmlHttpObj.responseXML;
    ! 
    !                       if (typeof(callback_fnc) == 'function') {
    !                               callback_fnc(response);
    !                       } else {
    !                               eval(callback_fnc+'(response)');
    !                       }
                }
        }
      
    

(Benjamin Pearson) #6

[quote]
Tried, tested and backward compatible.


    
    *** web_services_caller.js      2011-02-18 10:25:00.000000000 +0000
    --- web_services_caller.js.new  2011-02-25 12:17:27.000000000 +0000
    ***************
    *** 86,92 ****
        {
                if (xmlHttpObj.readyState == 4) {
                        var response    = xmlHttpObj.responseXML;
    !                       eval(callback_fnc+'(response)');
                }
        }
      
    --- 86,97 ----
        {
                if (xmlHttpObj.readyState == 4) {
                        var response    = xmlHttpObj.responseXML;
    ! 
    !                       if (typeof(callback_fnc) == 'function') {
    !                               callback_fnc(response);
    !                       } else {
    !                               eval(callback_fnc+'(response)');
    !                       }
                }
        }
      
    

[/quote]



Added to the bug tracker here


(Martin) #7

[quote]
Added to the bug tracker here

[/quote]



:slight_smile:


(Nic Hubbard) #8

You could always build a trigger to do the cloning. Then just hit that specific URL, obviously with some restrictions, to clone the asset.


(Mohamed Haidar) #9

[quote]
Tried, tested and backward compatible.


    
    *** web_services_caller.js      2011-02-18 10:25:00.000000000 +0000
    --- web_services_caller.js.new  2011-02-25 12:17:27.000000000 +0000
    ***************
    *** 86,92 ****
        {
                if (xmlHttpObj.readyState == 4) {
                        var response    = xmlHttpObj.responseXML;
    !                       eval(callback_fnc+'(response)');
                }
        }
      
    --- 86,97 ----
        {
                if (xmlHttpObj.readyState == 4) {
                        var response    = xmlHttpObj.responseXML;
    ! 
    !                       if (typeof(callback_fnc) == 'function') {
    !                               callback_fnc(response);
    !                       } else {
    !                               eval(callback_fnc+'(response)');
    !                       }
                }
        }
      
    

[/quote]



Matrix has been updated with the suggested enhancement above and will be available in the next release. See Enhancement 4976

Alternatively see Public CVS Enhancement 4976


(system) #10

Thanks for the info.