Api WSO2 PayloadFactory正在发送用jsonObject包装的json
我正在使用WSO2 API Manager 1.7.0,正在做一个简单的payloadfactory,试图将GET调用转换为传递json负载的POST调用 但是,当我查看日志文件时,似乎WSO2正在发送用{“jsonObject”:[myjson]}包装的json 我是WSO2新手,不确定需要使用什么配置设置来停止此操作。我假设这是一个配置设置,因为在我找到的任何示例或文档中都没有其他人提到这一点 我的api如下所示:Api WSO2 PayloadFactory正在发送用jsonObject包装的json,api,wso2,jsonobject,wso2-am,Api,Wso2,Jsonobject,Wso2 Am,我正在使用WSO2 API Manager 1.7.0,正在做一个简单的payloadfactory,试图将GET调用转换为传递json负载的POST调用 但是,当我查看日志文件时,似乎WSO2正在发送用{“jsonObject”:[myjson]}包装的json 我是WSO2新手,不确定需要使用什么配置设置来停止此操作。我假设这是一个配置设置,因为在我找到的任何示例或文档中都没有其他人提到这一点 我的api如下所示: "POST http://localhost:81/Service/Proc
"POST http://localhost:81/Service/ProcessRequest HTTP/1.1[\r][\n]"
"Authorization: Basic asdfadfadfadfadfadfadfa=[\r][\n]"
"Accept-Encoding: gzip,deflate[\r][\n]"
"Content-Type: application/json[\r][\n]"
"activityID: 2342342342342342342342342[\r][\n]"
"Transfer-Encoding: chunked[\r][\n]"
"Host: localhost:81[\r][\n]"
"Connection: Keep-Alive[\r][\n]"
"User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
"[\r][\n]"
I/O session http-outgoing-2-3 11.11.11.11:12345<->192.168.1.1:8080[ACTIVE][rw:w]: 0 bytes written
http-outgoing-2: Produce output
I/O session http-outgoing-2-3 11.11.11.11:12345<->192.168.1.1:8080[ACTIVE][rw:w]: 230 bytes written
"db[\r][\n]"
"{"jsonObject":{"UserType":"User"}}[\r][\n]"
"0[\r][\n]"
"[\r][\n]"
<api name="admin--JJJJJ" context="/jjjjj" version="v1.0" version-type="url">
<resource methods="GET" url-mapping="/documents">
<inSequence>
<payloadFactory media-type="json">
<format>{"UserType":"User"}</format>
<args/>
</payloadFactory>
<property name="Authorization" expression="fn:concat('Basic ', base64Encode('user:password'))" scope="transport"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<log>
<property name="JSON-Payload" expression="json-eval($.)"/>
</log>
<send>
<endpoint name="admin--JJJJJ_APIproductionEndpoint_0">
<http trace="enable" method="post" uri-template="http://localhost:81/Service/ProcessRequest"></http>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
<handlers>
...
</handlers>
</api>
“POSThttp://localhost:81/Service/ProcessRequest HTTP/1.1[\r][\n]“
“授权:基本ASDFADFADFA=[\r][\n]”
接受编码:gzip,解压缩[\r][\n]
“内容类型:应用程序/json[\r][\n]”
“活动ID:2342[\r][\n]”
“传输编码:分块[\r][\n]”
“主机:本地主机:81[\r][\n]”
“连接:保持活动状态[\r][\n]”
“用户代理:Synapse PT HttpComponents NIO[\r][\n]”
“[\r][\n]”
I/O会话http-outgoing-2-3 11.11.11.11:12345192.168.1.1:8080[活动][rw:w]:写入0字节
http-outgoing-2:生成输出
I/O会话http-outgoing-2-3 11.11.11.11:12345192.168.1.1:8080[活动][rw:w]:写入230字节
“数据库[\r][\n]”
{“jsonObject”:{“用户类型”:“用户”}[\r][\n]
“0[\r][\n]”
“[\r][\n]”
似乎应用于服务调用的日志文件部分如下所示:
"POST http://localhost:81/Service/ProcessRequest HTTP/1.1[\r][\n]"
"Authorization: Basic asdfadfadfadfadfadfadfa=[\r][\n]"
"Accept-Encoding: gzip,deflate[\r][\n]"
"Content-Type: application/json[\r][\n]"
"activityID: 2342342342342342342342342[\r][\n]"
"Transfer-Encoding: chunked[\r][\n]"
"Host: localhost:81[\r][\n]"
"Connection: Keep-Alive[\r][\n]"
"User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
"[\r][\n]"
I/O session http-outgoing-2-3 11.11.11.11:12345<->192.168.1.1:8080[ACTIVE][rw:w]: 0 bytes written
http-outgoing-2: Produce output
I/O session http-outgoing-2-3 11.11.11.11:12345<->192.168.1.1:8080[ACTIVE][rw:w]: 230 bytes written
"db[\r][\n]"
"{"jsonObject":{"UserType":"User"}}[\r][\n]"
"0[\r][\n]"
"[\r][\n]"
<api name="admin--JJJJJ" context="/jjjjj" version="v1.0" version-type="url">
<resource methods="GET" url-mapping="/documents">
<inSequence>
<payloadFactory media-type="json">
<format>{"UserType":"User"}</format>
<args/>
</payloadFactory>
<property name="Authorization" expression="fn:concat('Basic ', base64Encode('user:password'))" scope="transport"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<log>
<property name="JSON-Payload" expression="json-eval($.)"/>
</log>
<send>
<endpoint name="admin--JJJJJ_APIproductionEndpoint_0">
<http trace="enable" method="post" uri-template="http://localhost:81/Service/ProcessRequest"></http>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
<handlers>
...
</handlers>
</api>
{“用户类型”:“用户”}
...
我不确定db和0在传输中来自何处,但我从服务返回的错误似乎是由包装jsonObject引起的
是否有人对我如何防止这种包装或在发送之前修改有效负载以移除它有任何提示或想法。或者,我想有一种更好甚至不同的方法可以将GET请求转换为带有json负载的POST
感谢您提供有关我做错了什么的提示。将axi2.xml(/repository/conf/axis2/axis2.xml)文件中的MessageFormatter更改为
并注释json的默认消息格式化程序
<!--messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/-->
在这里了解有关json支持的更多信息[1]
您可以在发送中介之前向api添加一个enrich中介,以从主体中删除jsonObject包装,如下所示
<enrich>
<source clone="true" xpath="$body//jsonObject//UserType"/>
<target type="body"/>
</enrich>
您可以在充实中介后添加日志中介,并检查更改的主体
希望这对您有所帮助。请参阅: