Question
Mike Yackanich · Jan 13, 2021

How to set HTTP Response Status Code in httpResponse object

Hi all,

I have a passthru REST setup using EnsLib.HTTP.GenericService and EnsLib.HTTP.GenericOperation. Works well.

I am adding some logic to the Operation and for some scenarios I want to return an HTTP 40x response status code.

I create an httpResponse object within the Business Operation, but I can't figure out how to set the http response status code that is returned to my Posstman client that initiated the request. I set StatusCode=400, and StatusLine and ReasonPhrase properties - but when the ultimate requestor (Postman) receives the response back it is a 200 status code. I am quitting the OnMessage method with status of $$$OK - which I suspect is being interpreted as HTTP response status code of 200. But I thought the httpResponse.StatusCode property setting of 400 would override that (?)

So how do I control the status code of the response? Can that be done within the httpResponse object within the Business Operation? Or do I need to subclass the related Business Service?

Product version: 
IRIS 2020.4
00
1 0 2 35

Replies

This is how we handled that in Cache 2018 for a REST connection.

s %response.Status = $$$HTTP401UNAUTHORIZED

Thanks for the feedback Don. I ended up calling WRC and was informed that a Business Service alone does not allow control of the HTTP response status code other than either 200 or 500. A CSP layer is apparently needed in order to expose %request.Status.