我已经建立了一个使用OAUth介体的API,用于在外部后端中生成访问令牌。我正在使用cURL测试端点。通过启用有线日志,我看到正确接收了来自cURL的消息,然后APIM占用了外部后端,该后端回复所需信息。
但是,我遇到两个错误:
org.apache.axis2.AxisFault: Payload could not be written as JSON.
.
.
.
org.apache.axis2.AxisFault: Failed to submit the response
cURL永远不会收到响应并超时(来自服务器的空响应)。
请参阅附件中的碳记录图。
注意事项:
Axis2.xml已被编辑,在各自的部分中包含以下几行:
<messageBuilder contentType="application/hal+json" class="org.apache.axis2.json.JSONStreamBuilder"/>
.
.
.
<messageFormatter contentType="application/hal+json" class="org.apache.synapse.commons.json.JsonStreamFormatter"/>
我有两个调解政策
输入:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="secuenciaPrueba" statistics="enable" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<log description="" level="full"/>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<class name="org.wso2.apim.mediators.oauth.OAuthMediator">
<property name="endpointId" value="EP1"/>
</class>
</sequence>
输出:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="secuenciaPruebaOut" statistics="enable" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="OUT_MESSAGE" value="OUT_MESSAGE"/>
</log>
<log level="custom">
<property expression="get-property('ENDPOINT_PREFIX')" name="Endpoint"/>
<property expression="get-property('transport', 'Content-Type')" name="Content-Type"/>
<property expression="get-property('msgID')" name="Correlation_Id"/>
</log>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
</sequence>
我需要将JSON数据返回到cURL,这里缺少什么?
问题是messageFormatter和messageBuilder类错误。正确的设置是:
<messageFormatter contentType="application/hal+json"
class="org.apache.synapse.commons.json.JsonStreamFormatter"/>
.
.
.
<messageBuilder contentType="application/hal+json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"/>