4

I have WSO2 API Manager configured and everything seems to work fine.

The only issues bothering me is that in case of an Auth exception, the API manager always returns the response with XML content type, e.g.,

<ams:fault xmlns:ams="http://wso2.org/apimanager/security"><ams:code>900904</ams:code><ams:message>Access Token Inactive</ams:message><ams:description>Access failure for API: /exchange, version: 1.0 with key: 1139a466ebfd825aca953ad7259b9f45</ams:description></ams:fault>

In case of client communicates with my web service with JSON format, the XML response will look a little bit strange.

Is there any ideas how to make API Manager provide error response in JSON format?

Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
  • Do you get this response for both XML and JSON responses? – Nadeesha Jul 17 '13 at 03:27
  • I get the XML response all the time the API Manager I call the service and API Manager fails to authenticate or authorize the caller. It doesn't matter if I use Content-Type or Accepts header. (BTW I think carbon just removes such headers) – user2461343 Jul 17 '13 at 19:44
  • I am sorry but your scenario is not clear to me, what your saying is API Manager is failing to communicate with the Backend service or to authenticate your request? If your interested in XML to JSON conversion that can be done at the API Gateway. – Nadeesha Jul 18 '13 at 03:45
  • The error messages returned by API Manager, like auth error in my initial question, are always returned in XML. Is it possible to make API Manager respond in JSON in such cases? – user2461343 Jul 18 '13 at 15:09
  • Can you try http://lkabimaran.blogspot.com/2014/12/how-to-change-authentication-failure.html ? – Abimaran Kugathasan Nov 10 '17 at 08:20

1 Answers1

3

This has been addressed in recent versions of API Manager. Auth errors can be set to json format by adding or updating the error_message_type property in WSO2HOME/repository/deployment/server/synapse-configs/default/sequences/_auth_failure_handler_.xml:

<property name="error_message_type" value="application/json"/>

I've found this also requires JSONBuilder and JSONMessageFormatter to be selected for the json content type in axis2.xml (which is the default setting).

For older versions, this article explains how to manually do the same.

Facundo Olano
  • 2,492
  • 2
  • 26
  • 32