Reputation: 749
I am struggling a little to satisfy my use-case with the Mule REST module. I'd like to have different transformations according to templateUri and HTTP method.
Here is my configuration:
<flow name="http-interface">
<http:inbound-endpoint address="http://localhost:8555" exchange-pattern="request-response"/>
<rest:router templateUri="/schedule">
<rest:post>
<mxml:schema-validation-filter schemaLocations="xsd/scheduler.xsd" returnResult="true"/>
<mxml:jaxb-xml-to-object-transformer jaxbContext-ref="jaxb-context"/>
<vm:outbound-endpoint path="addjob"/>
</rest:post>
</rest:router>
<choice-exception-strategy>
<catch-exception-strategy when="exception.causedBy(org.mule.api.routing.filter.FilterUnacceptedException)">
<logger level="ERROR" message="FilterUnacceptedException #[message]"/>
<set-payload value="An error occurred while validating request. Please check the XML payload"/>
<set-property propertyName="http.status" value="400"/>
</catch-exception-strategy>
<catch-exception-strategy when="exception.causedBy(java.lang.NullPointerException)">
<logger level="ERROR" message="NullPointerException #[message]"/>
<set-payload value="An error occurred while validating request. Please check the XML payload"/>
<set-property propertyName="http.status" value="400"/>
</catch-exception-strategy>
</choice-exception-strategy>
</flow>
When invalid XML is posted to the endpoint, I am getting a NullPointerException in NestedProcessorChain.processWithExtraProperties. Hence the nasty catch for this exception (not ideal).
My IDE gives schema validation errors both for rest:router in flow and the mxml filter/transformer in the rest:post element. I can remove the first by putting rest:router inside the inbound-endpoint. Results are the same, and most examples don't have this
I tried moving the filter/transformation to a separate flow on a VM endpoint. Validation is clean, but then I can't figure out how to get the HTTP error code and response back to the client.
Any help much appreciated, Alfie.
Upvotes: 0
Views: 392
Reputation: 644
The NPE is NestedProcessorChain.processWithExtraProperties is a bug in Mule REST Router, I raised an issue here, but it seems that REST Router is not supported anymore.
In general NPE is being thrown when you call your URI with HTTP method not described in your <rest:router> element. Expected exception is UnsupportedHttpVerbException.
In details I have described the problem in one of my blog posts, and provided fixed version of Mule REST Router.
Instead of using VM Endpoint, call the separate flow using <flow-ref /> component or wrap it with <processor-chain />.
Upvotes: 1