rest - Mule REST APIKit- 我的流程没有返回消息正文

标签 rest mule synchronous

**问题已解决,感谢 neildo。以下是从 POST 获得响应所需要的

  • RAML 文件必须具有响应正文定义
  • HTTP 端点必须设置为请求-响应
  • 使用同步处理策略的所有流
  • Accept 和 Content-Type HTTP header 在请求上设置为 application/json
    **

  • 我的 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="{ &quot;message&quot;: &quot;Resource not found&quot; }" />
        </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/

    相关文章:

    Java UTF-8 无法正常处理 JSON

    java - 如何发布具有相同基地址的多个休息端点?

    xml - 骡子 http :outbound-endpoint + multipart/form-data

    java - 无法将 SessionVariable 传递给其他流 Mule

    javascript - 如何在for循环内进行同步延迟?

    java - 如何等待 HttpURLConnection 完成?

    ios - 调度同步的目的是什么?

    java - spring Rest 可分页仅发送内容

    Javascript:如何从 API 获取特定数据?

    java - Mule 3.1 - 使用 http-request-to-parameter-map 转换器的消息转换异常