Question

**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:  
Was it helpful?

Solution

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:

OTHER TIPS

I had the same problem (using version 3.5.0), but with a GET request. None of the proposed solutions (neither items 1 through 4 at the top of the edited question, nor the checked answer) solved the problem for me. (Most of them were already true in my case.)

What did work for me was adding the following at the bottom of the problematic GET flow's XML:

<response>
    <set-property propertyName="Content-Type" value="application/json"/>
</response>

Unfortunately, there seems to be no way to do this using the visual editor (in the "Message Flow" tab). I had to do this manually in the "Configuration XML" tab instead.

Also, inserting the above element in the main flow (the one that invokes the APIKit Router) -- which has to be done BEFORE the <exception-strategy> element for some reason -- does not solve the problem. However, in this case, the response element DOES show up in the visual editor.

I looked at this page on SO 15 times before I realized how I'd caused this. I'd added a Transformer to do some authentication. I'd customized my onCall method, but left transformMessage as the default which sets a 200 and returns null.

Lo and behold, changing return null to return message made everything work again.

Use this format of response for 200 status code in your RAML file. responses: 200: body: application/json:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top