**问题已解决,感谢 neildo。以下是从 POST 获得响应所需要的
**
我的 REST Flow 的实现调用了一个返回 Java 对象的 Java API。然后我将对象转换为 JSON 文档并将其返回给客户端。我的 Logger 步骤正在记录正确的数据,然而,客户端只是得到一个 200 OK 和一个空体 .
我已将所有流量设置为 同步 和我的 HTTP 端点到 请求-响应 .我错过了什么?
谢谢!
弥敦道
这是我的 XML 文件
<apikit:config name="IAMPerson-config" raml="IAMPerson.raml" consoleEnabled="true" consolePath="console" doc:name="Router"/>
<apikit:mapping-exception-strategy name="IAMPerson-apiKitGlobalExceptionMapping">
<apikit:mapping statusCode="404">
<apikit:exception value="org.mule.module.apikit.exception.NotFoundException" />
<set-property propertyName="Content-Type" value="application/json" />
<set-payload value="{ "message": "Resource not found" }" />
</apikit:mapping>
...
</apikit:mapping-exception-strategy>
<flow name="IAMPerson-main" doc:name="IAMPerson-main" processingStrategy="synchronous">
<http:inbound-endpoint address="http://localhost:8081/api" doc:name="HTTP" exchange-pattern="request-response" password="admin" user="admin" contentType="application/json"/>
<apikit:router config-ref="IAMPerson-config" doc:name="APIkit Router"/>
<exception-strategy ref="IAMPerson-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/>
</flow>
<flow name="post:/person:IAMPerson-config" doc:name="post:/person:IAMPerson-config" processingStrategy="synchronous">
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="PersonDTO"/>
<invoke name="invokeCreate" object-ref="personService" method="create" methodArguments="#[payload]"></invoke>
<json:object-to-json-transformer sourceClass="Person" doc:name="Person Object to JSON"/>
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>
<flow name="put:/person:IAMPerson-config" doc:name="put:/person:IAMPerson-config" processingStrategy="synchronous">
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="PersonDTO"/>
<invoke name="invokeUpdate" object-ref="personService" method="update" methodArguments="#[payload]"/>
<json:object-to-json-transformer sourceClass="Person" doc:name="Person Object to JSON"/>
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>
这是我的 RAML 文件的一部分,我在其中定义了请求和响应正文。当我向 Mule 发布消息时,我收到此错误,但没有任何内容记录到 Mule 控制台。
null (java.lang.NullPointerException)。消息负载类型为:ContentLengthInputStream
post:
body:
application/json:
responses:
200:
body:
application/json:
最佳答案
在您的 raml 文件中,确保您的资源方法将响应 200 主体与 application/json 映射。例如...
/person:
post:
responses:
200:
body:
application/json:
关于rest - Mule REST APIKit- 我的流程没有返回消息正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21393192/