How to set Content-type as application/json;charset=UTF-8 in a failed authentication response at service package level
Hi - Can someone please help me with the way to set the content-type in response object which would be sent when authentication at REST service package level fails. currently I am setting Param.pyChallenge to @java("PRAuthentication.DEFAULT_FAIL_STREAM") and the response in the corresponding HTML rule is set as below :
{ "procStatus":"FAILURE", "procStatusMessage":"Authentication failed."}
I tried to get the response object in the authentication activity but when trying to set content-Type it thows NullPointerException which means it is unable to get the response object:
javax.servlet.http.HttpServletResponse response = tools.getRequestor().getRequestorPage().getObject("HTTPServletResponse");
response.setContentType(request.getContentType());
Since authentication is done at service package level I am unable to send the response in json format to calling applications because Pega is setting default content type as text/html;charset=UTF-8. Any help in this regards would be really appreciated.