The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Rest messages with no response body is causing an error

Bendezium
Tera Expert

New to ServiceNow, please go easy on me 😛 I have a delete method AirWatch rest message that is being executed as a workflow activity. The API developer documentation for the AirWatch API states:

Delete Device
Functionality – Deletes the device information from the AirWatch Console and un-enrolls the device.
HTTP Method – DELETE
API URI – https://host/api/mdm/devices/{id}
You can delete a device using the following parameter:
Response Obtained – NA
Request payload – NA

When I execute the rest message as part of the workflow, the intended result from AirWatch is achieved, the object is indeed deleted. But a few observations:

  1. The activity in the sctask is marked as an error.
  2. If I hover my mouse over the activity in the workflow history, I can see it states "Fault Description: Error executing REST request: null"
  3. The rest message does not actually make an entry in the sys_outbound_http_log table even though I've enabled logging to All on the rest message.
  4. At the time the activity is executed, I can see the following stack trace on the syslog table:
REST Msg Outbound - RESTMessageClient : Error executing REST request: null: java.lang.NullPointerException: com.glide.communications.events.DirectHTTPEvent.getRequestBody(DirectHTTPEvent.java:226)
com.glide.outbound_http_log.log_entry.AllLogEntry.<init>(AllLogEntry.java:18)
com.glide.outbound_http_log.LogEntryFactory.getAllLogEntry(LogEntryFactory.java:89)
com.glide.outbound_http_log.LogEntryFactory.getLogEntry(LogEntryFactory.java:53)
com.glide.outbound_http_log.OutboundHTTPEventWatcher.watch(OutboundHTTPEventWatcher.java:40)
com.glide.communications.HTTPClient.notifyWatcher(HTTPClient.java:503)
com.glide.communications.HTTPRequest.notifyWatcher(HTTPRequest.java:219)
com.glide.communications.HTTPRequest.send(HTTPRequest.java:182)
com.glide.communications.HTTPRequest.del(HTTPRequest.java:148)
com.glide.rest.outbound.direct.DirectRESTRequestDispatcher.doDelete(DirectRESTRequestDispatcher.java:161)
com.glide.rest.outbound.direct.DirectRESTRequestDispatcher.doRequest(DirectRESTRequestDispatcher.java:103)
com.glide.rest.outbound.direct.DirectRESTRequestDispatcher.invoke(DirectRESTRequestDispatcher.java:50)
com.glide.rest.outbound.RESTMessageClient.invoke(RESTMessageClient.java:100)
com.glide.rest.outbound.RESTMessageClient.execute(RESTMessageClient.java:78)
com.snc.runbook_automation.element.providers.RestMessageJavaGateway.executeAndGetHTTPResponse(RestMessageJavaGateway.java:146)
com.snc.runbook_automation.element.providers.RestMessageProvider.doTask(RestMessageProvider.java:145)
com.snc.runbook_automation.element.providers.WebServiceProvider$1.doEvent(WebServiceProvider.java:235)
com.glideapp.workflow.element.ElementActivityProvider.handleEvent(ElementActivityProvider.java:189)
com.glideapp.workflow.element.ExecutingActivity.handleEvent(ExecutingActivity.java:64)
com.glideapp.workflow.queue.activity.ActivityManager.runActivity(ActivityManager.java:330)
com.glideapp.workflow.queue.activity.ActivityManager.runActivities(ActivityManager.java:260)
com.glideapp.workflow.queue.activity.ActivityManager.processCommand(ActivityManager.java:156)
com.glideapp.workflow.queue.command.ActiveCommandQueueDelegate.signal(ActiveCommandQueueDelegate.java:97)
com.glideapp.workflow.queue.command.ActiveCommandQueueDelegate.processCommand(ActiveCommandQueueDelegate.java:62)
com.glideapp.workflow.queue.command.CommandManager$CommandQueue.processCommand(CommandManager.java:367)
com.glideapp.workflow.queue.command.CommandManager.queue(CommandManager.java:135)
com.glideapp.workflow.WorkflowHelper.handleEvent(WorkflowHelper.java:176)
com.glideapp.workflow.WorkflowHelper.handleEventById(WorkflowHelper.java:266)
com.snc.discovery_automation.RBSensorProcessor.processSensors(RBSensorProcessor.java:54)
com.snc.discovery.SensorProcessor.processSinglePage(SensorProcessor.java:403)
com.snc.discovery.SensorProcessor.process(SensorProcessor.java:217)
sun.reflect.GeneratedMethodAccessor2169.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.mozilla.javascript.MemberBox.invoke(MemberBox.java:138)
org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:292)
org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2585)
org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1501)
org.mozilla.javascript.Interpreter.interpret(Interpreter.java:829)
org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:152)
org.mozilla.javascript.Context$ScriptCaller.call(Context.java:2939)
org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:151)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:563)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3429)
org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:164)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:279)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:118)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:82)
com.glide.script.Evaluator.evaluatePossiblePrefixedString(Evaluator.java:210)
com.glide.job.RunScriptJob.evaluateScript(RunScriptJob.java:166)
com.glide.job.RunScriptJob.execute(RunScriptJob.java:87)
com.glide.schedule.JobExecutor.lambda$executeJob$0(JobExecutor.java:108)
com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:111)
com.glide.schedule.JobExecutor.execute(JobExecutor.java:95)
com.glide.schedule_v2.SchedulerWorkerThread.executeJob(SchedulerWorkerThread.java:329)
com.glide.schedule_v2.SchedulerWorkerThread.lambda$process$0(SchedulerWorkerThread.java:192)
com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35)
com.glide.schedule_v2.SchedulerWorkerThread.process(SchedulerWorkerThread.java:192)
com.glide.schedule_v2.SchedulerWorkerThread.run(SchedulerWorkerThread.java:100)

