0
votes

I have defined the following flow in a Mule Community Edition 3.8 application:

<flow name="post:/api/v1:application/json:api-v1-config">
  <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
  <expression-component>
    payload = app.registry['RestServiceBean_2.10'].postApiCall(
      payload,
      message);
  </expression-component>
</flow>

And in the same file a mapping for an HTTP 415

<apikit:mapping statusCode="415">
  <apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException" />
  <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
  <set-payload value="{ &quot;message&quot;: &quot;Unsupported media type&quot; }" doc:name="Unsupported media type"/>
</apikit:mapping>

Now when I send a request to that endpoint with Content-Type: application/xml, I see an exception in the log called Flow not found for resource ... and receive an HTTP 500 response.

What am I missing, where do I have to tell the config that it should return an HTTP 415 in such cases?

2

2 Answers

1
votes

I figured out I have to remove application/json: from the flow name:

<flow name="post:/api/v1:api-v1-config">
  <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>

With this configuration, the correct exception (HTTP 415) is thrown.

0
votes

If your project isn't RAML-based you'll need to create a separate Flow for handling all other media types and then manually throw new org.mule.module.apikit.exception.UnsupportedMediaTypeException()