cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1411
Views
0
Helpful
2
Replies

finesse api returns status code of 200 instead of 202 and returns response only when the dataType dataType: "jsonp"

Hi All,

I am using finesse api to develop a thin client using jquery and jabber. When I make finesse api call, I get the success message with Status code as 200 and the response as xml.

Below is my code

/**
* Constructs and sends a request API (using jQuery). Since this sample JS
* and page is hosted outside of the Finesse Web Services server, making an
* Ajax request to that server will violate the same-origin policy. A common
* solution is to setup a HTTP proxy which will forward request to the
* Web Services server.
*
* @param {String} url
Where to send the request to.
* @param {String} method
*"GET", "POST", "PUT"
* @param {Map} headers
Object containing key/value header params.
* @param {Map} params
Object containing key/value params.
* @param {Function(Object)} handler
Callback to handle response.
* @param {Function(Object)} errHandler
Callback to handle error with request.
* @param {Boolean} cache
True if request should cache, false otherwise.
* @param {String} xml
The xml to pass to the request 
* @private
*/
_sendReq = function (
        url, method,
        headers, params,
        handler, errHandler,
        cache, xml) {
    var newUrl = url,
    delim = "?",
    param,
    p = p || {},
    xhrArgs;
  
      

  
    //Add BASIC credentials to be sent with each requests. The JSESSIONID
    //token should automatically be handled by the browser.
    if (_credentials) {
        headers = headers || {};
        headers.Authorization = "Basic " + _credentials;
    }
    xmlData = xml;
    
    //Request arguments.

    contentType = "application/xml";

  

    if (method === "GET") {

      xhrArgs = {

        url: newUrl,
        type: method,
        dataType: "jsonp",
        // contentType: contentType,
        accept : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    // added processData: false to not send data on url
    processData : false,
        beforeSend: _createSetHeader(headers),
        success: _createSuccessHandler(handler),
        error: _createErrorHandler(errHandler),
        cache: cache

      }

    } else {
      xhrArgs = {
        url: newUrl,
        type: method,
          dataType: "jsonp",
    //contentType: contentType,
    accept : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    data : xmlData,
    // added processData: false to not send data on url
    processData : false,
        beforeSend: _createSetHeader(headers),
        success: _createSuccessHandler(handler),
        error: _createErrorHandler(errHandler),
        cache: cache
   }
    };

    //Uses jQuery to send Ajax request to backend.
    jQuery.ajax(xhrArgs);
};

this.signIn = function (agentid, extension, forcedFlag, handler, errHandler) {
    // var method = "POST",
   var method = "PUT",
   cache = "",
    url = _webappPath + "/api/User/" + agentid;
    xmlData = "<User><state>LOGIN</state><extension>"+extension+"</extension></User>";
     //console.log(xmlData);
    _sendReq(url, method, null, null, handler, errHandler, null, xmlData);
};

I am able to get the response only when the dataType: "jsonp" (tested using firebug). The status code is 200 as oppose to 202 as per the documentation. Also I am not able to read the response in the the app.

I am using jquery 1.11.3, finesse 10.5.

Any help is appreciated

Thanks,

Hash

1 Accepted Solution

Accepted Solutions

ewindgat
Level 5
Level 5

If you are trying to make an API call from outside the domain of your thin-client, to avoid cross-site scripting issues, you can use the MakeRequest method.

gadgets.io.makerequest(url, callback, opt_params);

View solution in original post

2 Replies 2

ewindgat
Level 5
Level 5

If you are trying to make an API call from outside the domain of your thin-client, to avoid cross-site scripting issues, you can use the MakeRequest method.

gadgets.io.makerequest(url, callback, opt_params);

Hi Ewindgat,

  I was able to resolve the issue by setting up the reverse proxy on apache http server. I see the request being a success, but the response is empty.

Below is the proxy setting:-

<Proxy *>

Order Deny,Allow

#Deny from all

Allow from all

</Proxy>

ProxyRequests Off

ProxyPass /finesse http://finesse server:80/finesse

ProxyPassReverse  /finesse http://finesse server:80/finesse

ProxyPass /http-bind http://finesse server:7071/http-bind/ keepalive=On disablereuse=Off

ProxyPassReverse /http-bind http://finesse server:7071/http-bind/

Also enabled:-

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_http_module modules/mod_proxy_http.so

My Ajax call for sign-in is as below:-

if (method === "GET") {

      xhrArgs = {

        url: newUrl,
        type: method,
        //dataType: "jsonp",
        contentType: contentType,
        accept : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    // added processData: false to not send data on url
    processData : false,
        beforeSend: _createSetHeader(headers),
        success: _createSuccessHandler(handler),
        error: _createErrorHandler(errHandler),
        cache: cache

      }

    } else {
      xhrArgs = {
        url: newUrl,
        type: method,
          //dataType: "jsonp",
    contentType: contentType,
    accept : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    data : xmlData,
    // added processData: false to not send data on url
    processData : false,
        beforeSend: _createSetHeader(headers),
        success: _createSuccessHandler(handler),
        error: _createErrorHandler(errHandler),
        cache: cache
   }
    };

    //Uses jQuery to send Ajax request to backend.
    jQuery.ajax(xhrArgs);
};

this.signIn = function (agentid, extension, forcedFlag, handler, errHandler) {
    // var method = "POST",
   var method = "PUT",
   cache = "",
    url = _webappPath + "/api/User/" + agentid;
    xmlData = "<User><state>LOGIN</state><extension>"+extension+"</extension></User>";
     //console.log(xmlData);
    _sendReq(url, method, null, null, handler, errHandler, null, xmlData);
};

Just wondering, if I am missing something in the proxy configuration or the ajax call?

Thanks in advance.

Thanks,

Hash