I'd like to know if there is some noobish mistake I'm making? I can't imagine I'm the first person to cross this situation there, so I feel like there must be something I'm overlooking. Worst case scenario, I'll have the next activity check for the device I just tried to delete and branch from there, but this is fairly messy and would like to avoid it if at all possible. Thanks!

1 ACCEPTED SOLUTION

Dan156
Giga Contributor

I just had this exact problem and I believe we found the source of it. We were also using the DELETE method to reach out to an endpoint which returned a response body of null. The call was working as expected until we changed the sys_properties record for glide.outbound_http_log.override to true AND the property glide.outbound_http_log.override.level to all this cause the error you mention as well as failing to insert the call into the outbound http log BUT the call still worked as expected on the 3rd party system.

It seems to me the source of this problem comes from ServiceNow being unable to handle logging a REST response from a DELETE method where the response body is null .

I hope this saves some folks some time when they come across this, I also hope ServiceNow fixes this bug so that we can start capturing outbound http logs at a level other than basic without breaking requests that match the above criteria.

View solution in original post

5 REPLIES 5

Mike Patel
Tera Sage

Can you share code you have on workflow activity

if you are looking at body then it might be issue since there is nothing in res body.

you can do something like (just comment out .getBody() line from your code and use status field to check if it was success or not.)

var r = new sn_ws.RESTMessageV2('AirWatch API', 'delete');

var response = r.execute();
//var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
if (httpStatus == 200) {
    answer = 'yes';
} else {
    answer = 'no';
}

Hi Mike,

Thanks for writing! There is no code to share (I think). The workflow uses a standard rest message activity. I have created an activity after this that essentially does what you have proposed so I can continue on with the workflow, but it would be nice to still see see the rest call in the outbound http log and not have the activity show as an error.

Bendezium
Tera Expert

Hi Mike,

Thanks for writing! There is no code to share (I think). The workflow uses a standard rest message activity. I have created an activity after this that essentially does what you have proposed so I can continue on with the workflow, but it would be nice to still see see the rest call in the outbound http log and not have the activity show as an error.

Dan156
Giga Contributor

I just had this exact problem and I believe we found the source of it. We were also using the DELETE method to reach out to an endpoint which returned a response body of null. The call was working as expected until we changed the sys_properties record for glide.outbound_http_log.override to true AND the property glide.outbound_http_log.override.level to all this cause the error you mention as well as failing to insert the call into the outbound http log BUT the call still worked as expected on the 3rd party system.

It seems to me the source of this problem comes from ServiceNow being unable to handle logging a REST response from a DELETE method where the response body is null .

I hope this saves some folks some time when they come across this, I also hope ServiceNow fixes this bug so that we can start capturing outbound http logs at a level other than basic without breaking requests that match the above criteria.