REST request processing to set http status code and message


On API Gateway 10.3, I am using a request processing, over REST Virtual Service, that invokes a java service, in order to apply some validations. Whenever the validations are not succeeded one exception is raised (to stop the execution) and the http status code and messages are adapted.

To execute a manipulation of the http status code and message I am applying:

[size=9]private static void setStatusCode(int statusCode, String statusMessage, RestMessageContext msgCtx) throws ServiceException{

	HTTPResponse response = (HTTPResponse) msgCtx.getHttpResponse();
	response.getHeader().setResponse(statusCode, statusMessage);
	msgCtx.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE, statusCode);

	throw new ServiceException(statusMessage);


However, it seems the values set on “setResponse” and “setProperty” are totally ignored, since it always returns HTTP Status Code “500” and Message “Internal Server Error”.

Any idea what is missing here?

Thanks and regards.


The request/response transformation is a lot simpler in 10.2+ releases. Can you check

This also provides information on how to transform the status code.


Praveen, thanks for your reply.

I had already read the tutorial and only indicates how to transform the status code on Response Processing and Error Handling phases.

I think, to apply the transformation on Request Processing it must be programmatically, but could not find a way.


Hi João Felisberto,

If you want to transform anything in response, you should only do them in response stage (hence, Response processing and Error handling policies).

As a workaround to your use case, can you try throwing an exception from your IS service in request processing stage, and transform the resulting 500 status code to your own status code, by configuring another IS service in error handling policy.