Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mule REST APIKit- My flow isn't returning a messge body

**Issue solved, thanks to neildo. Here's what it took to get a response from a POST

  1. RAML file must have a response body definition
  2. HTTP Endpoint must be set to request-response
  3. All Flows using the synchronous Processing Strategy
  4. Accept and Content-Type HTTP headers set to application/json on the request **

The implementation of my REST Flow calls a Java API that returns a Java object. I then convert the object to a JSON document and return it to the client. My Logger step is logging the correct data, however the client just gets a 200 OK with an empty body.

I have set all my Flows to synchronous and my HTTP Endpoint to request-response. What am I missing?

Thank you! Nathan

Here is my XML file

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

Here is part of my RAML file where I define a request and response body. When I posted a message to Mule, I got this error with nothing logged to the Mule console.

null (java.lang.NullPointerException). Message payload is of type: ContentLengthInputStream

 post:    
body:
  application/json:              
responses:
  200:
    body:
      application/json:  
like image 507
Nathan Weddle Avatar asked Jan 27 '14 22:01

Nathan Weddle


Video Answer


1 Answers

In your raml file, make sure your resource method is mapping the response 200 body with application/json. For example...

/person:
  post: 
    responses:
      200:
        body:
          application/json:
like image 161
neildo Avatar answered Oct 03 '22 18:10

neildo