REST call via mid server debugging

erikbos
Giga Contributor

Hi,

I am trying to setup a REST call to retrieve data from an internal application via the midserver. I have defined the webserver via the UI and use JS to make the call and use the predefined webservice. In the WS definition for the GET method I have set the mid server to use.

At the moment I am just interested in making the call itself and do not care yet about parsing the json response yet: I am trying it with a few lines of code to log whether the call itself was successful or not.

var r = new sn_ws.RESTMessageV2('Device42', 'get');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log(httpStatus);

The code executes but hangs and I need to terminate it.

In the ECC queue I see an entry for every attempt I have done so far so I think the API call request gets queued for the mid server. An ECC queue entry contains the following XML as content:

<?xml version="1.0" encoding="UTF-8"?>

<parameters>

  <parameter name="message_headers" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;fields/&gt;"/>

  <parameter name="message_parameters" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;fields/&gt;"/>

  <parameter name="source" value="X"/>

  <parameter name="name" value="get"/>

  <parameter name="rest_user" value="............."/>

  <parameter name="rest_password" value="enc:...................."/>

</parameters>

On the mid server in the logs I do not see anything related to REST messages, this API end point, etc: like it did not receive this ecc queue entry at all. (I have set 'debug.logging' to true).  


Doing the API call by hand using curl on the mid server works fine so connectivity from the mid server to the internal application is ok.

Any idea how I debug this any further?

1 ACCEPTED SOLUTION

silas1
ServiceNow Employee
ServiceNow Employee

Erik, one thing I notice in the log is that the rest message appears to be null:


REST Msg Outbound - RESTMessageClient : Executing: Outbound REST Message/Method: null/get


Are you sure you're accessing the Rest message correctly by name? One thing to keep in mind, if this is part of a scoped application you might need to reference the rest message by it's scoped name e.g. "x_acme_myapp.Device42".


View solution in original post

6 REPLIES 6

silas1
ServiceNow Employee
ServiceNow Employee

Hi Erik, you can turn on the property glide.rest.outbound.debug=true to see what's happening with the request.


erikbos
Giga Contributor

Hi Silas,



Thanks for your response. With the debug settings I get a few logging entries:



[0:00:05.373] Script completed in scope global: script



REST Msg Outbound - RESTMessageClient : Executing synchronous request


REST Msg Outbound - RESTMessageClient : Executing: Outbound REST Message/Method: null/get


HTTP Request:


  GET https://X/api/1.0/buildings/all/


Basic Auth: true


  Username: ********


  Password: ********


Mutual Auth: false


ECC Queue: true


  MID Server: nlsrvud-snp01


  ECC Correlator: null


  ECC Params: NONE




REST Msg Outbound - ECCRESTRequestDispatcher : Inserting into ECC Queue with details: RESTProbe get https://X/api/1.0/buildings/all/ null,mid.server.nlsrvud-snp01


REST Msg Outbound - ECCRESTRequestDispatcher : Inserting into ECC Queue with payload: <?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="message_headers" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;fields/&gt;"/><parameter name="message_parameters" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;fields/&gt;"/><parameter name="source" value="https://X//api/1.0/buildings/all/"/><parameter name="name" value="get"/><parameter name="rest_user" value="********"/><parameter name="rest_password" value="enc:X=="/></parameters>


REST Msg Outbound - RESTMessageClient : Response: com.glide.rest.outbound.ecc.ECCRESTResponse@f82f0dECC Output:


  Output Queue SysId: c611e0700f828e00661b7f5ce1050e76


  Timeout (seconds): 300




Time: 0:00:00.136 id: tomtomdev_1[glide.18] for: (SELECT ecc_queue00010.`sys_id`, 'ecc_queue0001' AS `sys_table_name` FROM ecc_queue0001 ecc_queue00010   WHERE ecc_queue00010.`response_to` = 'c611e0700f828e00661b7f5ce1050e76') UNION ALL (SELECT ecc_queue00020.`sys_id`, 'ecc_queue0002' AS `sys_table_name` FROM ecc_queue0002 ecc_queue00020   WHERE ecc_queue00020.`response_to` = 'c611e0700f828e00661b7f5ce1050e76') UNION ALL (SELECT ecc_queue00030.`sys_id`, 'ecc_queue0003' AS `sys_table_name` FROM ecc_queue0003 ecc_queue00030   WHERE ecc_queue00030.`response_to` = 'c611e0700f828e00661b7f5ce1050e76') UNION ALL (SELECT ecc_queue00040.`sys_id`, 'ecc_queue0004' AS `sys_table_name` FROM ecc_queue0004 ecc_queue00040   WHERE ecc_queue00040.`response_to` = 'c611e0700f828e00661b7f5ce1050e76') UNION ALL (SELECT ecc_queue00050.`sys_id`, 'ecc_queue0005' AS `sys_table_name` FROM ecc_queue0005 ecc_queue00050   WHERE ecc_queue00050.`response_to` = 'c611e0700f828e00661b7f5ce1050e76') UNION ALL (SELECT ecc_queue00060.`sys_id`, 'ecc_queue0006' AS `sys_table_name` FROM ecc_queue0006 ecc_queue00060   WHERE ecc_queue00060.`response_to` = 'c611e0700f828e00661b7f5ce1050e76')


*** Script: 404


silas1
ServiceNow Employee
ServiceNow Employee

Erik, one thing I notice in the log is that the rest message appears to be null:


REST Msg Outbound - RESTMessageClient : Executing: Outbound REST Message/Method: null/get


Are you sure you're accessing the Rest message correctly by name? One thing to keep in mind, if this is part of a scoped application you might need to reference the rest message by it's scoped name e.g. "x_acme_myapp.Device42".


silas1
ServiceNow Employee
ServiceNow Employee

Also, you did get a response back from the server, it's a 404. The reason it "hangs" is because it has to wait to be picked up by the MID server which I believe will poll for work every 15 seconds. Note that if you don't care about the response i.e. if it's a fire and forget kind of request, you can send the request with .execute() and then don't call any method on the response like getBody or getStatus -- those will cause the client to block waiting for the response.