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="{ "message": "Unsupported media type" }" 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?
如果您的项目不是基于RAML的,则需要创建一个单独的Flow以处理所有其他媒体类型,然后手动throw new org.mule.module.apikit.exception.UnsupportedMediaTypeException()
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.