WSO2 API Manager Auth 错误内容类型 [英] WSO2 API Manager Auth error content type

查看:31
本文介绍了WSO2 API Manager Auth 错误内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我配置了 WSO2 API 管理器,一切似乎都正常.

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

唯一困扰我的问题是,如果出现 Auth 异常,API 管理器总是返回带有 XML 内容类型的响应,例如,

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>

如果客户端使用 JSON 格式与我的 Web 服务通信,XML 响应会看起来有点奇怪.

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

有没有办法让 API Manager 提供 JSON 格式的错误响应?

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

推荐答案

这已经得到解决 在 API Manager 的最新版本中.通过添加或更新 WSO2HOME/repository/deployment/server/synapse-configs/default/sequences/_auth_failure_handler_.xml 中的 error_message_type 属性,可以将身份验证错误设置为 json 格式:

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"/>

我发现这还需要为axis2.xml 中的json 内容类型选择JSONBuilderJSONMessageFormatter(这是默认设置).

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.

这篇关于WSO2 API Manager Auth 错误内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