REST + MID Server = No HTTP Header

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2013 01:37 PM
Background:
We are trying to integrate our Service-now instance with an application that provides a RESTful interface. This application is in our local space, so we must use a MID Server to access it. In addition, this application creates an authorization token and supplies that back in the response header. We need this authorization token because the application does not allow for authentication on every call. Only a call to a login URL will accept a basic login method. Calls to other URLs require a cookie or authorization token in a get/post header.
The Problem:
It appears that when we send a REST call through the MID Server, the MID Server does not pass back the HTTP header to the instance. When we try to execute code:
var r = new RESTMessage('myapplication', 'get'); r.setStringParameter('url', 'my/login/url'); var response = r.execute(); var k = 1; while ( response == null ) { gs.print( "waiting ... " + k + " seconds" ); response = r.getResponse( 1000 ); k++; if ( k > 30 ) { gs.log( 'service time-out' ); break; // service did not respond after 30 tries } } gs.print(response.getHeaders());
response.getHeaders() does not return anything. The ECC output, however, does correctly contain the HTTP Response Body with the confirmation of login. Also, response.getStatusCode() returns a 200 code (Success).
Testing:
I wasn't sure if this was a Service-now limitation or a MID Server limitation, so I took our application out of the picture entirely. I created a new REST call, but I sent it to another one of my Service-now environments and pointed it towards our Windows Server table. Since we do not need a MID server from one instance to another instance, I did not include a MID Server here. When I ran response.getHeader() again, I received the response header!! I then added a MID Server into the mix and called out to my other instance again. This time, when I ran response.getHeader(), it returned nothing.
So, my questions are: Why does this happen? Any suggestions on how I fix it (or a new way that fits with this anti-stateless cookie method 🙂 )?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2013 06:44 AM
Currently ServiceNow does not support getting SOAP or REST headers from responses when going through the MID Server. I logged an enhancement request/bug a few months ago. I believe/hope a solution will be provided in the Dublin release.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2013 07:06 AM
Until this fix is in place, one possible workaround would be to create a JavascriptProbe for the MID Server that executes Java code that posts the REST request and publishes the headers and results. It is a lot more work, and I haven't tried it. However, you could use the following blog articles as a guide:
JavascriptProbe Example/Basics
http://www.john-james-andersen.com/blog/service-now/javascriptprobe-and-mid-server-script-includes.html
Using Java Packages calls to issue RESTful requests and get headers and body back
http://www.john-james-andersen.com/blog/service-now/service-now-is-not-afraid-to-get-rest.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2014 01:14 PM
John, do you know if this enhancement request/bug has been resolved in the Dublin release?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2015 09:50 AM
This was hugely helpful; thank you.
The web service ran just fine from the Test UI Action, and I couldn't figure out why it wouldn't run from a script. This totally sorted that out.
Thanks!